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

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

Introduction

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

Prototype

public static <T> Optional<T> of(T reference) 

Source Link

Document

Returns an Optional instance containing the given non-null reference.

Usage

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.OrderedLeafSetModificationStrategy.java

@SuppressWarnings({ "unchecked", "rawtypes" })
OrderedLeafSetModificationStrategy(final LeafListSchemaNode schema, final DataTreeConfiguration treeConfig) {
    super((Class) LeafSetNode.class, treeConfig);
    entryStrategy = Optional.of(new LeafSetEntryModificationStrategy(schema));
}

From source file:org.eclipse.emf.eson.generators.GeneratorHelper.java

/**
 * Find the first occurrence of content of a certain type.
 * /* w  ww .  j av a  2s.c o  m*/
 * This helper intentionally, for optional performance, does NOT traverse the entire Resource, but only the first level.
 * 
 * @param resource EMF Resource
 * @param klass Java class to find in first level of getContents() of Resource
 * @return Guava optional
 */
public <T extends EObject> Optional<T> getFirstRootContentOfType(Resource resource, Class<T> klass) {
    if (!resource.isLoaded())
        return Optional.absent();

    EList<EObject> contents = resource.getContents();
    for (EObject eObject : contents) {
        if (klass.isInstance(eObject)) {
            return Optional.of(klass.cast(eObject));
        }
    }
    return Optional.absent();
}

From source file:org.akraievoy.cnet.gen.domain.LocationGeneratorFractalDLA.java

public LocationGeneratorFractalDLA(final EntropySource eSource) {
    this.eSource = eSource;
    this.eventModel = new WeightedEventModelBase(Optional.of("locations"));
}

From source file:org.whispersystems.websocket.messages.protobuf.ProtobufWebSocketResponseMessage.java

@Override
public Optional<byte[]> getBody() {
    if (message.hasBody()) {
        return Optional.of(message.getBody().toByteArray());
    } else {//ww w  .  ja v  a  2s  . c o m
        return Optional.absent();
    }
}

From source file:com.google.devtools.build.xcode.xcodegen.FileReference.java

/**
 * Returns an instance whose name is the base name of the path.
 *//*  w w  w  . j  av  a  2 s.  c o  m*/
public static FileReference of(String path, SourceTree sourceTree) {
    return new FileReference(new File(path).getName(), Optional.of(path), sourceTree,
            Optional.<String>absent());
}

From source file:org.basepom.mojo.propertyhelper.macros.DemoMacro.java

@Override
public Optional<String> getValue(@Nonnull final MacroDefinition macroDefinition,
        @Nonnull final ValueProvider valueProvider, @Nonnull final AbstractPropertyHelperMojo mojo) {
    Preconditions.checkState(mojo != null, "inserted mojo is null!");

    final String type = Objects.firstNonNull(macroDefinition.getProperties().get("type"), "static");
    if ("static".equals(type)) {
        return Optional.of("static-value");
    } else if ("property".equals(type)) {
        return valueProvider.getValue();
    } else {/*from   w  w w .  ja  va2 s  .  c  o  m*/
        return Optional.fromNullable(macroDefinition.getProperties().get("value"));
    }
}

From source file:org.jclouds.digitalocean2.handlers.DigitalOcean2RateLimitRetryHandler.java

@Override
protected Optional<Long> millisToNextAvailableRequest(HttpCommand command, HttpResponse response) {
    // The header is the Unix epoch time when the next request can be done
    String epochForNextAvailableRequest = response.getFirstHeaderOrNull("RateLimit-Reset");
    if (epochForNextAvailableRequest == null) {
        return Optional.absent();
    }/* w w w  .  j  av a  2  s.  co  m*/
    return Optional.of(millisUntilNextAvailableRequest(Long.parseLong(epochForNextAvailableRequest)));
}

From source file:li.klass.fhem.domain.CulHmSubType.java

public static Optional<CulHmSubType> subTypeFor(String value) {
    if ("DIMMER".equalsIgnoreCase(value) || "BLINDACTUATOR".equalsIgnoreCase(value)) {
        return Optional.of(DIMMER);
    } else if ("SWITCH".equalsIgnoreCase(value)) {
        return Optional.of(SWITCH);
    } else if ("SMOKEDETECTOR".equalsIgnoreCase(value)) {
        return Optional.of(CulHmSubType.SMOKE_DETECTOR);
    } else if ("THREESTATESENSOR".equalsIgnoreCase(value)) {
        return Optional.of(CulHmSubType.THREE_STATE);
    } else if ("THSensor".equalsIgnoreCase(value)) {
        return Optional.of(CulHmSubType.TH);
    } else if ("KFM100".equalsIgnoreCase(value)) {
        return Optional.of(CulHmSubType.FILL_STATE);
    } else if ("THERMOSTAT".equalsIgnoreCase(value)) {
        return Optional.of(THERMOSTAT);
    } else if ("MOTIONDETECTOR".equalsIgnoreCase(value)) {
        return Optional.of(MOTION);
    } else if (("KEYMATIC").equalsIgnoreCase(value)) {
        return Optional.of(KEYMATIC);
    } else if ("powerMeter".equalsIgnoreCase(value)) {
        return Optional.of(POWERMETER);
    } else if ("THPLSensor".equalsIgnoreCase(value)) {
        return Optional.of(THPL);
    } else if ("powerSensor".equalsIgnoreCase(value)) {
        return Optional.of(POWERSENSOR);
    }//from   w  w w  .java2  s  .  c o  m
    return Optional.absent();
}

From source file:io.crate.planner.Limits.java

public static Optional<Symbol> mergeMin(Optional<Symbol> limit1, Optional<Symbol> limit2) {
    if (limit1.isPresent()) {
        if (limit2.isPresent()) {
            return Optional
                    .of(new Function(LeastFunction.TWO_LONG_INFO, Arrays.asList(limit1.get(), limit2.get())));
        }//from www .j a v a  2 s.co m
        return limit1;
    }
    return limit2;
}

From source file:com.google.template.soy.jbcsrc.api.CompiledTemplates.java

/** Returns the strict content type of the template. */
public Optional<ContentKind> getTemplateContentKind(String name) {
    TemplateMetadata meta = getTemplateMetadata(name);
    String contentKind = meta.contentKind();
    if (contentKind.isEmpty()) {
        return Optional.absent();
    }/*from w  ww . j a v  a  2 s .c  om*/
    return Optional.of(ContentKind.valueOf(contentKind));
}