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.opendaylight.protocol.bgp.rib.spi.PeerRoleUtil.java

public static PeerRole roleForChange(final Optional<NormalizedNode<?, ?>> maybePeerRole) {
    if (maybePeerRole.isPresent()) {
        final LeafNode<?> peerRoleLeaf = (LeafNode<?>) maybePeerRole.get();
        return PeerRole.valueOf(BindingMapping.getClassName((String) peerRoleLeaf.getValue()));
    }//from  ww  w.ja va  2s . c o m
    return null;
}

From source file:google.registry.util.UrlFetchUtils.java

/** Sets the HTTP Basic Authentication header on an {@link HTTPRequest}. */
public static void setAuthorizationHeader(HTTPRequest req, Optional<String> login) {
    if (login.isPresent()) {
        String token = base64().encode(login.get().getBytes(UTF_8));
        req.addHeader(new HTTPHeader(AUTHORIZATION, "Basic " + token));
    }/*w  w w  .j av  a 2s.  com*/
}

From source file:li.klass.fhem.adapter.devices.core.generic.detail.actions.devices.MAXDetailActionProvider.java

private static boolean supportsHeating(XmlListDevice xmlListDevice) {
    Optional<String> mode = xmlListDevice.getState(MODE_STATE_NAME);
    return mode.isPresent() && MAXMode.modeFor(mode.get()).isPresent();
}

From source file:org.blockartistry.mod.ThermalRecycling.support.recipe.accessor.IC2AccessorBase.java

private static ItemStack crackRecipeInputOreDict(final Object o) {
    final RecipeInputOreDict r = (RecipeInputOreDict) o;
    final Optional<ItemStack> opt = ItemStackHelper.getItemStack(r.input, r.amount);
    return opt.isPresent() ? opt.get() : null;
}

From source file:org.apache.rya.indexing.pcj.fluo.app.export.ParametersBase.java

protected static boolean getBoolean(final Map<String, String> params, final String paramName,
        final boolean defaultValue) {
    checkNotNull(params);//from  w  ww  .  j a  va  2  s.c om
    checkNotNull(paramName);

    final Optional<String> paramValue = Optional.fromNullable(params.get(paramName));
    return paramValue.isPresent() ? Boolean.parseBoolean(paramValue.get()) : defaultValue;
}

From source file:org.locationtech.geogig.storage.impl.Blobs.java

public static List<String> readLines(Optional<byte[]> blob) {
    List<String> lines = ImmutableList.of();
    if (blob.isPresent()) {
        String contents = new String(blob.get(), Charsets.UTF_8);
        lines = Splitter.on("\n").splitToList(contents);
    }/*from  w  w w  .ja va  2 s .c om*/
    return lines;
}

From source file:org.opendaylight.faas.fabric.utils.InterfaceManager.java

public static LportAttribute getLogicalPortAttr(DataBroker broker, InstanceIdentifier<TerminationPoint> iid) {
    ReadTransaction rt = broker.newReadOnlyTransaction();
    Optional<TerminationPoint> opt = MdSalUtils.syncReadOper(rt, iid);
    if (opt.isPresent()) {
        TerminationPoint tp = opt.get();
        return tp.getAugmentation(LogicalPortAugment.class).getLportAttribute();
    }//from   ww  w  .  ja  va  2  s  .  c om
    return null;
}

From source file:module.organization.domain.groups.PersistentUnitGroup.java

static PersistentUnitGroup getInstance(final Unit unit, final Set<AccountabilityType> memberTypes,
        final Set<AccountabilityType> childUnitTypes) {
    Optional<PersistentUnitGroup> group = select(unit, memberTypes, childUnitTypes);
    return group.isPresent() ? group.get() : create(unit, memberTypes, childUnitTypes);
}

From source file:org.apache.distributedlog.namespace.DistributedLogNamespaceImpl.java

private static <T> java.util.Optional<T> gOptional2JOptional(Optional<T> gOptional) {
    if (gOptional.isPresent()) {
        return java.util.Optional.of(gOptional.get());
    } else {/*  ww w.java2  s. com*/
        return java.util.Optional.empty();
    }
}

From source file:module.organization.domain.groups.PersistentUnitGroup.java

@Atomic
private static PersistentUnitGroup create(final Unit unit, final Set<AccountabilityType> memberTypes,
        final Set<AccountabilityType> childUnitTypes) {
    Optional<PersistentUnitGroup> group = select(unit, memberTypes, childUnitTypes);
    return group.isPresent() ? group.get() : new PersistentUnitGroup(unit, memberTypes, childUnitTypes);
}