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.apache.aurora.scheduler.updater.InstanceUpdater.java

private static boolean isTaskPresent(Optional<IScheduledTask> task) {
    return task.isPresent() && !isPermanentlyKilled(task.get());
}

From source file:gobblin.hive.HiveMetaStoreClientFactory.java

private static HiveConf getHiveConf(Optional<String> hcatURI) {
    HiveConf hiveConf = new HiveConf();
    if (hcatURI.isPresent() && StringUtils.isNotBlank(hcatURI.get())) {
        hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, hcatURI.get());
        hiveConf.set(HIVE_METASTORE_TOKEN_SIGNATURE, hcatURI.get());
    }//w w w  .ja  va 2 s .  co  m
    return hiveConf;
}

From source file:springfox.documentation.schema.property.bean.Accessors.java

public static String propertyName(Method method) {
    Optional<JsonGetter> jsonGetterAnnotation = getterAnnotation(method);
    if (jsonGetterAnnotation.isPresent() && !isNullOrEmpty(jsonGetterAnnotation.get().value())) {
        return jsonGetterAnnotation.get().value();
    }// ww  w  . jav  a2s  .co  m
    Optional<JsonSetter> jsonSetterAnnotation = setterAnnotation(method);
    if (jsonSetterAnnotation.isPresent() && !isNullOrEmpty(jsonSetterAnnotation.get().value())) {
        return jsonSetterAnnotation.get().value();
    }
    Matcher matcher = getter.matcher(method.getName());
    if (matcher.find()) {
        return toCamelCase(matcher.group(1));
    }
    matcher = isGetter.matcher(method.getName());
    if (matcher.find()) {
        return toCamelCase(matcher.group(1));
    }
    matcher = setter.matcher(method.getName());
    if (matcher.find()) {
        return toCamelCase(matcher.group(1));
    }
    return "";
}

From source file:org.icgc.dcc.release.job.summarize.task.FeatureTypeSummarizeTask.java

/**
 * Filter out occurrences that have only 'controlled' observations. If an occurrence has both 'controlled' and
 * 'masked' it's passed downstream.//  www .j av  a  2s  .c  om
 */
private static Function<ObjectNode, Boolean> filterControlled() {
    return o -> {
        ArrayNode observations = o.withArray(FieldNames.LoaderFieldNames.OBSERVATION_ARRAY_NAME);
        boolean hasControlled = false;
        for (JsonNode observation : observations) {
            Optional<Marking> marking = Observations.getMarking(observation);
            if (marking.get().isControlled()) {
                hasControlled = true;
            } else {
                return Boolean.TRUE;
            }
        }

        return !hasControlled;
    };
}

From source file:com.github.jeluard.guayaba.base.Optionals.java

/**
 * @param <T>/*from   w w  w . j av  a 2  s. co  m*/
 * @param optional
 * @return an {@link Optional} returning encapsulated {@link Optional}
 */
public static <T> Optional<T> flatten(final Optional<Optional<T>> optional) {
    Preconditions.checkNotNull(optional, "null optional");

    if (!optional.isPresent()) {
        return Optional.absent();
    }

    return optional.get();
}

From source file:org.apache.gobblin.metadata.GlobalMetadata.java

/**
 * Builder that takes in an input {@GlobalMetadata} to use as a base.
 * @param inputMetadata input metadata// w ww . ja  v a 2  s.  c o  m
 * @param outputSchema output schema to set in the builder
 * @param <SI> input schema type
 * @param <SO> output schema type
 * @return builder
 */
public static <SI, SO> GlobalMetadataBuilder<SO> builderWithInput(GlobalMetadata<SI> inputMetadata,
        Optional<SO> outputSchema) {
    GlobalMetadataBuilder<SO> builder = (GlobalMetadataBuilder<SO>) builder();

    if (outputSchema.isPresent()) {
        builder.schema(outputSchema.get());
    }

    return builder;
}

From source file:springfox.documentation.swagger.readers.parameter.ParameterAnnotationReader.java

@SuppressWarnings("unchecked")
private static <A extends Annotation> A searchOnInterfaces(Method method, int parameterIndex,
        Class<A> annotationType, Class<?>[] interfaces) {

    A annotation = null;/* w  ww  .  j  a v  a  2 s  .  c om*/
    for (Class<?> interfaze : interfaces) {
        Optional<Method> interfaceMethod = interfaceMethod(interfaze, method);
        if (interfaceMethod.isPresent()) {
            Method superMethod = interfaceMethod.get();
            Optional<Annotation> found = tryFind(
                    newArrayList(superMethod.getParameterAnnotations()[parameterIndex]),
                    annotationOfType(annotationType));
            if (found.isPresent()) {
                annotation = (A) found.get();
                break;
            }
            Class<?>[] superInterfaces = superMethod.getDeclaringClass().getInterfaces();
            annotation = searchOnInterfaces(superMethod, parameterIndex, annotationType, superInterfaces);
        }
    }
    return annotation;
}

From source file:de.azapps.tools.OptionalUtils.java

@Nullable
public static <F, V> V transformOrNull(@NonNull final Optional<F> optional,
        @NonNull final Function<F, V> transformation) {
    if (optional.isPresent()) {
        return transformation.apply(optional.get());
    } else {//from  w ww .  ja v a 2s  . c  o m
        return null;
    }
}

From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.BindingHelper.java

public static Optional<String> getIdentifier(final ITypeBinding b) {
    if (b == null) {
        return absent();
    }/*from w  w w . j av  a 2s  .  com*/
    final Optional<ITypeName> opt = BindingUtils.toTypeName(b);
    if (!opt.isPresent()) {
        return absent();
    }
    return of(opt.get().getIdentifier());
}

From source file:cc.recommenders.utils.parser.VersionParserFactory.java

public static Version parse(final String version) {
    final Optional<IVersionParser> opt = getCompatibleParser(version);
    ensureIsTrue(opt.isPresent(), "Given version string '%s' has unknown format and can not be parsed.",
            version);/*from w ww .j a  v  a  2 s  . c om*/
    return opt.get().parse(version);
}