public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException { final int count = in.readInt(); final RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = DataStreamValueSerializerV1.INSTANCE.decode(fieldType, in); builder.addValue(value); } RevFeature built = builder.build(); return built; }
@Override protected RevFeature read(ObjectId id, BufferedReader reader, TYPE type) throws IOException { Preconditions.checkArgument(TYPE.FEATURE.equals(type), "Wrong type: %s", type.name()); RevFeatureBuilder builder = RevFeatureBuilder.builder(); String line; while ((line = reader.readLine()) != null) { builder.addValue(parseAttribute(line)); } return builder.build(); }
public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { final int count = readUnsignedVarInt(in); final RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = valueEncoder.decode(fieldType, in); builder.addValueNoCopy(value); } RevFeature built = id == null ? builder.build() : builder.build(id); return built; }
public static RevFeature createPointFeature(double x, double y, Object... extraAttribues) { RevFeatureBuilder builder = RevFeatureBuilder.builder(); builder.addValue(gf.createPoint(new Coordinate(x, y))); if (extraAttribues != null) { builder.addAll(Lists.newArrayList(extraAttribues)); } RevFeature feature = builder.build(); return feature; }
public static RevFeature feature(Object... rawValues) { RevFeatureBuilder builder = RevFeatureBuilder.builder().addAll(rawValues); return builder.build(); }
/** * Only for testing: allows to return a {@link RevFeature} with the specified id instead of the * one resulting from {@link HashObject} */ public static RevFeature featureForceId(ObjectId forceId, Object... rawValues) { RevFeatureBuilder builder = RevFeatureBuilder.builder().addAll(rawValues); RevFeature revFeature = builder.build(forceId); return revFeature; }
/** * Constructs a new {@link RevFeature} from the provided {@link Feature}. * * @param feature the feature to build from * @return the newly constructed RevFeature */ public static RevFeature build(Feature feature) { if (feature == null) { throw new IllegalStateException("No feature set"); } RevFeatureBuilder builder = RevFeatureBuilder.builder(); if (feature instanceof SimpleFeature) { // Just SimpleFeature sf = (SimpleFeature) feature; int attributeCount = sf.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { builder.addValue(sf.getAttribute(i)); } } else { Collection<Property> props = feature.getProperties(); props.forEach((p) -> builder.addProperty(p)); } return builder.build(); } }
@Before public void before() throws Exception { geom = new WKTReader().read( "MULTIPOLYGON (((-121.3647138 38.049474, -121.3646902 38.049614, -121.3646159 38.0496058, -121.3646188 38.049587, -121.3645936 38.049586, -121.3645924 38.0496222, -121.3645056 38.0496178, -121.3645321 38.0494567, -121.3647138 38.049474)))"); values = Lists.newArrayList(// "StringProp1_1", // Boolean.TRUE, // Byte.valueOf("18"), // new Double(100.01), // new BigDecimal("1.89e1021"), // new Float(12.5), // new Integer(1000), // new BigInteger("90000000"), // new Long(800000), // new java.util.Date(1264396155228L), // new java.sql.Date(1364356800000L), // new java.sql.Time(57355228L), // UUID.fromString("bd882d24-0fe9-11e1-a736-03b3c0d0d06d"), // geom); geomIndex = values.size() - 1; feature = RevFeatureBuilder.builder().addAll(values).build(); }
@Test public void testRevFeatureToString() { List<Object> values = Lists.newArrayList("StringProp1_1", new Integer(1000), "POINT(1 1)"); RevFeature feature = RevFeatureBuilder.builder().addAll(values).build(); String featureString = feature.toString(); assertEquals("Feature[" + feature.getId().toString() + "; StringProp, 1000, POINT(1 1)]", featureString); } }
@Test public void testRevFeatureConstructorAndAccessors() { List<Object> values = Lists.newArrayList("StringProp1_1", new Integer(1000), "POINT(1 1)"); RevFeature feature = RevFeatureBuilder.builder().addAll(values).build(); assertEquals(TYPE.FEATURE, feature.getType()); assertEquals(Lists.transform(values, (v) -> Optional.fromNullable(v)), feature.getValues()); }
@Test public void tesFeaturePropertyOfUnsupportedType() { TestSerializableObject serializableObject = new TestSerializableObject(); serializableObject.words = "words to serialize"; try { RevFeatureBuilder.builder().addValue(1).addValue("s").addValue(serializableObject) .build(); fail("Expected IAE"); } catch (IllegalArgumentException iae) { String expected = "Objects of class " + serializableObject.getClass().getName() + " are not supported as RevFeature attributes"; assertTrue(iae.getMessage(), iae.getMessage().startsWith(expected)); } }
ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.descriptors(); ImmutableList<PropertyDescriptor> newAttributes = featureType.descriptors(); RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < newAttributes.size(); i++) { int idx = oldAttributes.indexOf(newAttributes.get(i));
@Test public void testBuildWithAddProperty() throws Exception { SimpleFeature f = (SimpleFeature) points1; RevFeature feature = RevFeatureBuilder.build(f); RevFeatureBuilder b = builder(); for (Property p : f.getProperties()) { b.addProperty(p); } RevFeature built = b.build(); assertEquals(feature, built); for (int i = 0; i < f.getAttributeCount(); i++) { assertEquals(f.getAttribute(i), built.getValues().get(i).orNull()); } }
@Test public void testBuildEmpty() throws Exception { RevFeature emptyFeature = RevFeatureBuilder.builder().build(); assertNotNull(emptyFeature); assertTrue(emptyFeature.getValues().isEmpty()); assertEquals(ObjectId.valueOf("0aaf76f425c6e0f43a36197de768e67d9e035abb"), emptyFeature.getId()); }
@Test public void testBuildWithAddValue() throws Exception { SimpleFeature f = (SimpleFeature) points1; RevFeature feature = RevFeatureBuilder.build(f); RevFeatureBuilder b = builder(); for (int i = 0; i < f.getAttributeCount(); i++) { b.addValue(f.getAttribute(i)); } RevFeature built = b.build(); assertEquals(feature, built); for (int i = 0; i < f.getAttributeCount(); i++) { assertEquals(f.getAttribute(i), built.getValues().get(i).orNull()); } }
@Test public void testReset() { SimpleFeature f = (SimpleFeature) points1; RevFeature feature = RevFeatureBuilder.build(f); RevFeatureBuilder b = builder(); b.addValue(1000); b.addValue("str"); b.reset(); for (Property p : f.getProperties()) { b.addProperty(p); } RevFeature built = b.build(); assertEquals(feature, built); for (int i = 0; i < f.getAttributeCount(); i++) { assertEquals(f.getAttribute(i), built.getValues().get(i).orNull()); } }
@Test public void testAddAll() { SimpleFeature f = (SimpleFeature) points1; RevFeature feature = RevFeatureBuilder.build(f); RevFeatureBuilder b = builder(); b.addAll(f.getAttributes()); RevFeature builtWithList = b.build(); assertEquals(feature, builtWithList); b.reset(); b.addAll(f.getAttributes().toArray(new Object[f.getAttributeCount()])); RevFeature builtWithArray = b.build(); assertEquals(feature, builtWithArray); for (int i = 0; i < f.getAttributeCount(); i++) { assertEquals(f.getAttribute(i), builtWithList.getValues().get(i).orNull()); } }
public @Before void before() { mockSharedCache = mock(SharedCache.class); cacheId1 = new CacheIdentifier(0); cacheId2 = new CacheIdentifier(1000); cache1 = new ObjectCache(() -> mockSharedCache, cacheId1); cache2 = new ObjectCache(() -> mockSharedCache, cacheId2); o1 = RevFeatureBuilder.builder().addValue(0L).addValue("zero").build(); o2 = RevFeatureBuilder.builder().addValue(1L).addValue("one").build(); k11 = cacheId1.create(o1.getId()); k12 = cacheId1.create(o2.getId()); k21 = cacheId2.create(o1.getId()); k22 = cacheId2.create(o2.getId()); }
@Test public void testEnforcesPolygonNormalization() throws Exception { // outer ring in cw order, inner rings in ccw order String normalizedWKT = "POLYGON((0 0, 0 9, 9 9, 9 0, 0 0), (3 3, 6 3, 6 6, 3 6, 3 3))"; // outer ring in ccw order, inner rings in cc order String reversedWKT = "POLYGON((0 0, 9 0, 9 9, 0 9, 0 0), (3 3, 3 6, 6 6, 6 3, 3 3))"; Geometry normalized = new WKTReader().read(normalizedWKT); Geometry reversed = new WKTReader().read(reversedWKT); assertTrue(normalized.equalsExact(normalized.norm())); assertFalse(reversed.equalsExact(reversed.norm())); RevFeatureBuilder builder = builder(); RevFeature norm = builder.addValue(normalized).build(); RevFeature rev = builder.reset().addValue(reversed).build(); Geometry expected = (Geometry) norm.getValues().get(0).get(); Geometry actual = (Geometry) rev.getValues().get(0).get(); assertTrue(normalized.equalsExact(expected)); assertTrue(normalized.equalsExact(actual)); }
RevFeatureBuilder builder = builder(); RevFeature norm = builder.addValue(normalized).build(); RevFeature rev = builder.reset().addValue(reversed).build();