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.sonar.server.computation.task.projectanalysis.measure.MeasureDtoToMeasure.java

private static Measure.NewMeasureBuilder setCommonProperties(Measure.NewMeasureBuilder builder,
        MeasureDto measureDto) {//from   w w w. ja va  2s. c  o  m
    if (measureDto.getAlertStatus() != null) {
        Optional<Measure.Level> qualityGateStatus = toLevel(measureDto.getAlertStatus());
        if (qualityGateStatus.isPresent()) {
            builder.setQualityGateStatus(
                    new QualityGateStatus(qualityGateStatus.get(), measureDto.getAlertText()));
        }
    }
    if (hasAnyVariation(measureDto)) {
        builder.setVariation(measureDto.getVariation());
    }
    return builder;
}

From source file:org.opendaylight.netvirt.bgpmanager.BgpUtil.java

static VpnInstanceOpDataEntry getVpnInstanceOpData(DataBroker broker, String rd)
        throws InterruptedException, ExecutionException, TimeoutException {
    InstanceIdentifier<VpnInstanceOpDataEntry> id = getVpnInstanceOpDataIdentifier(rd);
    Optional<VpnInstanceOpDataEntry> vpnInstanceOpData = MDSALUtil.read(broker,
            LogicalDatastoreType.OPERATIONAL, id);
    if (vpnInstanceOpData.isPresent()) {
        return vpnInstanceOpData.get();
    }/*from www .jav  a 2s. c  o m*/
    return null;
}

From source file:org.sonar.server.computation.task.projectanalysis.measure.BatchMeasureToMeasure.java

private static Optional<Measure> toLevelMeasure(Measure.NewMeasureBuilder builder,
        ScannerReport.Measure batchMeasure) {
    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
        return toNoValueMeasure(builder, batchMeasure);
    }/*from   w ww .j av  a 2  s .  co m*/
    Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue().getValue());
    if (!level.isPresent()) {
        return toNoValueMeasure(builder, batchMeasure);
    }
    return of(builder.create(level.get()));
}

From source file:net.es.nsi.pce.pf.PfUtils.java

public static P2PServiceBaseType getP2PServiceBaseTypeOrFail(AttrConstraints constraints) {
    // Generic reservation information are in string constraint attributes,
    // but the P2PS specific constraints are in the P2PS P2PServiceBaseType.
    Optional<ObjectAttrConstraint> p2pObject = Optional
            .fromNullable(constraints.getObjectAttrConstraint(Point2PointTypes.P2PS));
    if (p2pObject.isPresent()) {
        return p2pObject.get().getValue(P2PServiceBaseType.class);
    }/*from ww w . j a  v a2 s  .  c o m*/

    throw Exceptions.missingParameter(Point2PointTypes.P2PS, "null", "null");
}

From source file:dagger2.internal.codegen.Util.java

/**
 * Unwraps an {@link Optional} of a {@link Wrapper} into an {@code Optional} of the underlying
 * type.//from   w w w.  jav a 2s  . c o  m
 */
static <T> Optional<T> unwrapOptionalEquivalence(Optional<Equivalence.Wrapper<T>> wrappedOptional) {
    return wrappedOptional.isPresent() ? Optional.of(wrappedOptional.get().get()) : Optional.<T>absent();
}

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

/**
 * Returns filename for this YANG module as specified in RFC 6020.
 *
 * Returns filename in format/*ww w . j a v a  2  s  .  co  m*/
 * <code>moduleName ['@' revision] '.yang'</code>
 *
 * Where Where revision-date is in format YYYY-mm-dd.
 *
 * <p>
 * See
 * http://tools.ietf.org/html/rfc6020#section-5.2
 *
 * @return Filename for this source identifier.
 */
public static final String toYangFileName(final String moduleName, final Optional<String> revision) {
    StringBuilder filename = new StringBuilder(moduleName);
    if (revision.isPresent()) {
        filename.append("@");
        filename.append(revision.get());
    }
    filename.append(".yang");
    return filename.toString();
}

From source file:de.azapps.mirakel.model.list.SpecialListsWhereDeserializer.java

@NonNull
private static Optional<SpecialListsBaseProperty> parseSpecialListWhere(final @NonNull JsonElement obj,
        final int deep) throws IllegalArgumentException {
    if (obj.isJsonObject()) {
        return parseSpecialListsCondition(obj);
    } else if (obj.isJsonArray()) {
        final List<SpecialListsBaseProperty> childs = new ArrayList<>(obj.getAsJsonArray().size());
        for (final JsonElement el : obj.getAsJsonArray()) {
            final Optional<SpecialListsBaseProperty> child = parseSpecialListWhere(el, deep + 1);
            if (child.isPresent()) {
                childs.add(child.get());
            }// w  w w .j a v a2s .c om
        }
        return of((SpecialListsBaseProperty) new SpecialListsConjunctionList(
                ((deep % 2) == 0) ? SpecialListsConjunctionList.CONJUNCTION.AND
                        : SpecialListsConjunctionList.CONJUNCTION.OR,
                childs));
    } else if (obj.isJsonNull()) {
        return absent();
    } else {
        throw new IllegalArgumentException("Unknown json type");
    }
}

From source file:net.es.nsi.pce.pf.PfUtils.java

public static P2PServiceBaseType removeP2PServiceBaseTypeOrFail(AttrConstraints constraints) {
    // Generic reservation information are in string constraint attributes,
    // but the P2PS specific constraints are in the P2PS P2PServiceBaseType.
    Optional<ObjectAttrConstraint> p2pObject = Optional
            .fromNullable(constraints.removeObjectAttrConstraint(Point2PointTypes.P2PS));
    if (p2pObject.isPresent()) {
        return p2pObject.get().getValue(P2PServiceBaseType.class);
    }//from w w w.j a  va 2 s. c  o  m

    throw Exceptions.missingParameter(Point2PointTypes.P2PS, "null", "null");
}

From source file:org.opendaylight.controller.netconf.util.xml.XmlUtil.java

public static Element createElement(final Document document, final String qName,
        final Optional<String> namespaceURI) {
    if (namespaceURI.isPresent()) {
        final Element element = document.createElementNS(namespaceURI.get(), qName);
        String name = XMLNS_ATTRIBUTE_KEY;
        if (element.getPrefix() != null) {
            name += ":" + element.getPrefix();
        }/*from  www  .j  a v  a 2  s  .c  o m*/
        element.setAttributeNS(XMLNS_URI, name, namespaceURI.get());
        return element;
    }
    return document.createElement(qName);
}

From source file:springfox.bean.validators.plugins.RangeAnnotations.java

public static AllowableRangeValues allowableRange(Optional<Min> min, Optional<Max> max) {
    AllowableRangeValues myvalues = null;

    if (min.isPresent() && max.isPresent()) {
        LOG.debug("@Min+@Max detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(Double.toString(min.get().value()), false,
                Double.toString(max.get().value()), false);

    } else if (min.isPresent()) {
        LOG.debug("@Min detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(Double.toString(min.get().value()), false, null, null);

    } else if (max.isPresent()) {
        LOG.debug("@Max detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(null, null, Double.toString(max.get().value()), false);
    }//w  ww.j a  va 2 s . c o m
    return myvalues;
}