List of usage examples for com.google.common.base Optional orNull
@Nullable public abstract T orNull();
From source file:org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite.java
public String getEndpointIpAddr(String vpnUuid) { if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) { LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName()); return null; }//from w w w. jav a 2 s. co m Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getFirstEndpointIpAddr() : getSecondEndpointIpAddr(); return optEndpointIpAddr.orNull(); }
From source file:org.geogit.osm.map.internal.OSMUnmapOp.java
@Override public RevTree call() { Iterator<NodeRef> iter = command(LsTreeOp.class).setReference(path).setStrategy(Strategy.FEATURES_ONLY) .call();/*from ww w. ja va2s .co m*/ FeatureMapFlusher flusher = new FeatureMapFlusher(getWorkTree()); while (iter.hasNext()) { NodeRef node = iter.next(); RevFeature revFeature = command(RevObjectParse.class).setObjectId(node.objectId()) .call(RevFeature.class).get(); RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()) .call(RevFeatureType.class).get(); List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors(); ImmutableList<Optional<Object>> values = revFeature.getValues(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( (SimpleFeatureType) revFeatureType.type()); String id = null; for (int i = 0; i < descriptors.size(); i++) { PropertyDescriptor descriptor = descriptors.get(i); if (descriptor.getName().getLocalPart().equals("id")) { id = values.get(i).get().toString(); } Optional<Object> value = values.get(i); featureBuilder.set(descriptor.getName(), value.orNull()); } Preconditions.checkNotNull(id, "No 'id' attribute found"); SimpleFeature feature = featureBuilder.buildFeature(id); unmapFeature(feature, flusher); } flusher.flushAll(); return getWorkTree().getTree(); }
From source file:ezbake.deployer.configuration.EzDeployerConfiguration.java
/** * Get a configuration value as a String. *//* w w w . ja va 2 s. c om*/ private String getString(Key key) { Optional<String> val = get(key); return val.orNull(); }
From source file:org.sonar.server.qualityprofile.RuleActivatorContextFactory.java
private void initActiveRules(String profileKey, RuleKey ruleKey, RuleActivatorContext context, DbSession session, boolean parent) { ActiveRuleKey key = ActiveRuleKey.of(profileKey, ruleKey); Optional<ActiveRuleDto> activeRule = db.activeRuleDao().selectByKey(session, key); Collection<ActiveRuleParamDto> activeRuleParams = null; if (activeRule.isPresent()) { activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(session, activeRule.get().getId()); }/*from ww w.j ava 2 s . co m*/ if (parent) { context.setParentActiveRule(activeRule.orNull()); context.setParentActiveRuleParams(activeRuleParams); } else { context.setActiveRule(activeRule.orNull()); context.setActiveRuleParams(activeRuleParams); } }
From source file:org.eclipse.buildship.ui.launch.GradleDistributionTab.java
@Override public boolean isValid(ILaunchConfiguration launchConfig) { if (!this.useAutomaticOption.getSelection()) { GradleDistributionWrapper gradleDistribution = getSelection(); Optional<String> error = this.gradleDistributionValidator.validate(gradleDistribution); setErrorMessage(error.orNull()); return !error.isPresent(); } else {//from ww w. j av a 2 s. c o m return true; } }
From source file:org.apache.aurora.scheduler.storage.log.WriteAheadStorage.java
@Override public void saveJobUpdate(IJobUpdate update, Optional<String> lockToken) { requireNonNull(update);/*from w ww.j a v a 2s . com*/ write(Op.saveJobUpdate(new SaveJobUpdate(update.newBuilder(), lockToken.orNull()))); jobUpdateStore.saveJobUpdate(update, lockToken); }
From source file:com.codebullets.sagalib.processing.SagaKeyReaderExtractor.java
/** * Does not throw an exception when accessing the loading cache for key readers. *///from ww w . j a va 2 s .co m 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; }
From source file:org.robotninjas.barge.log.DefaultRaftLog.java
public void updateVotedFor(@Nonnull Optional<Replica> vote) { LOGGER.debug("Voting for {}", vote.orNull()); setLastVotedFor(vote);/*ww w. j av a 2s . c om*/ try { LogProto.Vote.Builder voteBuilder = LogProto.Vote.newBuilder(); if (vote.isPresent()) { voteBuilder.setVotedFor(vote.get().toString()); } LogProto.JournalEntry entry = LogProto.JournalEntry.newBuilder().setVote(voteBuilder).build(); journal.write(entry.toByteArray(), WriteType.SYNC); } catch (IOException e) { Throwables.propagate(e); } }
From source file:pt.ist.maidSyncher.domain.dsi.DSIMilestone.java
public ACMilestone getAcMilestone(final ACProject acProject) { Optional<ACMilestone> optionalMilestone = Iterables.tryFind(getAcMilestonesSet(), new Predicate<ACMilestone>() { @Override// ww w . java2 s. c om public boolean apply(ACMilestone input) { if (input == null) return false; return ObjectUtils.equals(input.getProject(), acProject); } }); return optionalMilestone.orNull(); }
From source file:org.geogit.cli.porcelain.Conflicts.java
private void printConflictDiff(Conflict conflict, ConsoleReader console, GeoGIT geogit) throws IOException { FullDiffPrinter diffPrinter = new FullDiffPrinter(false, true); console.println("---" + conflict.getPath() + "---"); ObjectId mergeHeadId = geogit.command(RefParse.class).setName(Ref.MERGE_HEAD).call().get().getObjectId(); Optional<RevCommit> mergeHead = geogit.command(RevObjectParse.class).setObjectId(mergeHeadId) .call(RevCommit.class); ObjectId origHeadId = geogit.command(RefParse.class).setName(Ref.ORIG_HEAD).call().get().getObjectId(); Optional<RevCommit> origHead = geogit.command(RevObjectParse.class).setObjectId(origHeadId) .call(RevCommit.class); Optional<RevCommit> commonAncestor = geogit.command(FindCommonAncestor.class).setLeft(mergeHead.get()) .setRight(origHead.get()).call(); String ancestorPath = commonAncestor.get().getId().toString() + ":" + conflict.getPath(); Optional<NodeRef> ancestorNodeRef = geogit.command(FeatureNodeRefFromRefspec.class).setRefspec(ancestorPath) .call();//from w w w . j ava 2 s. c om String path = Ref.ORIG_HEAD + ":" + conflict.getPath(); Optional<NodeRef> oursNodeRef = geogit.command(FeatureNodeRefFromRefspec.class).setRefspec(path).call(); DiffEntry diffEntry = new DiffEntry(ancestorNodeRef.orNull(), oursNodeRef.orNull()); console.println("Ours"); diffPrinter.print(geogit, console, diffEntry); path = Ref.MERGE_HEAD + ":" + conflict.getPath(); Optional<NodeRef> theirsNodeRef = geogit.command(FeatureNodeRefFromRefspec.class).setRefspec(path).call(); diffEntry = new DiffEntry(ancestorNodeRef.orNull(), theirsNodeRef.orNull()); console.println("Theirs"); diffPrinter.print(geogit, console, diffEntry); }