下面列出了com.google.common.base.Optional#orNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
/**
* 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;
}
@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();
}
/**
* 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;
}
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());
}
@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();
}
/**
* 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();
}
@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;
}
}
@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();
}
@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();
}
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();
}
@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();
}
@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();
}
public void setOrganization(Optional<Organization> organization) {
this.organization = organization.orNull();
}
@Override
public void setCourse(Optional<Course> course) {
logger.info("Setting course -> {}. @SettingsTmc", course);
this.course = course.orNull();
}
public void setOauthCredentials(Optional<OauthCredentials> oauthCredentials) {
logger.info("Setting oauthCredentials. @SettingsTmc");
this.oauthCredentials = oauthCredentials.orNull();
}
public void setOauthCredentials(Optional<OauthCredentials> oauthCredentials) {
this.oauthCredentials = oauthCredentials.orNull();
}
public void setCurrentCourse(Optional<Course> currentCourse) {
this.currentCourse = currentCourse.orNull();
}