List of usage examples for com.google.common.base Optional orNull
@Nullable public abstract T orNull();
From source file:org.semanticweb.owlapi.model.OWLOntologyID.java
/** * replace an optional with a blank node iri with an absent optional * //w w w .ja v a 2 s .c o m * @param i * Optional to check * @return input optional if its iri is not a blank node iri, absent * otherwise */ @Nonnull private static Optional<IRI> opt(Optional<IRI> i) { if (NodeID.isAnonymousNodeIRI(i.orNull())) { return Optional.absent(); } return i; }
From source file:org.onos.yangtools.yang.model.util.SchemaNodeUtils.java
public static final SchemaNode getRootOriginalIfPossible(final SchemaNode data) { Optional<SchemaNode> previous = Optional.absent(); Optional<SchemaNode> next = getOriginalIfPossible(data); while (next.isPresent()) { previous = next;// w ww. java 2s .c o m next = getOriginalIfPossible(next.get()); } return previous.orNull(); }
From source file:org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils.java
public static SchemaNode getRootOriginalIfPossible(final SchemaNode data) { Optional<SchemaNode> previous = Optional.absent(); Optional<SchemaNode> next = getOriginalIfPossible(data); while (next.isPresent()) { previous = next;/*from w w w .j av a2s .co m*/ next = getOriginalIfPossible(next.get()); } return previous.orNull(); }
From source file:com.google.cloud.metrics.MetricsUtils.java
/** * Combines event and object type into a single type string. * * @param eventType type or category of the reporting event. * @param objectType optional type of the object this event applies to. * @return Combined type string.// w w w . j av a2 s . c o m */ static String buildCombinedType(String eventType, Optional<String> objectType) { return Joiner.on("/").skipNulls().join(eventType, objectType.orNull()); }
From source file:org.sonar.server.computation.task.projectanalysis.measure.MeasureAssert.java
public static MeasureAssert assertThat(@Nullable Optional<Measure> actual) { return new MeasureAssert(actual == null ? null : actual.orNull()); }
From source file:org.onos.yangtools.yang.model.util.MustDefinitionImpl.java
/** * * Creates new Must Definition/* w w w. jav a2s.c o m*/ * * @param mustStr must string statement, Must not be null. * @param description Description of condition * @param reference Reference for condition * @param errorAppTag error application tag which should be used for error reporting when condition fails * @param errorMessage message which should be used for error reporting when condition fails */ public static MustDefinitionImpl create(final String mustStr, final Optional<String> description, final Optional<String> reference, final Optional<String> errorAppTag, final Optional<String> errorMessage) { return new MustDefinitionImpl(mustStr, description.orNull(), reference.orNull(), errorAppTag.orNull(), errorMessage.orNull()); }
From source file:com.google.cloud.metrics.MetricsUtils.java
/** * Creates a virtual page name (relative URL) from an event type, object type and event name. * * @param eventType type or category of the reporting event. * @param objectType optional type of the object this event applies to. * @param eventName name of the reporting event. * @return Virtual page name constructed for this event. *//*from w w w . j a v a2 s .c om*/ static String buildVirtualPageName(String eventType, Optional<String> objectType, String eventName) { return Joiner.on("/").skipNulls().join(VIRTUAL_PAGE_PREFIX, eventType, objectType.orNull(), eventName); }
From source file:com.shufudong.GuavaExample.collect.OptionalExample.java
/** * @return//ww w. j a v a 2 s . co m * @category <p></p> * <ol> * <li> boolean isPresent()Optional?T?nulltrueTnullfalse</li> * <li>T get()Optional?TT???nullOptionalget()IllegalStateException</li> * <li>T or(T)Optional?T?Optional?T?T</li> * <li>T orNull()Optional??TOptional?null?fromNullable()</li> * <li>Set<T> asSet()??SetSet?Optional??TSet?T??Optional?T??Set</li> * </ol> * @throw */ public static void testMethodReturn() { Optional<Long> value = method(); if (value.isPresent() == true) { System.out.println(": " + value.get()); } else { System.out.println(": " + value.or(-12L)); } System.out.println(" orNull: " + value.orNull()); Optional<Long> valueNoNull = methodNoNull(); if (valueNoNull.isPresent() == true) { Set<Long> set = valueNoNull.asSet(); System.out.println(" set size : " + set.size()); System.out.println(": " + valueNoNull.get()); } else { System.out.println(": " + valueNoNull.or(-12L)); } System.out.println(" orNull: " + valueNoNull.orNull()); }
From source file:org.apache.gobblin.instrumented.Instrumented.java
/** * Generates a new {@link org.apache.gobblin.metrics.MetricContext} with the parent and tags taken from the reference context. * Allows replacing {@link org.apache.gobblin.metrics.Tag} with new input tags. * This method will not copy any {@link org.apache.gobblin.metrics.Metric} contained in the reference {@link org.apache.gobblin.metrics.MetricContext}. * * @param context Reference {@link org.apache.gobblin.metrics.MetricContext}. * @param newTags New {@link org.apache.gobblin.metrics.Tag} to apply to context. Repeated keys will override old tags. * @param name Name of the new {@link org.apache.gobblin.metrics.MetricContext}. * If absent or empty, will modify old name by adding a random integer at the end. * @return Generated {@link org.apache.gobblin.metrics.MetricContext}. *//* www.j av a2 s .c o m*/ public static MetricContext newContextFromReferenceContext(MetricContext context, List<Tag<?>> newTags, Optional<String> name) { String newName = name.orNull(); if (Strings.isNullOrEmpty(newName)) { UUID uuid = UUID.randomUUID(); String randomIdPrefix = "uuid:"; String oldName = context.getName(); List<String> splitName = Strings.isNullOrEmpty(oldName) ? Lists.<String>newArrayList() : Lists.newArrayList(Splitter.on(".").splitToList(oldName)); if (splitName.size() > 0 && StringUtils.startsWith(Iterables.getLast(splitName), randomIdPrefix)) { splitName.set(splitName.size() - 1, String.format("%s%s", randomIdPrefix, uuid.toString())); } else { splitName.add(String.format("%s%s", randomIdPrefix, uuid.toString())); } newName = Joiner.on(".").join(splitName); } MetricContext.Builder builder = context.getParent().isPresent() ? context.getParent().get().childBuilder(newName) : MetricContext.builder(newName); return builder.addTags(context.getTags()).addTags(newTags).build(); }
From source file:com.eucalyptus.util.CollectionUtils.java
public static <T> Function<Optional<T>, T> optionalOrNull() { return new Function<Optional<T>, T>() { @Nullable/*from ww w . ja v a2s. c om*/ @Override public T apply(final Optional<T> optional) { return optional == null ? null : optional.orNull(); } }; }