com.google.common.base.Optional#orNull ( )源码实例Demo

下面列出了com.google.common.base.Optional#orNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: estatio   文件: PostalAddressRepository.java
@Programmatic
public PostalAddress findByAddress(
        final CommunicationChannelOwner owner, 
        final String address1, 
        final String postalCode, 
        final String city, 
        final Country country) {

    // TODO: rewrite to use JDK8 streams
    final List<CommunicationChannelOwnerLink> links =
            communicationChannelOwnerLinkRepository.findByOwnerAndCommunicationChannelType(owner, CommunicationChannelType.POSTAL_ADDRESS);
    final Iterable<PostalAddress> postalAddresses =
            Iterables.transform(
                    links,
                    CommunicationChannelOwnerLink.Functions.communicationChannel(PostalAddress.class));
    final Optional<PostalAddress> postalAddressIfFound =
            Iterables.tryFind(postalAddresses, PostalAddress.Predicates.equalTo(address1, postalCode, city, country));
    return postalAddressIfFound.orNull();
}
 
源代码2 项目: unleash-maven-plugin   文件: ReleaseUtil.java
/**
 * Determines the home directory of the maven installation to be used.
 *
 * @param userDefined an optional user-defined path to use as maven home.
 * @return a path to a maven installation or {@code null} if none could be determined.
 */
public static File getMavenHome(Optional<String> userDefined) {
  String path = null;
  if (isValidMavenHome(userDefined.orNull())) {
    path = userDefined.orNull();
  } else {
    String sysProp = System.getProperty("maven.home");
    if (isValidMavenHome(sysProp)) {
      path = sysProp;
    } else {
      String envVar = System.getenv("M2_HOME");
      if (isValidMavenHome(envVar)) {
        path = envVar;
      }
    }
  }
  if (path != null) {
    return new File(path);
  }
  return null;
}
 
源代码3 项目: estatio   文件: PostalAddressRepository.java
@Programmatic
public PostalAddress findByAddress(
        final CommunicationChannelOwner owner,
        final String address1,
        final String address2,
        final String address3,
        final String postalCode,
        final String city,
        final Country country) {

    final List<CommunicationChannelOwnerLink> links =
            communicationChannelOwnerLinkRepository.findByOwnerAndCommunicationChannelType(owner, CommunicationChannelType.POSTAL_ADDRESS);
    final Iterable<PostalAddress> postalAddresses =
            Iterables.transform(
                    links,
                    CommunicationChannelOwnerLink.Functions.communicationChannel(PostalAddress.class));
    final Optional<PostalAddress> postalAddressIfFound =
            Iterables.tryFind(postalAddresses, PostalAddress.Predicates.equalTo(address1, address2, address3, postalCode, city, country));
    return postalAddressIfFound.orNull();
}
 
源代码4 项目: saga-lib   文件: SagaKeyReaderExtractor.java
/**
 * Does not throw an exception when accessing the loading cache for key readers.
 */
private KeyReader tryGetKeyReader(final Class<? extends Saga> sagaClazz, final Object message) {
    KeyReader reader;

    try {
        Optional<KeyReader> cachedReader = knownReaders.get(
                SagaMessageKey.forMessage(sagaClazz, message),
                () -> {
                    KeyReader foundReader = findReader(sagaClazz, message);
                    return Optional.fromNullable(foundReader);
                });
        reader = cachedReader.orNull();
    } catch (Exception ex) {
        LOG.error("Error searching for reader to extract saga key. sagatype = {}, message = {}", sagaClazz, message, ex);
        reader = null;
    }

    return reader;
}
 
源代码5 项目: verigreen   文件: JobWithDetails.java
public Build getBuildByNumber(final int buildNumber) {
    
    Predicate<Build> isMatchingBuildNumber = new Predicate<Build>() {
        
        @Override
        public boolean apply(Build input) {
            return input.getNumber() == buildNumber;
        }
    };
    
    Optional<Build> optionalBuild = Iterables.tryFind(builds, isMatchingBuildNumber);
    return optionalBuild.orNull() == null ? null : buildWithClient(optionalBuild.orNull());
}
 
源代码6 项目: netcdf-java   文件: CachingThreddsS3Client.java
@Override
public ObjectListing listObjects(S3URI s3uri) {
  Optional<ObjectListing> objectListing = objectListingCache.getIfPresent(s3uri);
  if (objectListing == null) {
    logger.debug(String.format("ObjectListing cache MISS: '%s'", s3uri));
    objectListing = Optional.fromNullable(threddsS3Client.listObjects(s3uri));
    objectListingCache.put(s3uri, objectListing);
  } else {
    logger.debug(String.format("ObjectListing cache hit: '%s'", s3uri));
  }

  return objectListing.orNull();
}
 
源代码7 项目: datacollector   文件: HMSCache.java
/**
 * Returns if the {@link HMSCache} has the corresponding {@link HMSCacheSupport.HMSCacheInfo} and qualified table name.
 * @param hmsCacheType {@link HMSCacheType}
 * @param qualifiedTableName qualified table name
 * @param <T> {@link HMSCacheSupport.HMSCacheInfo}
 * @return Corresponding {@link HMSCacheSupport.HMSCacheInfo} for the qualified table name.
 * @throws StageException if the {@link HMSCacheType} is not supported by {@link HMSCache}
 */
