List of usage examples for com.google.common.base Optional orNull
@Nullable public abstract T orNull();
From source file:com.github.jsdossier.jscomp.JsDoc.java
public boolean hasAnnotation(Annotation target) { for (Marker marker : info.getMarkers()) { Optional<Annotation> annotation = Annotation.forMarker(marker); if (target.equals(annotation.orNull())) { return true; }//from ww w. ja v a 2s . c o m } return false; }
From source file:org.onos.yangtools.yang.model.util.LengthConstraintImpl.java
LengthConstraintImpl(final Number min, final Number max, final Optional<String> description, final Optional<String> reference) { super();/*from w ww .ja va2 s. co m*/ this.min = Preconditions.checkNotNull(min, "min must not be null."); this.max = Preconditions.checkNotNull(max, "max must not be null"); this.description = description.orNull(); this.reference = reference.orNull(); this.errorAppTag = "length-out-of-specified-bounds"; this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">"; }
From source file:gobblin.writer.AvroHdfsTimePartitionedWriter.java
/** * Check if the partition column value is present and is a Long object. Otherwise, use current system time. *//*from www . j a va 2s . c o m*/ protected long getRecordTimestamp(Optional<Object> writerPartitionColumnValue) { return writerPartitionColumnValue.orNull() instanceof Long ? (Long) writerPartitionColumnValue.get() : System.currentTimeMillis(); }
From source file:org.opendaylight.yangtools.yang.model.util.LengthConstraintImpl.java
LengthConstraintImpl(final Number min, final Number max, final Optional<String> description, final Optional<String> reference, final String errorAppTag, final String errorMessage) { this.min = Preconditions.checkNotNull(min, "min must not be null."); this.max = Preconditions.checkNotNull(max, "max must not be null"); this.description = description.orNull(); this.reference = reference.orNull(); this.errorAppTag = errorAppTag != null ? errorAppTag : "length-out-of-specified-bounds"; this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max + ">"; }
From source file:de.metas.ui.web.vaadin.window.components.CalloutFieldDependenciesBinder.java
private ICalloutField getCalloutField(final Property<?> property) { final Field<?> field = getField(property); if (field == null) { return null; }//from w w w . j a v a 2 s. c o m Optional<ICalloutField> calloutFieldOptional = calloutFields.get(field); if (calloutFieldOptional == null) { final ICalloutField calloutField = createCalloutField(field); calloutFieldOptional = Optional.fromNullable(calloutField); calloutFields.put(field, calloutFieldOptional); } return calloutFieldOptional.orNull(); }
From source file:org.knight.examples.guava.basic.UsingAvoidingNullExamples.java
public void run() { Optional<String> o1 = Optional.of("Guava-library"); if (o1.isPresent()) { log("o1: " + o1.get()); } else {/* ww w . j a v a 2 s . com*/ log("o1: " + o1.toString()); } Optional<String> o2 = Optional.absent(); try { //will cause a IllegalStateException log("o2: " + o2.get()); } catch (IllegalStateException e) { log("o2 is absent, use get() will cause a IllegalStateException."); } Optional<String> o3 = Optional.fromNullable(null); log("o3 present = " + o3.isPresent()); try { //will cause a IllegalStateException log("o3: " + o3.get()); } catch (IllegalStateException e) { log("o3 is absent, use get() will cause a IllegalStateException."); } if (o3.orNull() == null) { log("o3 is absent, so orNull() returns null."); } Optional<String> o4 = Optional.fromNullable("Hello World"); log("o4: " + o4.or("o4 is present, so this default value will not be printed.")); Optional<Book> o5 = Optional.of(Book.generateBook()); log("o5: " + o5.get().toString()); }
From source file:org.eclipse.buildship.ui.wizard.project.ProjectImportWizardController.java
private GradleDistributionWrapper createGradleDistribution(Optional<String> gradleDistributionType, Optional<String> gradleDistributionConfiguration) { DistributionType distributionType = DistributionType .valueOf(gradleDistributionType.or(DistributionType.WRAPPER.name())); String distributionConfiguration = gradleDistributionConfiguration.orNull(); return GradleDistributionWrapper.from(distributionType, distributionConfiguration); }
From source file:org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite.java
public String getOtherEndpoint(String vpnUuid) { if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) { LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName()); return null; }// ww w .j a v a 2 s .com Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr() : getFirstEndpointIpAddr(); return optEndpointIpAddr.orNull(); }
From source file:org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite.java
public String getOtherVpnName(String vpnName) { if (!isFirstEndpointVpnName(vpnName) && !isSecondEndpointVpnName(vpnName)) { LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnName, getInterVpnLinkName()); return null; }/*from ww w . j ava 2 s .c o m*/ Optional<String> optOtherVpnName = isFirstEndpointVpnName(vpnName) ? getSecondEndpointVpnUuid() : getFirstEndpointVpnUuid(); return optOtherVpnName.orNull(); }
From source file:org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite.java
public String getOtherEndpointIpAddr(String vpnUuid) { if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) { LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName()); return null; }/*from ww w . j a v a 2s. c om*/ Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr() : getFirstEndpointIpAddr(); return optEndpointIpAddr.orNull(); }