List of usage examples for com.google.common.base Optional orNull
@Nullable public abstract T orNull();
From source file:org.sonar.server.component.ComponentService.java
@CheckForNull public ComponentDto getNullableByKey(String key) { DbSession session = dbClient.openSession(false); try {/*from www. j a v a 2 s.com*/ Optional<ComponentDto> component = dbClient.componentDao().selectByKey(session, key); return component.orNull(); } finally { session.close(); } }
From source file:org.jclouds.collect.internal.CallerArg0ToPagedIterable.java
@Override public PagedIterable<T> apply(IterableWithMarker<T> input) { if (input.nextMarker() == null) return PagedIterables.of(input); Optional<String> arg0Option = Optional.absent(); if (request.getCaller().get().getArgs().size() > 0) { Object arg0 = request.getCaller().get().getArgs().get(0); if (arg0 != null) arg0Option = Optional.of(arg0.toString()); }//from w w w . j a v a 2s. c om final String arg0 = arg0Option.orNull(); return PagedIterables.advance(input, markerToNextForCallingArg0(arg0)); }
From source file:org.eclipse.buildship.ui.launch.ProjectTab.java
@SuppressWarnings("Contract") @Override/*from w w w . j a va2 s. c o m*/ public boolean isValid(ILaunchConfiguration configuration) { String workingDirectoryExpression = this.workingDirectoryText.getText(); String workingDirectoryResolved; try { workingDirectoryResolved = ExpressionUtils.decode(workingDirectoryExpression); } catch (CoreException e) { setErrorMessage( NLS.bind(LaunchMessages.ErrorMessage_CannotResolveExpression_0, workingDirectoryExpression)); return false; } File workingDir = FileUtils.getAbsoluteFile(workingDirectoryResolved).orNull(); Optional<String> error = this.workingDirValidator.validate(workingDir); setErrorMessage(error.orNull()); return !error.isPresent(); }
From source file:com.dangdang.ddframe.rdb.sharding.parsing.parser.dialect.sqlserver.SQLServerParser.java
@Override protected boolean isRowNumberCondition(final SelectStatement selectStatement, final String columnLabel) { Optional<String> rowNumberAlias = Optional.absent(); for (SelectItem each : selectStatement.getItems()) { if (each.getAlias().isPresent() && "ROW_NUMBER".equalsIgnoreCase(each.getExpression())) { rowNumberAlias = each.getAlias(); }/*from w w w . j a v a 2s. c o m*/ } return columnLabel.equalsIgnoreCase(rowNumberAlias.orNull()); }
From source file:com.arpnetworking.tsdcore.statistics.SumStatistic.java
/** * {@inheritDoc}//from www . j av a 2 s . c om */ @Override public Quantity calculate(final List<Quantity> unorderedValues) { double sum = 0d; Optional<Unit> unit = Optional.absent(); for (final Quantity sample : unorderedValues) { sum += sample.getValue(); unit = unit.or(sample.getUnit()); } return new Quantity.Builder().setValue(sum).setUnit(unit.orNull()).build(); }
From source file:org.opendaylight.yangtools.yang.model.util.PatternConstraintImpl.java
PatternConstraintImpl(final String regex, final Optional<String> description, final Optional<String> reference, final String errorAppTag, final String errorMessage, final Optional<ModifierKind> modifier) { this.regex = Preconditions.checkNotNull(regex, "regex must not be null."); this.description = description.orNull(); this.reference = reference.orNull(); this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression"; this.errorMessage = errorMessage != null ? errorMessage : String.format("Supplied value does not match the regular expression %s.", regex); this.modifier = modifier.orNull(); }
From source file:com.pinterest.teletraan.resource.Builds.java
@GET @Path("/names") public List<String> getBuildNames(@QueryParam("filter") Optional<String> nameFilter, @QueryParam("start") Optional<Integer> start, @QueryParam("size") Optional<Integer> size) throws Exception { return buildDAO.getBuildNames(nameFilter.orNull(), start.or(1), size.or(DEFAULT_SIZE)); }
From source file:org.ow2.petals.cloud.manager.commands.paas.BaseCommand.java
/** * Get the deployment provider from its type * * @param type//from ww w. j a v a 2 s. c om * @return */ protected DeploymentProvider getDeploymentProvider(final String type) { checkNotNull(type); Optional<DeploymentProvider> support = Iterables.tryFind(supportedRuntimes, new Predicate<DeploymentProvider>() { public boolean apply(DeploymentProvider input) { return type.equalsIgnoreCase(input.getType()); } }); return support.orNull(); }
From source file:org.auraframework.util.ServiceLocator.java
@SuppressWarnings("unchecked") @Override/* w w w.j av a 2 s .c om*/ public <T extends AuraServiceProvider> T get(Class<T> type, String name) { try { ConcurrentMap<String, Optional<Object>> c = namedInstanceCache.get(type); if (c == null) { c = new ConcurrentHashMap<String, Optional<Object>>(); namedInstanceCache.putIfAbsent(type, c); } Optional<Object> o = c.get(name); if (o == null) { o = loadNamedInstance(type, name); c.putIfAbsent(name, o); } return (T) o.orNull(); } catch (Exception e) { throw new ServiceLocatorException(e); } }
From source file:org.locationtech.geogig.plumbing.diff.VerifyPatchOp.java
/** * Executes the verify command/* w ww .j av a 2s. co m*/ * * @return the result of checking if the patch can be applied */ protected VerifyPatchResults _call() throws RuntimeException { Preconditions.checkArgument(patch != null, "No patch file provided"); Patch patch = reverse ? this.patch.reversed() : this.patch; Map<ObjectId, RevFeatureType> typeCache = patch.featureTypes(); Patch toApply = new Patch(typeCache); Patch toReject = new Patch(typeCache); String path; Optional<RevObject> obj; List<FeatureDiff> diffs = patch.getModifiedFeatures(); for (FeatureDiff diff : diffs) { path = diff.getPath(); String refSpec = Ref.WORK_HEAD + ":" + path; obj = command(RevObjectParse.class).setRefSpec(refSpec).call(); if (!obj.isPresent()) { toReject.addModifiedFeature(diff); break; } RevFeature feature = (RevFeature) obj.get(); DepthSearch depthSearch = new DepthSearch(objectDatabase()); Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), path); RevFeatureType featureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId()) .call(RevFeatureType.class).get(); ImmutableList<PropertyDescriptor> descriptors = featureType.descriptors(); Set<Entry<PropertyDescriptor, AttributeDiff>> attrDiffs = diff.getDiffs().entrySet(); boolean ok = true; for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = attrDiffs.iterator(); iterator .hasNext();) { Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next(); AttributeDiff attrDiff = entry.getValue(); PropertyDescriptor descriptor = entry.getKey(); switch (attrDiff.getType()) { case ADDED: if (descriptors.contains(descriptor)) { ok = false; } break; case REMOVED: case MODIFIED: if (!descriptors.contains(descriptor)) { ok = false; break; } for (int i = 0; i < descriptors.size(); i++) { if (descriptors.get(i).equals(descriptor)) { Optional<Object> value = feature.get(i); if (!attrDiff.canBeAppliedOn(value.orNull())) { ok = false; } break; } } case NO_CHANGE: break;// nothing to do } } if (!ok) { toReject.addModifiedFeature(diff); } else { toApply.addModifiedFeature(diff); } } List<FeatureInfo> added = patch.getAddedFeatures(); for (FeatureInfo feature : added) { String refSpec = Ref.WORK_HEAD + ":" + feature.getPath(); obj = command(RevObjectParse.class).setRefSpec(refSpec).call(); if (obj.isPresent()) { toReject.addAddedFeature(feature.getPath(), feature.getFeature(), getType(feature.getFeatureTypeId(), typeCache)); } else { toApply.addAddedFeature(feature.getPath(), feature.getFeature(), getType(feature.getFeatureTypeId(), typeCache)); } } List<FeatureInfo> removed = patch.getRemovedFeatures(); for (FeatureInfo feature : removed) { String refSpec = Ref.WORK_HEAD + ":" + feature.getPath(); obj = command(RevObjectParse.class).setRefSpec(refSpec).call(); if (!obj.isPresent()) { toReject.addRemovedFeature(feature.getPath(), feature.getFeature(), getType(feature.getFeatureTypeId(), typeCache)); } else { RevFeature revFeature = (RevFeature) obj.get(); DepthSearch depthSearch = new DepthSearch(objectDatabase()); Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), feature.getPath()); ObjectId revFeatureTypeId = noderef.get().getMetadataId(); RevFeature patchRevFeature = feature.getFeature(); if (revFeature.equals(patchRevFeature) && revFeatureTypeId.equals(feature.getFeatureTypeId())) { toApply.addRemovedFeature(feature.getPath(), feature.getFeature(), getType(feature.getFeatureTypeId(), typeCache)); } else { toReject.addRemovedFeature(feature.getPath(), feature.getFeature(), getType(feature.getFeatureTypeId(), typeCache)); } } } ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees(); for (FeatureTypeDiff diff : alteredTrees) { DepthSearch depthSearch = new DepthSearch(objectDatabase()); Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), diff.getPath()); ObjectId metadataId = noderef.isPresent() ? noderef.get().getMetadataId() : ObjectId.NULL; if (Objects.equal(metadataId, diff.getOldFeatureType())) { toApply.addAlteredTree(diff); } else { toReject.addAlteredTree(diff); } } return new VerifyPatchResults(toApply, toReject); }