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:be.nbb.demetra.various.SpreadSheetProviderBuddy2.java

private static DataSet toDataSet(TsMoniker moniker) {
    Optional<IDataSourceProvider> provider = TsProviders.lookup(IDataSourceProvider.class, moniker);
    if (provider.isPresent()) {
        DataSet dataSet = provider.get().toDataSet(moniker);
        if (dataSet != null) {
            return dataSet;
        }//w w  w  .j a va2 s  . c om
    }
    return null;
}

From source file:com.google.devtools.build.lib.rules.proto.ProtoCompileAction.java

/**
 * A convenience method to register an action, if it's present.
 * @param protoCompileActionOptional//  w w w .  ja  v  a2  s  . c  o  m
 */
public static void registerAction(Optional<ProtoCompileAction> protoCompileActionOptional) {
    if (protoCompileActionOptional.isPresent()) {
        protoCompileActionOptional.get().registerAction();
    }
}

From source file:org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper.java

public static List<Routes> getAllVpnExtraRoutes(DataBroker dataBroker, String vpnName, List<String> usedRds,
        String destPrefix) {//  w  w  w  . ja v  a  2s .  co  m
    List<Routes> routes = new ArrayList<>();
    for (String rd : usedRds) {
        Optional<Routes> extraRouteInfo = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
                getVpnToExtrarouteVrfIdIdentifier(vpnName, rd, destPrefix));
        if (extraRouteInfo.isPresent()) {
            routes.add(extraRouteInfo.get());
        }
    }
    return routes;
}

From source file:org.splevo.project.utils.SPLevoProjectUtil.java

/**
 * Loads a SPLevo project from a file resource.
 * //  w  w w. j av  a  2s  .c o m
 * @param consolidationProject
 *            The project that represents the consolidation project.
 * @return The loaded SPLevo project.
 * @throws IOException
 *             Thrown if the file could not be loaded.
 */
public static SPLevoProject loadSPLevoProjectModel(IProject consolidationProject) throws IOException {
    Optional<IFile> projectFile = findSPLevoProjectFile(consolidationProject);
    if (projectFile.isPresent()) {
        return loadSPLevoProjectModel(projectFile.get());
    }
    return null;
}

From source file:com.arpnetworking.utility.SampleUtils.java

/**
 * Converts all of the samples to a single unit.
 *
 * @param samples samples to convert//from ww w .j  av a  2 s  .co  m
 * @return list of samples with a unified unit
 */
public static List<Quantity> unifyUnits(final List<Quantity> samples) {
    //This is a 2-pass operation:
    //First pass is to grab the smallest unit in the samples
    //Second pass is to convert everything to that unit
    Optional<Unit> smallestUnit = Optional.absent();
    for (final Quantity sample : samples) {
        if (!smallestUnit.isPresent()) {
            smallestUnit = sample.getUnit();
        } else if (sample.getUnit().isPresent()
                && smallestUnit.get().getSmallerUnit(sample.getUnit().get()) != smallestUnit.get()) {
            smallestUnit = sample.getUnit();
        }
    }

    if (smallestUnit.isPresent()) {
        return FluentIterable.from(samples).transform(new SampleConverter(smallestUnit.get())).toList();
    }

    return samples;
}

From source file:org.sonar.server.computation.measure.MeasureDtoToMeasure.java

private static Measure.NewMeasureBuilder setCommonProperties(Measure.NewMeasureBuilder builder,
        MeasureDto measureDto) {//ww  w . j a  v  a  2  s .  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.setVariations(createVariations(measureDto));
    }
    Integer ruleId = measureDto.getRuleId();
    if (ruleId != null) {
        builder.forRule(ruleId);
    }
    return builder;
}

From source file:org.sonar.server.computation.task.projectanalysis.qualitymodel.NewMaintainabilityMeasuresVisitor.java

private static long getLongValue(Optional<Measure> measure) {
    if (!measure.isPresent()) {
        return 0L;
    }/* w  w  w .  j a  va  2s.  c  om*/
    return getLongValue(measure.get());
}

From source file:com.replaymod.replaystudio.pathing.serialize.LegacyTimelineConverter.java

private static KeyframeSet[] readAndParse(ReplayFile replayFile) throws IOException {
    Optional<InputStream> optIn = read(replayFile);
    if (!optIn.isPresent()) {
        return null;
    }/*  w  ww  .j  av  a 2  s .  c om*/
    KeyframeSet[] keyframeSets;
    try (InputStream in = optIn.get()) {
        keyframeSets = parse(in);
    }
    return keyframeSets;
}

From source file:org.opendaylight.vtn.manager.it.util.inventory.InventoryUtils.java

/**
 * Find a VTN port that meets the specified condition.
 *
 * @param rtx   A read-only MD-SAL datastore transaction.
 * @param nid   The node identifier string.
 * @param pid   A string representation of the port ID.
 * @param name  The name of the port./*from   ww w . ja  va 2s  . com*/
 * @return  A {@link VtnPort} instance if found.
 *          {@code null} otherwise.
 */
public static VtnPort findPort(ReadTransaction rtx, String nid, String pid, String name) {
    Optional<VtnNode> opt = DataStoreUtils.read(rtx, getVtnNodeIdentifier(nid));
    VtnPort found = null;
    if (opt.isPresent()) {
        List<VtnPort> ports = opt.get().getVtnPort();
        if (ports != null) {
            for (VtnPort vport : ports) {
                if (match(vport, nid, pid, name)) {
                    found = vport;
                    break;
                }
            }
        }
    }

    return found;
}

From source file:org.opendaylight.controller.sal.connect.netconf.NetconfMapping.java

static CompositeNode toNotificationNode(NetconfMessage message, Optional<SchemaContext> ctx) {
    if (ctx.isPresent()) {
        SchemaContext schemaContext = ctx.get();
        Set<NotificationDefinition> notifications = schemaContext.getNotifications();
        Document document = message.getDocument();
        return XmlDocumentUtils.notificationToDomNodes(document, Optional.fromNullable(notifications));
    }//ww w  . j a  v a 2s  .c  o  m
    return null;
}