VectorDataNodeIO { public static VectorDataNode[] getVectorDataNodes(VectorDataNode vectorDataNode, boolean individualShapes, String attributeName) { VectorDataNode[] vectorDataNodes; if (individualShapes) { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorDataNode.getFeatureCollection(); SimpleFeature[] features = featureCollection.toArray(new SimpleFeature[0]); vectorDataNodes = new VectorDataNode[features.length]; for (int i = 0; i < features.length; i++) { SimpleFeature feature = features[i]; String newName; if (attributeName != null && feature.getAttribute(attributeName) != null && !feature.getAttribute(attributeName).toString().isEmpty()) { newName = feature.getAttribute(attributeName).toString().replace(" ", "_").replace("-", "_"); } else { newName = vectorDataNode.getName() + "_" + (i + 1); } vectorDataNodes[i] = new VectorDataNode(newName, new ListFeatureCollection(vectorDataNode.getFeatureType(), Arrays.asList(feature))); } } else { vectorDataNodes = new VectorDataNode[]{vectorDataNode}; } return vectorDataNodes; }  static Converter[] getConverters(SimpleFeatureType simpleFeatureType); static String encodeTabString(String input); static String decodeTabString(String input); static VectorDataNode[] getVectorDataNodes(VectorDataNode vectorDataNode, boolean individualShapes, String attributeName); static final char DEFAULT_DELIMITER_CHAR; static final String ESCAPE_STRING; static final String NULL_TEXT; static final String FILENAME_EXTENSION; }
@Test public void testGetVectorDataNodes() throws Exception { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("sft"); builder.add("CAPITAL", String.class); SimpleFeatureType featureType = builder.buildFeatureType(); VectorDataNode vectorDataNode = new VectorDataNode("originalName", featureType); SimpleFeatureBuilder simpleFeatureBuilder = new SimpleFeatureBuilder(featureType); simpleFeatureBuilder.set("CAPITAL", "Moscow"); vectorDataNode.getFeatureCollection().add(simpleFeatureBuilder.buildFeature("0")); simpleFeatureBuilder.set("CAPITAL", "Coruscant"); vectorDataNode.getFeatureCollection().add(simpleFeatureBuilder.buildFeature("1")); VectorDataNode[] vectorDataNodes = VectorDataNodeIO.getVectorDataNodes(vectorDataNode, true, "CAPITAL"); assertEquals(2, vectorDataNodes.length); assertEquals("Moscow", vectorDataNodes[0].getName()); assertEquals("Coruscant", vectorDataNodes[1].getName()); vectorDataNodes = VectorDataNodeIO.getVectorDataNodes(vectorDataNode, false, "CAPITAL"); assertEquals(1, vectorDataNodes.length); assertEquals("originalName", vectorDataNodes[0].getName()); }
@Test public void testGetVectorDataNodesWithEmptyAttribute() throws Exception { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("sft"); builder.add("CAPITAL", String.class); SimpleFeatureType featureType = builder.buildFeatureType(); VectorDataNode vectorDataNode = new VectorDataNode("originalName", featureType); SimpleFeatureBuilder simpleFeatureBuilder = new SimpleFeatureBuilder(featureType); simpleFeatureBuilder.set("CAPITAL", ""); vectorDataNode.getFeatureCollection().add(simpleFeatureBuilder.buildFeature("0")); simpleFeatureBuilder.set("CAPITAL", "Coruscant"); vectorDataNode.getFeatureCollection().add(simpleFeatureBuilder.buildFeature("1")); VectorDataNode[] vectorDataNodes = VectorDataNodeIO.getVectorDataNodes(vectorDataNode, true, "CAPITAL"); assertEquals(2, vectorDataNodes.length); assertEquals("originalName_1", vectorDataNodes[0].getName()); assertEquals("Coruscant", vectorDataNodes[1].getName()); }