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:com.google.gerrit.server.notedb.rebuild.StatusChangeEvent.java

static Optional<StatusChangeEvent> parseFromMessage(ChangeMessage message, Change change, Change noteDbChange) {
    String msg = message.getMessage();
    if (msg == null) {
        return Optional.absent();
    }//  w  w  w  .j  a  va2 s  . c o m
    for (Map.Entry<Change.Status, Pattern> e : PATTERNS.entrySet()) {
        if (e.getValue().matcher(msg).matches()) {
            return Optional.of(new StatusChangeEvent(message, change, noteDbChange, e.getKey()));
        }
    }
    return Optional.absent();
}

From source file:com.qcadoo.mes.orders.dates.OrderDates.java

public static Optional<OrderDates> of(final Entity order) {
    if (hasPlannedDatesDefined(order)) {
        return Optional.of(OrderDates.of(order, Optional.<DateTime>absent(), Optional.<DateTime>absent()));
    } else {//  www.  j  ava  2s.  c o  m
        return Optional.absent();
    }
}

From source file:com.facebook.buck.cxx.CxxInferSourceFilter.java

CxxInferSourceFilter(InferBuckConfig config) {
    Optional<String> rawFilterRegex = config.getValue("blacklist_regex");

    blacklistRegex = rawFilterRegex.isPresent() ? Optional.of(Pattern.compile(rawFilterRegex.get()))
            : Optional.<Pattern>absent();
}

From source file:gobblin.metrics.reporter.util.EventUtils.java

/**
 * Parses a {@link gobblin.metrics.MetricReport} from a byte array representing a json input.
 * @param reuse MetricReport to reuse./* ww w .  j a  v a2s  .  c  om*/
 * @param bytes Input bytes.
 * @return MetricReport.
 * @throws java.io.IOException
 */
public synchronized static GobblinTrackingEvent deserializeReportFromJson(GobblinTrackingEvent reuse,
        byte[] bytes) throws IOException {
    if (!reader.isPresent()) {
        reader = Optional.of(new SpecificDatumReader<>(GobblinTrackingEvent.class));
    }

    Closer closer = Closer.create();

    try {
        DataInputStream inputStream = closer.register(new DataInputStream(new ByteArrayInputStream(bytes)));

        // Check version byte
        int versionNumber = inputStream.readInt();
        if (versionNumber != SCHEMA_VERSION) {
            throw new IOException(
                    String.format("MetricReport schema version not recognized. Found version %d, expected %d.",
                            versionNumber, SCHEMA_VERSION));
        }

        // Decode the rest
        Decoder decoder = DecoderFactory.get().jsonDecoder(GobblinTrackingEvent.SCHEMA$, inputStream);
        return reader.get().read(reuse, decoder);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}

From source file:org.sitemap4j.dom4j.Dom4jHelper.java

static Document getDocumentFromRawSiteMap(final RawSiteMap rawSiteMap) {
    if (!rawSiteMap.hasRepresentation(Document.class)) {
        rawSiteMap.addRepresentation(representationFunction(), Optional.of(Document.class));
    }//from w  w w  . jav a  2 s .c  om

    return rawSiteMap.getRepresentation(Document.class).get();
}

From source file:org.tensorics.core.quantity.ImmutableErronousValue.java

public static <V> ImmutableErronousValue<V> ofValueAndError(V value, V error) {
    return new ImmutableErronousValue<V>(value, Optional.of(error));
}

From source file:extrabiomes.module.amica.thermalexpansion.ThermalExpansionAPI.java

ThermalExpansionAPI() {
    try {/* w  w w  . java2 s.  c  o  m*/
        final Class cls = Class.forName("thermalexpansion.api.crafting.CraftingHelpers");
        addSawmillLogToPlankRecipe = Optional
                .fromNullable(cls.getMethod("addSawmillLogToPlankRecipe", ItemStack.class, ItemStack.class));
        craftingHelpers = Optional.of(cls.newInstance());
    } catch (final Exception e) {
        e.printStackTrace();
        craftingHelpers = Optional.absent();
        addSawmillLogToPlankRecipe = Optional.absent();
    }
}

From source file:org.codeqinvest.quality.analysis.ViolationsAnalysisResult.java

static ViolationsAnalysisResult createFailedAnalysis(List<ViolationOccurence> violations,
        String failureReason) {//from  w  w w . j  av a2 s.  c  o  m
    return new ViolationsAnalysisResult(false, violations, Optional.of(failureReason));
}

From source file:org.apache.gobblin.metrics.reporter.util.MetricReportUtils.java

/**
 * Parses a {@link org.apache.gobblin.metrics.MetricReport} from a byte array representing a json input.
 * @param reuse MetricReport to reuse./*from  www.j av  a  2 s  . c o m*/
 * @param bytes Input bytes.
 * @return MetricReport.
 * @throws java.io.IOException
 */
public synchronized static MetricReport deserializeReportFromJson(MetricReport reuse, byte[] bytes)
        throws IOException {
    if (!READER.isPresent()) {
        READER = Optional.of(new SpecificDatumReader<>(MetricReport.class));
    }

    Closer closer = Closer.create();

    try {
        DataInputStream inputStream = closer.register(new DataInputStream(new ByteArrayInputStream(bytes)));

        // Check version byte
        int versionNumber = inputStream.readInt();
        if (versionNumber != SCHEMA_VERSION) {
            throw new IOException(
                    String.format("MetricReport schema version not recognized. Found version %d, expected %d.",
                            versionNumber, SCHEMA_VERSION));
        }

        // Decode the rest
        Decoder decoder = DecoderFactory.get().jsonDecoder(MetricReport.SCHEMA$, inputStream);
        return READER.get().read(reuse, decoder);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}

From source file:org.apache.isis.runtimes.dflt.runtime.runner.opts.OptionValidatorForPersistor.java

private static Optional<String> setIf(final boolean fail, final String failMsg) {
    return fail ? Optional.of(failMsg) : Optional.<String>absent();
}