Java Code Examples for com.google.common.base.Optional#orNull()
The following examples show how to use
com.google.common.base.Optional#orNull() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: estatio File: PostalAddressRepository.java License: Apache License 2.0 | 6 votes |
@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(); }
Example 2
Source Project: unleash-maven-plugin File: ReleaseUtil.java License: Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example 3
Source Project: estatio File: PostalAddressRepository.java License: Apache License 2.0 | 6 votes |
@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(); }
Example 4
Source Project: saga-lib File: SagaKeyReaderExtractor.java License: Apache License 2.0 | 6 votes |
/** * 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; }
Example 5
Source Project: verigreen File: JobWithDetails.java License: Apache License 2.0 | 5 votes |
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()); }
Example 6
Source Project: netcdf-java File: CachingThreddsS3Client.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@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(); }
Example 7
Source Project: datacollector File: HMSCache.java License: Apache License 2.0 | 5 votes |
/** * 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(); }
Example 8
Source Project: tac-kbp-eal File: StrictAssessmentCreator.java License: MIT License | 5 votes |
@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()); }
Example 9
Source Project: jersey-hmac-auth File: AbstractCachingAuthenticator.java License: Apache License 2.0 | 5 votes |
/** * 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; } }
Example 10
Source Project: onedev File: Project.java License: MIT License | 5 votes |
@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(); }
Example 11
Source Project: estatio File: PhoneOrFaxNumberRepository.java License: Apache License 2.0 | 5 votes |
@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(); }
Example 12
Source Project: Elasticsearch File: CrateSearchContext.java License: Apache License 2.0 | 5 votes |
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(); }
Example 13
Source Project: unleash-maven-plugin File: ScmProviderRegistry.java License: Eclipse Public License 1.0 | 5 votes |
@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(); }
Example 14
Source Project: tmc-intellij File: SettingsTmc.java License: MIT License | 5 votes |
@Override public void setOrganization(Optional<Organization> org) { if (org.isPresent()) { logger.info("Setting organization -> {}", org.get().getName()); } this.organization = org.orNull(); }
Example 15
Source Project: incubator-gobblin File: AvroFieldRetrieverConverter.java License: Apache License 2.0 | 4 votes |
@Override public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException { Optional<Schema> schema = AvroUtils.getFieldSchema(inputSchema, this.fieldLocation); return schema.orNull(); }
Example 16
Source Project: tmc-cli File: Account.java License: MIT License | 4 votes |
public void setOrganization(Optional<Organization> organization) { this.organization = organization.orNull(); }
Example 17
Source Project: tmc-intellij File: SettingsTmc.java License: MIT License | 4 votes |
@Override public void setCourse(Optional<Course> course) { logger.info("Setting course -> {}. @SettingsTmc", course); this.course = course.orNull(); }
Example 18
Source Project: tmc-intellij File: SettingsTmc.java License: MIT License | 4 votes |
public void setOauthCredentials(Optional<OauthCredentials> oauthCredentials) { logger.info("Setting oauthCredentials. @SettingsTmc"); this.oauthCredentials = oauthCredentials.orNull(); }
Example 19
Source Project: tmc-cli File: Account.java License: MIT License | 4 votes |
public void setOauthCredentials(Optional<OauthCredentials> oauthCredentials) { this.oauthCredentials = oauthCredentials.orNull(); }
Example 20
Source Project: tmc-cli File: Account.java License: MIT License | 4 votes |
public void setCurrentCourse(Optional<Course> currentCourse) { this.currentCourse = currentCourse.orNull(); }