List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:com.github.kevints.mesos.scheduler.server.LibprocessServletUtils.java
static Optional<PID> getSenderPid(HttpServletRequest req) { Optional<String> libprocessFrom = Optional.fromNullable(req.getHeader("X-Libprocess-From")); if (libprocessFrom.isPresent()) { try {//from w w w . j a v a2 s .c om return Optional.of(PID.fromString(libprocessFrom.get())); } catch (IllegalArgumentException e) { return Optional.absent(); } } Optional<String> userAgent = Optional.fromNullable(req.getHeader("User-Agent")); if (userAgent.isPresent()) { List<String> pid = Splitter.on("libprocess/").omitEmptyStrings().splitToList(userAgent.get()); if (pid.size() != 1) { return Optional.absent(); } else { try { return Optional.of(PID.fromString(pid.get(0))); } catch (IllegalArgumentException e) { return Optional.absent(); } } } return Optional.absent(); }
From source file:de.azapps.mirakel.helper.MirakelModelPreferences.java
@NonNull public static AccountMirakel getDefaultAccount() { final long id = settings.getLong("defaultAccountID", AccountMirakel.getLocal().getId()); final Optional<AccountMirakel> a = AccountMirakel.get(id); if (a.isPresent()) { return a.get(); }/*from w w w. j a va2 s. c o m*/ return AccountMirakel.getLocal(); }
From source file:com.google.gerrit.server.query.change.IsReviewedPredicate.java
@SuppressWarnings("deprecation") private static FieldDef<ChangeData, ?> getField(Schema<ChangeData> schema) { Optional<FieldDef<ChangeData, ?>> f = schema.getField(REVIEWEDBY, LEGACY_REVIEWED); checkState(f.isPresent(), "Schema %s missing field %s", schema.getVersion(), REVIEWEDBY.getName()); return f.get(); }
From source file:org.eclipse.buildship.core.workspace.internal.OutputLocationUpdater.java
public static void update(IJavaProject project, Optional<OmniEclipseOutputLocation> outputLocation, IProgressMonitor monitor) throws CoreException { if (outputLocation.isPresent()) { IPath projectPath = project.getProject().getFullPath(); String outputPath = outputLocation.get().getPath(); project.setOutputLocation(projectPath.append(outputPath), monitor); }// w w w .j av a 2 s. c om }
From source file:springfox.bean.validators.plugins.BeanValidators.java
public static <T extends Annotation> Optional<T> validatorFromField(ModelPropertyContext context, Class<T> annotationType) { Optional<AnnotatedElement> annotatedElement = context.getAnnotatedElement(); Optional<T> notNull = Optional.absent(); if (annotatedElement.isPresent()) { notNull = Optional.fromNullable(annotatedElement.get().getAnnotation(annotationType)); }// www .ja v a 2 s . c o m return notNull; }
From source file:org.anhonesteffort.flock.sync.key.KeySyncUtil.java
public static Optional<String[]> getSaltAndEncryptedKeyMaterial(Context context, DavAccount account) throws PropertyParseException, DavException, IOException { String[] saltAndEncryptedKeyMaterial = { "", "" }; Optional<HidingCalDavCollection> keyCollection = getKeyCollection(context, account); if (keyCollection.isPresent()) { if (keyCollection.get().getKeyMaterialSalt().isPresent() && keyCollection.get().getEncryptedKeyMaterial().isPresent()) { saltAndEncryptedKeyMaterial[0] = keyCollection.get().getKeyMaterialSalt().get(); saltAndEncryptedKeyMaterial[1] = keyCollection.get().getEncryptedKeyMaterial().get(); keyCollection.get().getStore().closeHttpConnection(); return Optional.of(saltAndEncryptedKeyMaterial); }/* w ww . j a v a 2 s . c o m*/ keyCollection.get().getStore().closeHttpConnection(); return Optional.absent(); } return Optional.absent(); }
From source file:com.google.testing.junit.runner.model.AntXmlResultWriter.java
private static String getFormattedRunTime(Optional<Interval> runTimeInterval) { return !runTimeInterval.isPresent() ? "0.0" : String.valueOf(runTimeInterval.get().toDurationMillis() / 1000.0D); }
From source file:org.opendaylight.vpnservice.interfacemgr.globals.InterfaceServiceUtil.java
public static short getVlanId(String interfaceName, DataBroker broker) { InstanceIdentifier<Interface> id = InstanceIdentifier.builder(Interfaces.class) .child(Interface.class, new InterfaceKey(interfaceName)).build(); Optional<Interface> ifInstance = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, id, broker); if (ifInstance.isPresent()) { IfL2vlan vlanIface = ifInstance.get().getAugmentation(IfL2vlan.class); short vlanId = vlanIface.getVlanId() == null ? 0 : vlanIface.getVlanId().getValue().shortValue(); return vlanId; }/*from www . j a va 2 s .co m*/ return -1; }
From source file:com.forerunnergames.tools.common.pool.AutoDisposable.java
/** * Acquires an AutoDisposable from the given pool and unpacks the reference, returning it as an Optional of the * AutoDisposable's parameterized type./*from w w w . j a v a2 s . c om*/ */ public static <T> Optional<T> acquireFrom(final ObjectPool<AutoDisposable<T>> pool) { Arguments.checkIsNotNull(pool, "pool"); final Optional<AutoDisposable<T>> ref = pool.acquire(); if (ref.isPresent()) return Optional.of(ref.get().unpack()); return Optional.absent(); }
From source file:org.opendaylight.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); return relativePath.isPresent() ? findNode(rootNode, relativePath.get()) : Optional.absent(); }