public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException { final int count = in.readInt(); final RevFeatureBuilder builder = RevFeature.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; }
public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { final int count = readUnsignedVarInt(in); final RevFeatureBuilder builder = RevFeature.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 = builder.id(id).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 = RevFeature.builder(); String line; while ((line = reader.readLine()) != null) { builder.addValue(parseAttribute(line)); } return builder.id(id).build(); }
@Override public FeatureInfo apply(SimpleFeature f) { return FeatureInfo.insert(RevFeature.builder().build(f), featureTypeId, NodeRef.appendChild(treePath, f.getID())); }};
@Override public FeatureInfo apply(Feature f) { RevFeature rf = RevFeature.builder().build(f); String path = NodeRef.appendChild(treePath, f.getIdentifier().getID()); return FeatureInfo.insert(rf, featureTypeId, path); } };
@Override public FeatureInfo apply(SimpleFeature f) { RevFeature feature = RevFeature.builder().build(f); String fid = f.getID(); String path = NodeRef.appendChild(treePath, fid); String version = feature.getId().toString(); if (returnFidsOnInsert) { insertedFids.add(new FeatureIdVersionedImpl(fid, version)); } return FeatureInfo.insert(feature, featureTypeId, path); }};
@Test public void testNullFeature() throws Exception { try { RevFeature.builder().build((Feature) null); fail("expected NullPointerException on null feature"); } catch (NullPointerException e) { assertTrue(e.getMessage(), e.getMessage().contains("feature is marked @NonNull but is null")); } }
@Test public void testRevFeatureToString() { List<Object> values = Lists.newArrayList("StringProp1_1", new Integer(1000), "POINT(1 1)"); RevFeature feature = RevFeature.builder().addAll(values).build(); String featureString = feature.toString(); String expected = RevObjects.toString(feature); assertEquals(expected, featureString); } }
/** * 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) { RevFeature revFeature = RevFeature.builder().addAll(rawValues).id(forceId).build(); return revFeature; }
@Test public void testRevFeatureConstructorAndAccessors() { List<Object> values = Lists.newArrayList("StringProp1_1", new Integer(1000), "POINT(1 1)"); RevFeature feature = RevFeature.builder().addAll(values).build(); assertEquals(TYPE.FEATURE, feature.getType()); assertEquals(Lists.transform(values, (v) -> Optional.fromNullable(v)), feature.getValues()); }
public static RevFeature createPointFeature(double x, double y, Object... extraAttribues) { RevFeatureBuilder builder = RevFeature.builder(); builder.addValue(gf.createPoint(new Coordinate(x, y))); if (extraAttribues != null) { builder.addAll(Lists.newArrayList(extraAttribues)); } RevFeature feature = builder.build(); return feature; }
@Test public void TestCatFeatureObject() { RevFeature feature = RevFeature.builder().build(points1); CharSequence desc = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(feature)) .call(); String[] lines = desc.toString().split("\n"); assertEquals(points1.getProperties().size() + 2, lines.length); assertEquals(FieldType.STRING.name() + "\tStringProp1_1", lines[2]); assertEquals(FieldType.INTEGER.name() + "\t1000", lines[3]); assertEquals(FieldType.POINT.name() + "\tPOINT (1 1)", lines[4]); }
@Test public void testBuildEmpty() throws Exception { RevFeature emptyFeature = RevFeature.builder().build(); assertNotNull(emptyFeature); assertTrue(emptyFeature.getValues().isEmpty()); assertEquals(ObjectId.valueOf("0aaf76f425c6e0f43a36197de768e67d9e035abb"), emptyFeature.getId()); }
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 = RevFeature.builder().addValue(0L).addValue("zero").build(); o2 = RevFeature.builder().addValue(1L).addValue("one").build(); k11 = cacheId1.create(o1.getId()); k21 = cacheId2.create(o1.getId()); k22 = cacheId2.create(o2.getId()); }
private Node feature(ObjectStore db, String idPrefix, int index) { final String id = idPrefix + "." + index; final Feature feature; feature = super.feature(pointsType, id, id, index, point(index)); RevFeature revFeature = RevFeature.builder().build(feature); db.put(revFeature); Envelope bounds = (Envelope) feature.getBounds(); return RevObjectFactory.defaultInstance().createNode(id, revFeature.getId(), ObjectId.NULL, TYPE.FEATURE, bounds, null); }
public FeatureInfo featureInfo(String treePath, Feature f) { final String path = NodeRef.appendChild(treePath, f.getIdentifier().getID()); RevFeature feature = RevFeature.builder().build(f); FeatureType type = f.getType(); RevFeatureType ftype = RevFeatureType.builder().type(type).build(); return FeatureInfo.insert(feature, ftype.getId(), path); }
@Test public void testAddFeaturePatch() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); patch.addAddedFeature(path, RevFeature.builder().build(points1), RevFeatureType.builder().type(pointsType).build()); testPatch(patch); }
@Test public void testRemoveFeaturePatch() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); patch.addRemovedFeature(path, RevFeature.builder().build(points1), RevFeatureType.builder().type(pointsType).build()); testPatch(patch); }
protected FeatureInfo featureInfo(SimpleFeatureType type, String id, Object... values) { RevFeature feature = RevFeature.builder().build(feature(type, id, values)); RevFeatureType ftype = RevFeatureType.builder().type(type).build(); repo.objectDatabase().put(ftype); String path = NodeRef.appendChild(type.getName().getLocalPart(), id); return FeatureInfo.insert(feature, ftype.getId(), path); }
protected ObjectId insert(Repository repo, Feature f) throws Exception { final WorkingTree workTree = repo.workingTree(); Name name = f.getType().getName(); String parentPath = name.getLocalPart(); RevFeatureType type = RevFeatureType.builder().type(f.getType()).build(); repo.objectDatabase().put(type); String path = NodeRef.appendChild(parentPath, f.getIdentifier().getID()); FeatureInfo fi = FeatureInfo.insert(RevFeature.builder().build(f), type.getId(), path); workTree.insert(fi); return fi.getFeature().getId(); }