List of usage examples for com.google.common.base Optional absent
public static <T> Optional<T> absent()
From source file:org.dswarm.graph.batch.rdf.pnx.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }/* w ww.j a v a 2 s .c o m*/ final NodeType nodeType; final Node node = optionalNode.get(); if (node instanceof Resource) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } } else if (node instanceof BNode) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } } else if (node instanceof Literal) { nodeType = NodeType.Literal; } else { nodeType = null; } return Optional.fromNullable(nodeType); }
From source file:com.arpnetworking.utility.SampleUtils.java
/** * Converts all of the samples to a single unit. * * @param samples samples to convert/* ww w .j a v a 2s. c o m*/ * @return list of samples with a unified unit */ public static List<Quantity> unifyUnits(final List<Quantity> samples) { //This is a 2-pass operation: //First pass is to grab the smallest unit in the samples //Second pass is to convert everything to that unit Optional<Unit> smallestUnit = Optional.absent(); for (final Quantity sample : samples) { if (!smallestUnit.isPresent()) { smallestUnit = sample.getUnit(); } else if (sample.getUnit().isPresent() && smallestUnit.get().getSmallerUnit(sample.getUnit().get()) != smallestUnit.get()) { smallestUnit = sample.getUnit(); } } if (smallestUnit.isPresent()) { return FluentIterable.from(samples).transform(new SampleConverter(smallestUnit.get())).toList(); } return samples; }
From source file:fi.vm.sade.osoitepalvelu.kooste.common.util.CriteriaHelper.java
public static Optional<Criteria> inAnyKoodiVersion(Criteria c, String key, Collection<String> koodis) { if (koodis == null || koodis.isEmpty()) { return Optional.absent(); }//from ww w . ja v a 2 s. c o m Criteria[] criteria = new Criteria[koodis.size()]; int i = 0; for (String koodi : koodis) { // Strip the version part if specified: Matcher m = KOODI_WITH_VERSION.matcher(koodi); if (m.find()) { koodi = m.group(1); } criteria[i++] = Criteria.where(key).regex(Pattern.compile(koodi + OPTIONAL_KOODI_VERSION_POSTFIX)); } return Optional.of(c.orOperator(criteria)); }
From source file:org.brooklyncentral.catalog.scrape.CatalogItemScraper.java
private static Optional<String> getGithubRawText(String repoUrl, String fileName) { String rawGithubUrl = generateRawGithubUrl(repoUrl, fileName); try (InputStream inputStream = new URL(rawGithubUrl).openStream()) { return Optional.of(Streams.readFullyString(inputStream)); } catch (Exception e) { // TODO Log or something: String error = // "Unable to read raw Github URL " + rawGithubUrl + ": " + e, // e);/*from w w w. java2 s . c o m*/ return Optional.absent(); } }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.config.parser.XMLParsers.java
/** * The method returns the attribute value if any * @param in provides access to the XML data * @param name identifies the attribute to get value of * @return the matching value if any/* w w w. ja v a2s . c o m*/ */ public static Optional<String> getAttribute(XMLStreamReader in, String name) { int size = in.getAttributeCount(); for (int index = 0; index < size; index++) { if (in.getAttributeLocalName(index).equals(name)) { return Optional.of(in.getAttributeValue(index)); } } return Optional.absent(); }
From source file:org.apache.aurora.scheduler.http.api.security.FieldGetters.java
public static <P extends TBase<P, ?>, C extends TBase<C, ?>, G extends TBase<G, ?>> FieldGetter<P, G> compose( final FieldGetter<P, C> parent, final FieldGetter<C, G> child) { return new FieldGetter<P, G>() { @Override//from ww w . j a v a2 s .c o m public Class<P> getStructClass() { return parent.getStructClass(); } @Override public Class<G> getValueClass() { return child.getValueClass(); } @Override public Optional<G> apply(P input) { Optional<C> parentValue = parent.apply(input); if (parentValue.isPresent()) { return child.apply(parentValue.get()); } else { return Optional.absent(); } } }; }
From source file:springfox.documentation.spring.web.HandlerMethodReturnTypes.java
public static Optional<Class> useType(Class beanType) { if (Proxy.class.isAssignableFrom(beanType)) { return Optional.absent(); }/*w w w . j a v a 2s . c o m*/ if (Class.class.getName().equals(beanType.getName())) { return Optional.absent(); } return Optional.fromNullable(beanType); }
From source file:com.afterkraft.kraftrpg.api.util.DataUtil.java
public static Optional<DataView> copyFromExisting(DataView data) { return Optional.absent(); }
From source file:io.mesosphere.mesos.util.Functions.java
@NotNull public static <A> Optional<A> headOption(@NotNull final Iterable<A> iterable) { final Iterator<A> iter = iterable.iterator(); if (iter.hasNext()) { return Optional.fromNullable(iter.next()); } else {/* w w w .java 2s .c o m*/ return Optional.absent(); } }
From source file:org.automagic.deps.doctor.TransitiveDepsGroup.java
public TransitiveDepsGroup() { dependencies = new ArrayList<>(); topLevelDependency = Optional.absent(); }