@Test public void testFromString() throws Exception { BoxData boxData = BoxData.fromString("1,2.3,4,5,2,0123"); Assert.assertEquals("invalid level parsed", 1, boxData.getLevel()); Assert.assertEquals("invalid z parsed", 2.3, boxData.getZ(), 0.001); Assert.assertEquals("invalid row parsed", 4, boxData.getRow()); Assert.assertEquals("invalid column parsed", 5, boxData.getColumn()); Assert.assertEquals("invalid number of siblings parsed", 2, boxData.getNumberOfSiblings()); Assert.assertEquals("invalid number of children parsed", 4, boxData.getChildCount()); List<BoxData> children = boxData.getChildren(); for (int i = 0; i < children.size(); i++) { final BoxData child = children.get(i); Assert.assertNotNull("child " + i + " is null", child); Assert.assertEquals("invalid parent level for child " + i, boxData.getLevel(), child.getParentLevel()); Assert.assertEquals("invalid parent row for child " + i, boxData.getRow(), child.getParentRow()); Assert.assertEquals("invalid parent column for child " + i, boxData.getColumn(), child.getParentColumn()); } boxData = BoxData.fromString("0,99,10,20,1,"); Assert.assertEquals("invalid level parsed", 0, boxData.getLevel()); Assert.assertEquals("invalid number of children parsed", 0, boxData.getChildCount()); boxData = BoxData.fromString("2,99,40,41,1,13"); Assert.assertEquals("invalid level parsed", 2, boxData.getLevel()); Assert.assertEquals("invalid number of children parsed", 2, boxData.getChildCount()); children = boxData.getChildren(); Assert.assertEquals("invalid parent index for first child", 1, children.get(0).getParentIndex()); Assert.assertEquals("invalid parent index for second child", 3, children.get(1).getParentIndex()); }
public static BoxData fromString(final String boxDataString) throws IllegalArgumentException { final String[] stringElements = PATH_PATTERN.split(boxDataString); if (stringElements.length < 5) { throw new IllegalArgumentException( "box data string '" + boxDataString + "' must have at least 5 comma separated fields"); } final int level = Integer.parseInt(stringElements[0]); final double z = Double.parseDouble(stringElements[1]); final int row = Integer.parseInt(stringElements[2]); final int column = Integer.parseInt(stringElements[3]); final int numberOfSiblings = Integer.parseInt(stringElements[4]); final BoxData boxData = new BoxData(z, level, row, column); boxData.numberOfSiblings = numberOfSiblings; if (level > 0) { if (stringElements.length < 6) { throw new IllegalArgumentException( "level " + level + " box data string '" + boxDataString + "' is missing child index field"); } for (final char childIndexValue : stringElements[5].toCharArray()) { final int childIndex = Character.getNumericValue(childIndexValue); final int childLevel = level - 1; final int childRow = (row * 2) + (childIndex / 2); final int childColumn = (column * 2) + (childIndex % 2); boxData.addChild(new BoxData(z, childLevel, childRow, childColumn)); } boxData.updateSiblingCountForAllChildren(); } return boxData; }
BoxData implements Serializable, Comparable<BoxData> { public static BoxData fromString(final String boxDataString) throws IllegalArgumentException { final String[] stringElements = PATH_PATTERN.split(boxDataString); if (stringElements.length < 5) { throw new IllegalArgumentException( "box data string '" + boxDataString + "' must have at least 5 comma separated fields"); } final int level = Integer.parseInt(stringElements[0]); final double z = Double.parseDouble(stringElements[1]); final int row = Integer.parseInt(stringElements[2]); final int column = Integer.parseInt(stringElements[3]); final int numberOfSiblings = Integer.parseInt(stringElements[4]); final BoxData boxData = new BoxData(z, level, row, column); boxData.numberOfSiblings = numberOfSiblings; if (level > 0) { if (stringElements.length < 6) { throw new IllegalArgumentException( "level " + level + " box data string '" + boxDataString + "' is missing child index field"); } for (final char childIndexValue : stringElements[5].toCharArray()) { final int childIndex = Character.getNumericValue(childIndexValue); final int childLevel = level - 1; final int childRow = (row * 2) + (childIndex / 2); final int childColumn = (column * 2) + (childIndex % 2); boxData.addChild(new BoxData(z, childLevel, childRow, childColumn)); } boxData.updateSiblingCountForAllChildren(); } return boxData; } }
BoxData implements Serializable, Comparable<BoxData> { public static BoxData fromString(final String boxDataString) throws IllegalArgumentException { final String[] stringElements = PATH_PATTERN.split(boxDataString); if (stringElements.length < 5) { throw new IllegalArgumentException( "box data string '" + boxDataString + "' must have at least 5 comma separated fields"); } final int level = Integer.parseInt(stringElements[0]); final double z = Double.parseDouble(stringElements[1]); final int row = Integer.parseInt(stringElements[2]); final int column = Integer.parseInt(stringElements[3]); final int numberOfSiblings = Integer.parseInt(stringElements[4]); final BoxData boxData = new BoxData(z, level, row, column); boxData.numberOfSiblings = numberOfSiblings; if (level > 0) { if (stringElements.length < 6) { throw new IllegalArgumentException( "level " + level + " box data string '" + boxDataString + "' is missing child index field"); } for (final char childIndexValue : stringElements[5].toCharArray()) { final int childIndex = Character.getNumericValue(childIndexValue); final int childLevel = level - 1; final int childRow = (row * 2) + (childIndex / 2); final int childColumn = (column * 2) + (childIndex % 2); boxData.addChild(new BoxData(z, childLevel, childRow, childColumn)); } boxData.updateSiblingCountForAllChildren(); } return boxData; } BoxData(final double z,
                   final int level,
                   final int row,
                   final int column); }
