use of com.google.common.base.Optional in project core-java by SpineEventEngine.
the class PairShould method return_Empty_for_absent_Optional_in_iterator.
@Test
public void return_Empty_for_absent_Optional_in_iterator() {
StringValue a = TestValues.newUuidValue();
Pair<StringValue, Optional<BoolValue>> pair = Pair.withNullable(a, null);
final Iterator<Message> iterator = pair.iterator();
assertEquals(a, iterator.next());
assertEquals(Empty.getDefaultInstance(), iterator.next());
assertFalse(iterator.hasNext());
}
use of com.google.common.base.Optional in project core-java by SpineEventEngine.
the class PairShould method allow_optional_B_present.
@Test
public void allow_optional_B_present() {
StringValue a = TestValues.newUuidValue();
Optional<BoolValue> b = Optional.of(BoolValue.of(true));
Pair<StringValue, Optional<BoolValue>> pair = Pair.withNullable(a, b.get());
assertEquals(a, pair.getA());
assertEquals(b, pair.getB());
}
use of com.google.common.base.Optional in project GeoGig by boundlessgeo.
the class FeatureBuilder method buildLazy.
public Feature buildLazy(final String id, final Node node, final RevObjectParse parser) {
Supplier<? extends List<Optional<Object>>> valueSupplier = new LazyFeatureLoader(node.getObjectId(), parser);
valueSupplier = Suppliers.memoize(valueSupplier);
final FeatureId fid = new LazyVersionedFeatureId(id, node.getObjectId());
GeogigSimpleFeature feature = new GeogigSimpleFeature(valueSupplier, (SimpleFeatureType) featureType, fid, attNameToRevTypeIndex, node);
return feature;
}
use of com.google.common.base.Optional in project GeoGig by boundlessgeo.
the class DeepMove method moveObjects.
private void moveObjects(final ObjectDatabase from, final ObjectDatabase to, final Supplier<Iterator<Node>> nodesToMove, final Set<ObjectId> metadataIds) {
Iterable<ObjectId> ids = new Iterable<ObjectId>() {
final Function<Node, ObjectId> asId = new Function<Node, ObjectId>() {
@Override
public ObjectId apply(Node input) {
Optional<ObjectId> metadataId = input.getMetadataId();
if (metadataId.isPresent()) {
metadataIds.add(input.getMetadataId().get());
}
ObjectId id = input.getObjectId();
return id;
}
};
@Override
public Iterator<ObjectId> iterator() {
Iterator<Node> iterator = nodesToMove.get();
Iterator<ObjectId> ids = Iterators.transform(iterator, asId);
return ids;
}
};
final ExecutorService deletingService = Executors.newSingleThreadExecutor();
try {
final DeletingListener deletingListener = new DeletingListener(deletingService, from);
// store objects into the target db and remove them from the origin db in one shot
to.putAll(from.getAll(ids), deletingListener);
// in case there are some deletes pending cause the iterator finished and the listener
// didn't fill its buffer
deletingListener.deleteInserted();
} finally {
deletingService.shutdown();
while (!deletingService.isTerminated()) {
try {
deletingService.awaitTermination(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// ok, still awaiting for delete tasks to finish
}
}
}
}
use of com.google.common.base.Optional in project GeoGig by boundlessgeo.
the class GeogigSimpleFeature method getDefaultGeometry.
@Override
public Object getDefaultGeometry() {
// should be specified in the index as the default key (null)
Integer idx = nameToRevTypeIndex.get(null);
List<Optional<Object>> values = getValues();
Object defaultGeometry = idx != null ? values.get(idx).orNull() : null;
// not found? do we have a default geometry at all?
if (defaultGeometry == null) {
GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor();
if (geometryDescriptor != null) {
Integer defaultGeomIndex = nameToRevTypeIndex.get(geometryDescriptor.getName().getLocalPart());
defaultGeometry = values.get(defaultGeomIndex.intValue()).get();
}
}
return defaultGeometry;
}
Aggregations