@SuppressWarnings("unchecked")
public <T extends HMSCacheSupport.HMSCacheInfo> T getIfPresent(
    HMSCacheType hmsCacheType,
    String qualifiedTableName
) throws StageException {
  if (!cacheMap.containsKey(hmsCacheType)) {
    throw new StageException(Errors.HIVE_16, hmsCacheType);
  }
  Optional<HMSCacheSupport.HMSCacheInfo> ret = cacheMap.get(hmsCacheType).getIfPresent(qualifiedTableName);
  return ret == null ? null : (T)ret.orNull();
}
 
源代码8 项目: tac-kbp-eal   文件: StrictAssessmentCreator.java
@Override
public AssessmentParseResult createAssessmentFromFields(Optional<FieldAssessment> aet,
    Optional<FieldAssessment> aer, Optional<FieldAssessment> casAssessment,
    Optional<KBPRealis> realis,
    Optional<FieldAssessment> baseFillerAssessment, Optional<Integer> coreference,
    Optional<FillerMentionType> mentionTypeOfCAS) {
  return new AssessmentParseResult(ResponseAssessment.of(aet, aer, casAssessment, realis,
      baseFillerAssessment, mentionTypeOfCAS), coreference.orNull());
}
 
/**
 * If the Principal for this Credentials is already cached, return it.  Otherwise call {@link #loadPrincipal} and cache the results.
 */
@Override
protected final Principal getPrincipal(final Credentials credentials) {
    try {
        Optional<Principal> principalOptional = cache.get(credentials.getApiKey(), new Callable<Optional<Principal>>() {
            public Optional<Principal> call() throws Exception {
                return Optional.fromNullable(loadPrincipal(credentials));
            }
        });
        return principalOptional.orNull();
    } catch (ExecutionException e) {
        LOG.warn("Exception when loading the cache for credentials with API key " + credentials.getApiKey());
        return null;
    }
}
 
源代码10 项目: onedev   文件: Project.java
@Nullable
public Ref getRef(String revision) {
	if (refCache == null)
		refCache = new HashMap<>();
	Optional<Ref> optional = refCache.get(revision);
	if (optional == null) {
		try {
			optional = Optional.fromNullable(getRepository().findRef(revision));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		refCache.put(revision, optional);
	}
	return optional.orNull();
}
 
源代码11 项目: estatio   文件: PhoneOrFaxNumberRepository.java
@Programmatic
public PhoneOrFaxNumber findByPhoneOrFaxNumber(
        final CommunicationChannelOwner owner,
        final String phoneNumber) {

    final Optional<PhoneOrFaxNumber> phoneNumberIfFound = findByPhoneOrFaxNumber(owner, phoneNumber, CommunicationChannelType.PHONE_NUMBER);
    if(phoneNumberIfFound.isPresent()) {
        return phoneNumberIfFound.get();
    }

    final Optional<PhoneOrFaxNumber> faxNumberIfFound = findByPhoneOrFaxNumber(owner, phoneNumber, CommunicationChannelType.FAX_NUMBER);
    return faxNumberIfFound.orNull();
}
 
源代码12 项目: Elasticsearch   文件: CrateSearchContext.java
private CrateSearchShardRequest(long nowInMillis, Optional<Scroll> scroll,
                                IndexShard indexShard) {
    this.nowInMillis = nowInMillis;
    this.scroll = scroll.orNull();
    this.index = indexShard.indexService().index().name();
    this.shardId = indexShard.shardId().id();
}
 
源代码13 项目: unleash-maven-plugin   文件: ScmProviderRegistry.java
@PostConstruct
private void init() {
  Optional<String> providerName = MavenScmUtil.calcProviderName(this.project);
  if (!providerName.isPresent()) {
    this.log.error(
        "Could not determine SCM provider name from your POM configuration! Please check the SCM section of your POM and provide connections in the correct format (see also: https://maven.apache.org/scm/scm-url-format.html).");
  } else {
    this.log.debug("Resolved required SCM provider implementation to '" + providerName.get() + "'");
  }
  this.scmProviderName = providerName.orNull();
}
 
源代码14 项目: tmc-intellij   文件: SettingsTmc.java
@Override
public void setOrganization(Optional<Organization> org) {
    if (org.isPresent()) {
        logger.info("Setting organization -> {}", org.get().getName());
    }
    this.organization = org.orNull();
}
 
@Override
public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
  Optional<Schema> schema = AvroUtils.getFieldSchema(inputSchema, this.fieldLocation);

  return schema.orNull();
}
 
源代码16 项目: tmc-cli   文件: Account.java
public void setOrganization(Optional<Organization> organization) {
    this.organization = organization.orNull();
}
 
源代码17 项目: tmc-intellij   文件: SettingsTmc.java
@Override
public void setCourse(Optional<Course> course) {
    logger.info("Setting course -> {}. @SettingsTmc", course);
    this.course = course.orNull();
}
 
源代码18 项目: tmc-intellij   文件: SettingsTmc.java
public void setOauthCredentials(Optional<OauthCredentials> oauthCredentials) {
    logger.info("Setting oauthCredentials. @SettingsTmc");
    this.oauthCredentials = oauthCredentials.orNull();
}
 
源代码19 项目: tmc-cli   文件: Account.java
public void setOauthCredentials(Optional<OauthCredentials> oauthCredentials) {
    this.oauthCredentials = oauthCredentials.orNull();
}
 
源代码20 项目: tmc-cli   文件: Account.java
public void setCurrentCourse(Optional<Course> currentCourse) {
    this.currentCourse = currentCourse.orNull();
}