BoxData implements Serializable, Comparable<BoxData> { public static BoxData fromString(final String boxDataString) throws IllegalArgumentException { final String[] stringElements = PATH_PATTERN.split(boxDataString); if (stringElements.length < 5) { throw new IllegalArgumentException( "box data string '" + boxDataString + "' must have at least 5 comma separated fields"); } final int level = Integer.parseInt(stringElements[0]); final double z = Double.parseDouble(stringElements[1]); final int row = Integer.parseInt(stringElements[2]); final int column = Integer.parseInt(stringElements[3]); final int numberOfSiblings = Integer.parseInt(stringElements[4]); final BoxData boxData = new BoxData(z, level, row, column); boxData.numberOfSiblings = numberOfSiblings; if (level > 0) { if (stringElements.length < 6) { throw new IllegalArgumentException( "level " + level + " box data string '" + boxDataString + "' is missing child index field"); } for (final char childIndexValue : stringElements[5].toCharArray()) { final int childIndex = Character.getNumericValue(childIndexValue); final int childLevel = level - 1; final int childRow = (row * 2) + (childIndex / 2); final int childColumn = (column * 2) + (childIndex % 2); boxData.addChild(new BoxData(z, childLevel, childRow, childColumn)); } boxData.updateSiblingCountForAllChildren(); } return boxData; } BoxData(final double z,
                   final int level,
                   final int row,
                   final int column); double getZ(); int getLevel(); int getRow(); int getColumn(); int getNumberOfSiblings(); int getLayerLevelIndex(); void setLayerLevelIndex(final int layerLevelIndex); boolean hasChildren(); int getChildCount(); List<BoxData> getChildren(); void addChild(final BoxData child); void updateSiblingCountForAllChildren(); int getParentIndex(); int getParentLevel(); int getParentRow(); int getParentColumn(); BoxData getParentBoxData(); String getServicePath(final int boxWidth,
                                 final int boxHeight); String getLevelPath(); File getAbsoluteLevelFile(final String baseBoxPath,
                                     final String boxPathSuffix); String toDelimitedString(final char d); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final BoxData that); static BoxData fromString(final String boxDataString); }
BoxData implements Serializable, Comparable<BoxData> { public static BoxData fromString(final String boxDataString) throws IllegalArgumentException { final String[] stringElements = PATH_PATTERN.split(boxDataString); if (stringElements.length < 5) { throw new IllegalArgumentException( "box data string '" + boxDataString + "' must have at least 5 comma separated fields"); } final int level = Integer.parseInt(stringElements[0]); final double z = Double.parseDouble(stringElements[1]); final int row = Integer.parseInt(stringElements[2]); final int column = Integer.parseInt(stringElements[3]); final int numberOfSiblings = Integer.parseInt(stringElements[4]); final BoxData boxData = new BoxData(z, level, row, column); boxData.numberOfSiblings = numberOfSiblings; if (level > 0) { if (stringElements.length < 6) { throw new IllegalArgumentException( "level " + level + " box data string '" + boxDataString + "' is missing child index field"); } for (final char childIndexValue : stringElements[5].toCharArray()) { final int childIndex = Character.getNumericValue(childIndexValue); final int childLevel = level - 1; final int childRow = (row * 2) + (childIndex / 2); final int childColumn = (column * 2) + (childIndex % 2); boxData.addChild(new BoxData(z, childLevel, childRow, childColumn)); } boxData.updateSiblingCountForAllChildren(); } return boxData; } BoxData(final double z,
                   final int level,
                   final int row,
                   final int column); double getZ(); int getLevel(); int getRow(); int getColumn(); int getNumberOfSiblings(); int getLayerLevelIndex(); void setLayerLevelIndex(final int layerLevelIndex); boolean hasChildren(); int getChildCount(); List<BoxData> getChildren(); void addChild(final BoxData child); void updateSiblingCountForAllChildren(); int getParentIndex(); int getParentLevel(); int getParentRow(); int getParentColumn(); BoxData getParentBoxData(); String getServicePath(final int boxWidth,
                                 final int boxHeight); String getLevelPath(); File getAbsoluteLevelFile(final String baseBoxPath,
                                     final String boxPathSuffix); String toDelimitedString(final char d); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final BoxData that); static BoxData fromString(final String boxDataString);  }