List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:fathom.rest.controller.extractors.AuthExtractor.java
@Override public Account extract(Context context) { Account session = context.getSession(AuthConstants.ACCOUNT_ATTRIBUTE); Account local = context.getLocal(AuthConstants.ACCOUNT_ATTRIBUTE); Account account = Optional.fromNullable(session).or(Optional.fromNullable(local).or(Account.GUEST)); return account; }
From source file:com.vmware.photon.controller.apife.db.dao.AttachedDiskDao.java
public Optional<AttachedDiskEntity> findByDisk(BaseDiskEntity disk) { Query query;/* www .ja v a2 s . c om*/ switch (disk.getKind()) { case PersistentDisk.KIND: query = namedQuery("AttachedDisk.findByPersistentDisk"); break; case EphemeralDisk.KIND: query = namedQuery("AttachedDisk.findByEphemeralDisk"); break; default: throw new IllegalArgumentException(disk.getKind()); } return Optional.fromNullable(uniqueResult(query.setString("diskId", disk.getId()))); }
From source file:com.google.security.zynamics.binnavi.disassembly.types.RawTypeMember.java
public RawTypeMember(final int id, final String name, final int baseTypeId, final Integer parentId, final Integer offset, final Integer argument, final Integer numberOfElements) { this.id = id; this.name = Preconditions.checkNotNull(name, "Error: name can not be null"); this.baseTypeId = baseTypeId; this.parentId = parentId; Preconditions.checkArgument(offset == null || offset >= 0, "Error: offset must be positive."); this.offset = Optional.fromNullable(offset); this.argument = Optional.fromNullable(argument); Preconditions.checkArgument(numberOfElements == null || numberOfElements >= 0, "Error: number of elements must be null or greater than zero."); Preconditions.checkArgument(!Objects.equals(numberOfElements, offset) ^ this.argument.isPresent(), "Error: Either this is a struct member or a array member, or a prototype argument."); this.numberOfElements = Optional.fromNullable(numberOfElements); }
From source file:org.cloudifysource.cosmo.kvstore.KVStore.java
@Override public Optional<EntityTag> getEntityTag(URI key) { EntityTag etag = null;/*from w ww.ja v a 2 s . com*/ final EntityTagState<String> value = store.get(key); if (value != null) { etag = value.getEntityTag(); } return Optional.fromNullable(etag); }
From source file:com.spotify.helios.common.descriptors.PortMapping.java
public PortMapping(@JsonProperty("internalPort") final int internalPort, @JsonProperty("externalPort") final Integer externalPort, @JsonProperty("protocol") final String protocol) { this.internalPort = internalPort; this.externalPort = externalPort; this.protocol = Optional.fromNullable(protocol).or(TCP); }
From source file:org.opendaylight.yangtools.yang.parser.impl.util.YangSourceFromDependencyInfoResolver.java
@Override public Optional<YangModelDependencyInfo> getDependencyInfo(final SourceIdentifier identifier) { if (identifier.getRevision() != null) { return Optional.fromNullable(dependencyInfo.get(identifier)); }/*from w ww .ja v a 2s.c o m*/ YangModelDependencyInfo potential = dependencyInfo.get(identifier); if (potential == null) { for (Entry<SourceIdentifier, YangModelDependencyInfo> newPotential : dependencyInfo.entrySet()) { String newPotentialName = newPotential.getKey().getName(); if (newPotentialName.equals(identifier.getName())) { String newPotentialRevision = newPotential.getKey().getRevision(); if (potential == null || 1 == newPotentialRevision.compareTo(potential.getFormattedRevision())) { potential = newPotential.getValue(); } } } } return Optional.fromNullable(potential); }
From source file:org.eclipse.buildship.ui.view.task.OpenBuildScriptHandler.java
private Optional<File> getBuildScriptFor(ProjectNode projectNode) { Maybe<OmniGradleScript> buildScript = projectNode.getGradleProject().getBuildScript(); return buildScript.isPresent() ? Optional.fromNullable(buildScript.get().getSourceFile()) : Optional.<File>absent(); }
From source file:it.f2informatica.core.services.UserServiceImpl.java
@Override public Optional<UserModel> findByUsername(String username) { return Optional.fromNullable(userRepositoryGateway.findByUsername(username)); }
From source file:org.apache.aurora.scheduler.zookeeper.guice.client.flagged.FlaggedClientConfig.java
/** * Creates a configuration from command line arguments. * * @return Configuration instance./* w w w. j a v a 2 s . c o m*/ */ public static ClientConfig create() { return new ClientConfig(ZK_ENDPOINTS.get(), Optional.fromNullable(CHROOT_PATH.get()), IN_PROCESS.get(), SESSION_TIMEOUT.get(), DIGEST_CREDENTIALS.hasAppliedValue() ? getCredentials(DIGEST_CREDENTIALS.get()) : Credentials.NONE); }
From source file:org.auraframework.impl.css.parser.omakase.ThemeMediaQueryList.java
public Optional<MediaQueryList> queryList() { return Optional.fromNullable(queryList); }