List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:gobblin.hive.HiveSchemaManager.java
/** * Get an instance of {@link HiveSchemaManager}. * * @param type The {@link HiveSchemaManager} type. It could be AVRO, NOP or the name of a class that implements * {@link HiveSchemaManager}. The specified {@link HiveSchemaManager} type must have a constructor that takes a * {@link State} object.// w ww .j a v a2 s . c om * @param props A {@link State} object used to instantiate {@link HiveSchemaManager}. */ public static HiveSchemaManager getInstance(String type, State props) { Optional<Implementation> implementation = Enums.getIfPresent(Implementation.class, type.toUpperCase()); if (implementation.isPresent()) { try { return (HiveSchemaManager) ConstructorUtils .invokeConstructor(Class.forName(implementation.get().toString()), props); } catch (ReflectiveOperationException e) { throw new RuntimeException( "Unable to instantiate " + HiveSchemaManager.class.getSimpleName() + " with type " + type, e); } } else { log.info(String.format("%s with type %s does not exist. Using %s", HiveSchemaManager.class.getSimpleName(), type, HiveNopSchemaManager.class.getSimpleName())); return new HiveNopSchemaManager(props); } }
From source file:org.apache.gobblin.hive.HiveSerDeWrapper.java
/** * Get an instance of {@link HiveSerDeWrapper}. * * @param serDeType The SerDe type. If serDeType is one of the available {@link HiveSerDeWrapper.BuiltInHiveSerDe}, * the other three parameters are not used. Otherwise, serDeType should be the class name of a {@link SerDe}, * and the other three parameters must be present. *///w ww .java 2 s . c o m public static HiveSerDeWrapper get(String serDeType, Optional<String> inputFormatClassName, Optional<String> outputFormatClassName) { Optional<BuiltInHiveSerDe> hiveSerDe = Enums.getIfPresent(BuiltInHiveSerDe.class, serDeType.toUpperCase()); if (hiveSerDe.isPresent()) { return new HiveSerDeWrapper(hiveSerDe.get()); } Preconditions.checkArgument(inputFormatClassName.isPresent(), "Missing input format class name for SerDe " + serDeType); Preconditions.checkArgument(outputFormatClassName.isPresent(), "Missing output format class name for SerDe " + serDeType); return new HiveSerDeWrapper(serDeType, inputFormatClassName.get(), outputFormatClassName.get()); }
From source file:com.google.errorprone.bugpatterns.threadsafety.AbstractLockMethodChecker.java
private static Optional<ImmutableSet<GuardedByExpression>> parseLockExpressions(List<String> lockExpressions, Tree tree, VisitorState state) { ImmutableSet.Builder<GuardedByExpression> builder = ImmutableSet.builder(); for (String lockExpression : lockExpressions) { Optional<GuardedByExpression> guard = GuardedByBinder.bindString(lockExpression, GuardedBySymbolResolver.from(tree, state)); if (!guard.isPresent()) { return Optional.absent(); }//from w w w. jav a2s. co m builder.add(guard.get()); } return Optional.of(builder.build()); }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.CaseShorthandImpl.java
private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) { if (caseShorthandNode instanceof DerivableSchemaNode) { final Optional<? extends SchemaNode> original = ((DerivableSchemaNode) caseShorthandNode).getOriginal(); if (original.isPresent()) { return new CaseShorthandImpl((DataSchemaNode) original.get()); }// w ww.ja v a2s .co m } return null; }
From source file:org.opendaylight.genius.utils.cache.DataStoreCache.java
public static <T extends DataObject> Object get(String cacheName, InstanceIdentifier<T> identifier, String key, DataBroker broker, boolean isConfig) { Object dataObject = getCache(cacheName).get(key); if (dataObject == null) { Optional<T> datastoreObject = MDSALDataStoreUtils.read(broker, isConfig ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL, identifier); if (datastoreObject.isPresent()) { dataObject = datastoreObject.get(); add(cacheName, key, dataObject); }//from w w w . j a v a 2 s.c om } return dataObject; }
From source file:jcomposition.processor.utils.AnnotationUtils.java
private static Optional<AnnotationValue> getParameterFrom(TypeElement typeElement, Class<? extends Annotation> annotationClass, String paramName, ProcessingEnvironment env) { Optional<AnnotationMirror> annotationMirror = MoreElements.getAnnotationMirror(typeElement, annotationClass);/*from w w w .j a v a2s . com*/ if (annotationMirror.isPresent()) { AnnotationValue value = getAnnotationValue(annotationMirror.get(), paramName, env); return Optional.fromNullable(value); } return Optional.absent(); }
From source file:com.google.errorprone.refaster.Choice.java
/** * Returns a choice of the optional value, if it is present, or the empty choice if it is absent. *//*from w w w. j av a 2 s. c o m*/ public static <T> Choice<T> fromOptional(Optional<T> optional) { return optional.isPresent() ? of(optional.get()) : Choice.<T>none(); }
From source file:com.google.devtools.build.lib.bazel.repository.StripPrefixedPath.java
/** * If a prefix is given, it will be removed from the entry's path. This also turns absolute paths * into relative paths (e.g., /usr/bin/bash will become usr/bin/bash, same as unzip's default * behavior) and normalizes the paths (foo/../bar////baz will become bar/baz). Note that this * could cause collisions, if a zip file had one entry for bin/some-binary and another entry for * /bin/some-binary./* www.j a v a2s.co m*/ * * Note that the prefix is stripped to move the files up one level, so if you have an entry * "foo/../bar" and a prefix of "foo", the result will be "bar" not "../bar". */ public static StripPrefixedPath maybeDeprefix(String entry, Optional<String> prefix) { Preconditions.checkNotNull(entry); PathFragment entryPath = relativize(entry); if (!prefix.isPresent()) { return new StripPrefixedPath(entryPath, false, false); } PathFragment prefixPath = relativize(prefix.get()); boolean found = false; boolean skip = false; if (entryPath.startsWith(prefixPath)) { found = true; entryPath = entryPath.relativeTo(prefixPath); if (entryPath.getPathString().isEmpty()) { skip = true; } } else { skip = true; } return new StripPrefixedPath(entryPath, found, skip); }
From source file:com.jaspersoft.android.jaspermobile.test.utils.espresso.JasperMatcher.java
public static ViewAssertion hasTotalCount(final int totalCount) { return new ViewAssertion() { @Override/*www . j a va 2 s.c o m*/ public void check(Optional<View> view, Optional<NoMatchingViewException> noView) { @SuppressWarnings("rawtypes") AbsListView adapter = ((AbsListView) view.get()); assertThat(adapter.getAdapter().getCount(), is(totalCount)); } }; }
From source file:com.eucalyptus.auth.tokens.RoleSecurityTokenAttributes.java
public static <T extends RoleSecurityTokenAttributes> Optional<T> fromContext(Class<T> type) { try {//from w w w . j av a 2 s . c o m final Context context = Contexts.lookup(); final UserPrincipal principal = context.getUser(); if (principal != null) { final Optional<RoleSecurityTokenAttributes> attributes = RoleSecurityTokenAttributes .forUser(principal); if (attributes.isPresent() && type.isInstance(attributes.get())) { return Optional.of(type.cast(attributes.get())); } } } catch (final IllegalContextAccessException e) { // absent } return Optional.absent(); }