Search in sources :

Example 26 with Optional

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());
}
Also used : Optional(com.google.common.base.Optional) Message(com.google.protobuf.Message) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 27 with Optional

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());
}
Also used : Optional(com.google.common.base.Optional) BoolValue(com.google.protobuf.BoolValue) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 28 with Optional

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;
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) Optional(com.google.common.base.Optional)

Example 29 with Optional

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
            }
        }
    }
}
Also used : Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Function(com.google.common.base.Function) ExecutorService(java.util.concurrent.ExecutorService)

Example 30 with Optional

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;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Optional(com.google.common.base.Optional)

Aggregations

Optional (com.google.common.base.Optional)319 List (java.util.List)79 Test (org.junit.Test)72 ArrayList (java.util.ArrayList)64 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)45 Map (java.util.Map)44 RevFeature (org.locationtech.geogig.api.RevFeature)42 Collections (java.util.Collections)38 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)36 Logger (org.slf4j.Logger)36 LoggerFactory (org.slf4j.LoggerFactory)36 ExecutionException (java.util.concurrent.ExecutionException)35 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)33 ImmutableList (com.google.common.collect.ImmutableList)32 HashMap (java.util.HashMap)32 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)30 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)30 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)28 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)28 File (java.io.File)27