package org.gzigzag; import java.util.*; class Level { static Map kopien = new HashMap(); ZZCell level; Level(ZZCell level) { this.level=level; } ZZCell copyLevel() { Set cells = new HashSet(); cells.add(level); ZZCell cell = ZZCursorReal.get(level); addCells(cell, cells); Map copies = new HashMap(); for(Iterator i=cells.iterator(); i.hasNext();) { ZZCell c = (ZZCell)i.next(); copies.put(c, c.zzclone()); } for(Iterator i=cells.iterator(); i.hasNext();) { ZZCell c = (ZZCell)i.next(); copyConn(c, copies, "d.1"); copyConn(c, copies, "d.2"); copyConn(c, copies, "d.lagerplaetze"); } for(Iterator i=copies.entrySet().iterator(); i.hasNext();) { Map.Entry e = (Map.Entry)i.next(); ZZCell c = (ZZCell)e.getKey(); ZZCell copy = (ZZCell)e.getValue(); if(c.s("d.kiste") != null) copy.N("d.kiste"); } ZZCell lvlcopy = (ZZCell)copies.get(level); ZZCell cellcopy = (ZZCell)copies.get(cell); ZZCursorReal.set(lvlcopy, cellcopy); return lvlcopy; } void copyConn(ZZCell c, Map copies, String dim) { ZZCell d = c.s(dim, 1); ZZCell ccopy = (ZZCell)copies.get(c); ZZCell dcopy = (ZZCell)copies.get(d); if(ccopy != null && dcopy != null) { ccopy.connect(dim, 1, dcopy); System.out.println("Copied: "+c+"/"+ccopy+" "+dim+" "+d+"/"+dcopy); } } void addCells(ZZCell start, Set s) { if(s.contains(start)) return; s.add(start); System.out.println("Add cell: "+start); addCells(start, s, "d.1", -1); addCells(start, s, "d.1", 1); addCells(start, s, "d.2", -1); addCells(start, s, "d.2", 1); } void addCells(ZZCell start, Set s, String dim, int dir) { ZZCell c = start.s(dim, dir); if(c != null) addCells(c, s); } public ZZCell start(ZZCell window){ ZZCell level = copyLevel(); if(level == null) throw new NullPointerException("null level"); ZZCursorReal.set(window, ZZCursorReal.get(level)); return level; } }