@Test public void deepCloneTest() throws TransformationException, UnsupportedEncodingException { InputStream stream = BxModelUtilsTest.class.getResourceAsStream(EXP_STR_LAB_1); TrueVizToBxDocumentReader reader = new TrueVizToBxDocumentReader(); BxDocument doc = new BxDocument().setPages(reader.read(new InputStreamReader(stream, "UTF-8"))); BxDocument copy = BxModelUtils.deepClone(doc); assertFalse(doc == copy); assertTrue(BxModelUtils.areEqual(doc, copy)); Stack<BxPage> pages = new Stack<BxPage>(); Stack<BxZone> zones = new Stack<BxZone>(); Stack<BxLine> lines = new Stack<BxLine>(); Stack<BxWord> words = new Stack<BxWord>(); Stack<BxChunk> chunks = new Stack<BxChunk>(); for (BxPage page : copy) { assertTrue(page.getParent() == copy); for (BxZone zone : page) { assertTrue(zone.getParent() == page); for (BxLine line : zone) { assertTrue(line.getParent() == zone); for (BxWord word : line) { assertTrue(word.getParent() == line); for (BxChunk chunk : word) { assertTrue(chunk.getParent() == word); } } } } } BxPage page = copy.getFirstChild(); while (page != null) { pages.push(page); page = page.getNext(); } page = pages.peek(); BxZone zone = copy.getFirstChild().getFirstChild(); while (zone != null) { zones.push(zone); zone = zone.getNext(); } zone = zones.peek(); BxLine line = copy.getFirstChild().getFirstChild().getFirstChild(); while (line != null) { lines.push(line); line = line.getNext(); } line = lines.peek(); BxWord word = copy.getFirstChild().getFirstChild().getFirstChild().getFirstChild(); while (word != null) { words.push(word); word = word.getNext(); } word = words.peek(); BxChunk chunk = copy.getFirstChild().getFirstChild().getFirstChild().getFirstChild().getFirstChild(); while (chunk != null) { chunks.push(chunk); chunk = chunk.getNext(); } chunk = chunks.peek(); while (!pages.empty() && !zones.empty() && !lines.empty() && !words.empty() && !chunks.empty()) { BxChunk ch = chunks.pop(); assertTrue(ch.getParent() == words.peek()); assertTrue(words.peek().getParent() == lines.peek()); assertTrue(lines.peek().getParent() == zones.peek()); assertTrue(zones.peek().getParent() == pages.peek()); if (chunks.empty()) { words.pop(); lines.pop(); zones.pop(); pages.pop(); } else if (ch.getParent() != chunks.peek().getParent()) { BxWord w = words.pop(); assertFalse(words.empty()); if (w.getParent() != words.peek().getParent()) { BxLine l = lines.pop(); assertFalse(lines.empty()); if (l.getParent() != lines.peek().getParent()) { BxZone z = zones.pop(); assertFalse(zones.empty()); if (z.getParent() != zones.peek().getParent()) { pages.pop(); assertFalse(pages.empty()); } } } } } assertTrue(pages.empty()); assertTrue(zones.empty()); assertTrue(lines.empty()); assertTrue(words.empty()); assertTrue(chunks.empty()); while (page != null) { pages.push(page); page = page.getPrev(); } while (zone != null) { zones.push(zone); zone = zone.getPrev(); } while (line != null) { lines.push(line); line = line.getPrev(); } while (word != null) { words.push(word); word = word.getPrev(); } while (chunk != null) { chunks.push(chunk); chunk = chunk.getPrev(); } while (!pages.empty() && !zones.empty() && !lines.empty() && !words.empty() && !chunks.empty()) { BxChunk ch = chunks.pop(); assertTrue(ch.getParent() == words.peek()); assertTrue(words.peek().getParent() == lines.peek()); assertTrue(lines.peek().getParent() == zones.peek()); assertTrue(zones.peek().getParent() == pages.peek()); if (chunks.empty()) { words.pop(); lines.pop(); zones.pop(); pages.pop(); } else if (ch.getParent() != chunks.peek().getParent()) { BxWord w = words.pop(); assertFalse(words.empty()); if (w.getParent() != words.peek().getParent()) { BxLine l = lines.pop(); assertFalse(lines.empty()); if (l.getParent() != lines.peek().getParent()) { BxZone z = zones.pop(); assertFalse(zones.empty()); if (z.getParent() != zones.peek().getParent()) { pages.pop(); assertFalse(pages.empty()); } } } } } assertTrue(pages.empty()); assertTrue(zones.empty()); assertTrue(lines.empty()); assertTrue(words.empty()); assertTrue(chunks.empty()); }
public static BxBounds deepClone(BxBounds bounds) { return new BxBounds(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); }
BxModelUtils { public static BxBounds deepClone(BxBounds bounds) { return new BxBounds(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } }
BxModelUtils { public static BxBounds deepClone(BxBounds bounds) { return new BxBounds(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } private  BxModelUtils(); }
BxModelUtils { public static BxBounds deepClone(BxBounds bounds) { return new BxBounds(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } private  BxModelUtils(); static void setParents(BxDocument doc); static void setParents(BxPage page); static void sortZonesYX(BxPage page, final double tolerance); static void sortZonesYX(BxPage page); static void sortZonesXY(BxPage page, final double tolerance); static void sortZonesXY(BxPage page); static void sortLines(BxZone zone); static void sortWords(BxLine line); static void sortChunks(BxWord word); static void sortZoneRecursively(BxZone zone); static void sortZonesRecursively(BxPage page); static void sortZonesRecursively(BxDocument document); static BxBounds deepClone(BxBounds bounds); static BxChunk deepClone(BxChunk chunk); static BxWord deepClone(BxWord word); static BxLine deepClone(BxLine line); static BxZone deepClone(BxZone zone); static BxPage deepClone(BxPage page); static BxDocument deepClone(BxDocument document); static List<BxDocument> deepClone(List<BxDocument> documents); static Map<BxChunk, BxWord> mapChunksToWords(BxPage page); static Map<BxChunk, BxLine> mapChunksToLines(BxPage page); static Map<BxChunk, BxZone> mapChunksToZones(BxPage page); static int countChunks(BxLine line); static int countChunks(BxZone zone); static boolean contains(BxBounds containing, BxBounds contained, double tolerance); static boolean areEqual(BxChunk chunk1, BxChunk chunk2); static boolean areEqual(BxWord word1, BxWord word2); static boolean areEqual(BxLine line1, BxLine line2); static boolean areEqual(BxZone zone1, BxZone zone2); static boolean areEqual(BxPage page1, BxPage page2); static boolean areEqual(BxDocument doc1, BxDocument doc2); }
BxModelUtils { public static BxBounds deepClone(BxBounds bounds) { return new BxBounds(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } private  BxModelUtils(); static void setParents(BxDocument doc); static void setParents(BxPage page); static void sortZonesYX(BxPage page, final double tolerance); static void sortZonesYX(BxPage page); static void sortZonesXY(BxPage page, final double tolerance); static void sortZonesXY(BxPage page); static void sortLines(BxZone zone); static void sortWords(BxLine line); static void sortChunks(BxWord word); static void sortZoneRecursively(BxZone zone); static void sortZonesRecursively(BxPage page); static void sortZonesRecursively(BxDocument document); static BxBounds deepClone(BxBounds bounds); static BxChunk deepClone(BxChunk chunk); static BxWord deepClone(BxWord word); static BxLine deepClone(BxLine line); static BxZone deepClone(BxZone zone); static BxPage deepClone(BxPage page); static BxDocument deepClone(BxDocument document); static List<BxDocument> deepClone(List<BxDocument> documents); static Map<BxChunk, BxWord> mapChunksToWords(BxPage page); static Map<BxChunk, BxLine> mapChunksToLines(BxPage page); static Map<BxChunk, BxZone> mapChunksToZones(BxPage page); static int countChunks(BxLine line); static int countChunks(BxZone zone); static boolean contains(BxBounds containing, BxBounds contained, double tolerance); static boolean areEqual(BxChunk chunk1, BxChunk chunk2); static boolean areEqual(BxWord word1, BxWord word2); static boolean areEqual(BxLine line1, BxLine line2); static boolean areEqual(BxZone zone1, BxZone zone2); static boolean areEqual(BxPage page1, BxPage page2); static boolean areEqual(BxDocument doc1, BxDocument doc2);  }