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

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

Introduction

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

Prototype

public abstract boolean isPresent();

Source Link

Document

Returns true if this holder contains a (non-null) instance.

Usage

From source file:org.onos.yangtools.yang.data.api.schema.NormalizedNodes.java

public static Optional<NormalizedNode<?, ?>> findNode(final YangInstanceIdentifier rootPath,
        final NormalizedNode<?, ?> rootNode, final YangInstanceIdentifier childPath) {
    final Optional<YangInstanceIdentifier> relativePath = childPath.relativeTo(rootPath);
    if (relativePath.isPresent()) {
        return findNode(rootNode, relativePath.get());
    } else {//from  ww w  .  j a  v a 2 s  .  co m
        return Optional.absent();
    }
}

From source file:org.anhonesteffort.flock.crypto.KeyHelper.java

public static void generateAndSaveSaltAndKeyMaterial(Context context)
        throws IOException, GeneralSecurityException {
    Log.d(TAG, "GENERATING SALT AND KEY MATERIAL!");
    byte[] cipherKey = KeyUtil.generateCipherKey();
    byte[] macKey = KeyUtil.generateMacKey();
    byte[] salt = KeyUtil.generateSalt();

    Log.d(TAG, "SAVING SALT AND KEY MATERIAL!");
    KeyStore.saveCipherKey(context, cipherKey);
    KeyStore.saveMacKey(context, macKey);
    KeyStore.saveKeyMaterialSalt(context, salt);

    Optional<String> encryptedKeyMaterial = buildEncryptedKeyMaterial(context);
    if (encryptedKeyMaterial.isPresent())
        KeyStore.saveEncryptedKeyMaterial(context, encryptedKeyMaterial.get());
}

From source file:com.incapture.apigen.slate.gen.TypeNodeFactory.java

public static Collection<Node> createTypesNodes(Function function, TypesContainer typesContainer) {
    List<Node> nodes = new LinkedList<>();

    List<Field> fields = new LinkedList<>();
    fields.addAll(function.getParameters());
    fields.add(function.getReturnType());

    for (Field parameter : fields) {
        Optional<TypeDefinition> typeOptional = typesContainer.get(parameter.getPackageName(),
                parameter.getType());//from   w  w w  .j a v  a 2  s .c  o m
        if (typeOptional.isPresent()) {
            //add some description
            TypeDefinition typeDefinition = typeOptional.get();
            nodes.add(new HeaderNode(typeDefinition.getName(), 4));
            nodes.add(new TextNode(String.format("*%s*", typeDefinition.getDocumentation())));
            if (typeDefinition.isDeprecated()) {
                if (typeDefinition.getDeprecatedText() != null) {
                    nodes.add(new AsideNode("This type is deprecated: " + typeDefinition.getDeprecatedText(),
                            AsideNodeType.WARNING));
                } else {
                    nodes.add(new AsideNode("This type is deprecated.", AsideNodeType.WARNING));
                }
            }
            nodes.add(new EmptyLineNode());

            //add all the fields
            TableHeaderNode headerNode = new TableHeaderNode("Field", "Type");
            TableNode tableNode = new TableNode(headerNode);
            for (Field field : typeDefinition.getFields()) {
                String text = field.getType(); //maybe add <a href=''... link here, to link to other types?
                tableNode.getRows().add(new TableRowNode(field.getName(), text));
            }
            nodes.add(tableNode);
            nodes.add(new EmptyLineNode());
        }
    }
    return nodes;
}

From source file:extrabiomes.handlers.BiomeHandler.java

public static void enableBiomes() {
    final Set<WorldType> worldTypes = BiomeHelper.discoverWorldTypes();

    for (final BiomeSettings setting : BiomeSettings.values()) {
        final Optional<? extends BiomeGenBase> biome = setting.getBiome();
        if (!setting.isVanilla()) {
            if (setting.isEnabled() && biome.isPresent()) {
                BiomeHelper.enableBiome(worldTypes, biome.get());
            } else {
                LogHelper.fine("Custom biome %s disabled.", setting.toString());
            }/*from w  w w  .jav a 2  s.co m*/
        } else if (!setting.isEnabled()) {
            Extrabiomes.proxy.removeBiome(BiomeHelper.settingToBiomeGenBase(setting));
            LogHelper.fine("Vanilla biome %s disabled.", biome.toString());
        }

        if (setting.allowVillages() && biome.isPresent()) {
            BiomeManager.addVillageBiome(biome.get(), true);
            LogHelper.fine("Village spawning enabled for custom biome %s.", setting.toString());
        }
    }

}

From source file:org.opendaylight.netconf.messagebus.eventsources.netconf.NetconfEventSourceMount.java

private static <T extends DOMService> T getService(DOMMountPoint mountPoint, Class<T> service) {
    final Optional<T> optional = mountPoint.getService(service);
    Preconditions.checkState(optional.isPresent(), "Service not present on mount point: %s", service.getName());
    return optional.get();
}

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

public static String getDestinationStpOrFail(P2PServiceBaseType p2ps) {
    Optional<String> destStp = Optional.fromNullable(Strings.emptyToNull(p2ps.getDestSTP()));
    if (destStp.isPresent()) {
        return destStp.get();
    }//from w ww  . j a  v a2s  . c  o m

    throw Exceptions.missingParameter(Point2PointTypes.getSourceStp().getNamespace(),
            Point2PointTypes.getDestStp().getType(), "null");
}

From source file:springfox.documentation.spring.web.readers.operation.ResponseMessagesReader.java

public static int httpStatusCode(OperationContext context) {
    Optional<ResponseStatus> responseStatus = context.findAnnotation(ResponseStatus.class);
    int httpStatusCode = HttpStatus.OK.value();
    if (responseStatus.isPresent()) {
        httpStatusCode = responseStatus.get().value().value();
    }/*from  w  w w.ja  va 2 s  .  c o  m*/
    return httpStatusCode;
}

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

private static Optional<InputStream> read(ReplayFile replayFile) throws IOException {
    Optional<InputStream> in = replayFile.get("paths.json");
    if (!in.isPresent()) {
        in = replayFile.get("paths");
    }/*from w w  w.  j  a  v  a 2 s. c  o  m*/
    return in;
}

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

public static <T extends Annotation> Optional<T> annotationFromBean(ModelPropertyContext context,
        Class<T> annotationType) {

    Optional<BeanPropertyDefinition> propertyDefinition = context.getBeanPropertyDefinition();
    Optional<T> notNull = Optional.absent();
    if (propertyDefinition.isPresent()) {
        Optional<Method> getter = extractGetterFromPropertyDefinition(propertyDefinition.get());
        Optional<Field> field = extractFieldFromPropertyDefinition(propertyDefinition.get());
        notNull = findAnnotation(getter, annotationType).or(findAnnotation(field, annotationType));
    }//  w  ww.  j  a va  2  s .  co m

    return notNull;
}

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

public static ServiceDomainType getServiceDomainOrFail(NsiTopology topology, StpType stp) {
    Optional<ResourceRefType> serviceDomain = Optional.fromNullable(stp.getServiceDomain());
    if (serviceDomain.isPresent()) {
        Optional<ServiceDomainType> sd = Optional
                .fromNullable(topology.getServiceDomain(stp.getServiceDomain().getId()));
        if (sd.isPresent()) {
            return sd.get();
        }//from w  ww  .  jav  a2s  .  co m
    }
    throw Exceptions.noPathFound("Missing ServiceDomain for source sdpId=" + stp.getId());
}