Example usage for com.google.common.base Optional get

List of usage examples for com.google.common.base Optional get

Introduction

In this page you can find the example usage for com.google.common.base Optional get.

Prototype

public abstract T get();

Source Link

Document

Returns the contained instance, which must be present.

Usage

From source file:org.geogit.storage.FieldType.java

public static FieldType forValue(Optional<Object> field) {
    if (field.isPresent()) {
        Object realField = field.get();
        Class<?> fieldClass = realField.getClass();
        return forBinding(fieldClass);
    } else {//  w  w  w. j a va 2  s.c om
        return NULL;
    }
}

From source file:org.onos.yangtools.yang.model.util.SchemaNodeUtils.java

public static final SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
    Optional<SchemaNode> previous = Optional.absent();
    Optional<SchemaNode> next = getOriginalIfPossible(data);
    while (next.isPresent()) {
        previous = next;//from  w  w w . j a  va2  s. com
        next = getOriginalIfPossible(next.get());
    }
    return previous.orNull();
}

From source file:org.opendaylight.alto.basic.simpleird.SimpleIrdUtils.java

public static IrdInstance readInstance(ResourceId instanceId, ReadTransaction rx)
        throws InterruptedException, ExecutionException {
    InstanceIdentifier<IrdInstance> iid = getInstanceIID(instanceId);

    Optional<IrdInstance> instance = rx.read(LogicalDatastoreType.OPERATIONAL, iid).get();
    if (instance.isPresent()) {
        return instance.get();
    }//  www  . j  a  v  a 2  s  . com
    return null;
}

From source file:org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils.java

public static SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
    Optional<SchemaNode> previous = Optional.absent();
    Optional<SchemaNode> next = getOriginalIfPossible(data);
    while (next.isPresent()) {
        previous = next;//from ww w .  j  a v a2 s. com
        next = getOriginalIfPossible(next.get());
    }
    return previous.orNull();
}

From source file:de.azapps.tools.OptionalUtils.java

public static <F> void withOptional(@NonNull final Optional<F> optional,
        @NonNull final Procedure<F> procedure) {
    if (optional.isPresent()) {
        procedure.apply(optional.get());
    }/*from w w w.jav a 2s . c  o  m*/
}

From source file:org.sonar.server.computation.task.projectanalysis.step.BuildComponentTreeStep.java

@CheckForNull
private static Analysis toAnalysis(Optional<SnapshotDto> snapshotDto) {
    if (snapshotDto.isPresent()) {
        SnapshotDto dto = snapshotDto.get();
        return new Analysis.Builder().setId(dto.getId()).setUuid(dto.getUuid()).setCreatedAt(dto.getCreatedAt())
                .build();//from   w  w w  . j ava 2 s .c o  m
    }
    return null;
}

From source file:extrabiomes.module.fabrica.scarecrow.ItemScarecrow.java

private static boolean spawnCreature(World world, double x, double y, double z) {
    //{//from   w w w  .java 2 s. c  o  m
    final Optional<Entity> entity = Optional.fromNullable(EntityList.createEntityByName(NAME, world));

    if (entity.isPresent()) {
        entity.get().setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F);
        world.spawnEntityInWorld(entity.get());
    }

    return entity.isPresent();
    //}
}

From source file:org.assertj.guava.error.OptionalShouldBePresentWithValue.java

public static <T> ErrorMessageFactory shouldBePresentWithValue(final Optional<T> actual, final Object value) {
    return new OptionalShouldBePresentWithValue(
            "%nExpecting Optional to contain value %n<%s>%n but contained %n<%s>", value, actual.get());
}

From source file:org.opendaylight.groupbasedpolicy.neutron.ovsdb.util.NeutronHelper.java

/**
 * This looks up the Endpoint L2 key from an
 * operational data store kept in neutron-mapper
 *
 * @param externalId The neutron port UUID
 * @param dataBroker {@link DataBroker} to use for the transaction
 * @return {@link EndpointKey} of the matching Endpoint, null if not found
 *///from  w w  w. j a v a  2 s.c o  m
public static EndpointKey getEpKeyFromNeutronMapper(UniqueId externalId, DataBroker dataBroker) {

    ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
    InstanceIdentifier<EndpointByPort> iid = InstanceIdentifier.create(Mappings.class)
            .child(GbpByNeutronMappings.class).child(EndpointsByPorts.class)
            .child(EndpointByPort.class, new EndpointByPortKey(externalId));
    Optional<EndpointByPort> optionalEp = readFromDs(LogicalDatastoreType.OPERATIONAL, iid, transaction);
    if (optionalEp.isPresent()) {
        EndpointByPort epByPort = optionalEp.get();
        return new EndpointKey(epByPort.getL2Context(), epByPort.getMacAddress());
    }
    return null;
}

From source file:de.flapdoodle.logparser.matcher.stacktrace.AbstractStackElement.java

protected static <T> Optional<T> match(CharSequence input, Pattern pattern, IStackElementFactory<T> factory) {
    Optional<Map<String, String>> m = Patterns.match(pattern.matcher(input));
    if (m.isPresent()) {
        return Optional.of(factory.newInstance(input.toString(), m.get()));
    }/*from   w w w. j  a v a2 s .  co  m*/
    return Optional.absent();
}