Example usage for com.google.common.base Optional absent

List of usage examples for com.google.common.base Optional absent

Introduction

In this page you can find the example usage for com.google.common.base Optional absent.

Prototype

public static <T> Optional<T> absent() 

Source Link

Document

Returns an Optional instance with no contained reference.

Usage

From source file:manifestor.util.ManifestUtil.java

public final static Optional<Map<String, String>> readManifestFromInputStream(final InputStream inputStream) {
    try {//  w  ww  . ja  va2 s  .  c o  m
        final Map<String, String> manifestMap = ManifestUtil.load(inputStream);
        return Optional.of(manifestMap);
    } catch (IOException ioex) {
        logger.error("Failed to fetch manifest details", ioex);
    }

    return Optional.absent();
}

From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.StringCharactersSpan.java

@Override
public Optional<? extends Inline> createInline(Cursor cursor) {
    Matcher matcher = cursor.matcher(pattern);
    if (matcher.matches()) {
        String group = matcher.group(1);
        int length = cursor.getOffset(matcher.end(1)) - cursor.getOffset();
        return Optional.of(new Characters(cursor.getLineAtOffset(), cursor.getOffset(), length, group));
    }//from  w w w  .j a  v a2 s  .co  m
    return Optional.absent();
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ArrayAttributeMappingStrategy.java

@Override
public Optional<List<Object>> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }// w  ww.  ja va2s .c om

    Preconditions.checkArgument(value.getClass().isArray(), "Value has to be instanceof Array ");

    List<Object> retVal = Lists.newArrayList();

    for (int i = 0; i < Array.getLength(value); i++) {
        Object innerValue = Array.get(value, i);
        Optional<?> mapAttribute = innerElementStrategy.mapAttribute(innerValue);

        if (mapAttribute.isPresent()) {
            retVal.add(mapAttribute.get());
        }
    }

    return Optional.of(retVal);
}

From source file:org.apache.aurora.scheduler.filter.ConstraintMatcher.java

/**
 * Gets the veto (if any) for a scheduling constraint based on the {@link AttributeAggregate} this
 * filter was created with./* www .j  a  v a 2  s  .  co m*/
 *
 * @param constraint Scheduling filter to check.
 * @return A veto if the constraint is not satisfied based on the existing state of the job.
 */
static Optional<Veto> getVeto(AttributeAggregate cachedjobState, Iterable<IAttribute> hostAttributes,
        IConstraint constraint) {

    Iterable<IAttribute> sameNameAttributes = Iterables.filter(hostAttributes,
            new NameFilter(constraint.getName()));
    Optional<IAttribute> attribute;
    if (Iterables.isEmpty(sameNameAttributes)) {
        attribute = Optional.absent();
    } else {
        Set<String> attributeValues = ImmutableSet
                .copyOf(Iterables.concat(Iterables.transform(sameNameAttributes, GET_VALUES)));
        attribute = Optional.of(IAttribute.build(new Attribute(constraint.getName(), attributeValues)));
    }

    ITaskConstraint taskConstraint = constraint.getConstraint();
    switch (taskConstraint.getSetField()) {
    case VALUE:
        boolean matches = AttributeFilter.matches(attribute.transform(GET_VALUES).or(ImmutableSet.of()),
                taskConstraint.getValue());
        return matches ? Optional.absent() : Optional.of(Veto.constraintMismatch(constraint.getName()));

    case LIMIT:
        if (!attribute.isPresent()) {
            return Optional.of(Veto.constraintMismatch(constraint.getName()));
        }

        boolean satisfied = AttributeFilter.matches(attribute.get(), taskConstraint.getLimit().getLimit(),
                cachedjobState);
        return satisfied ? Optional.absent() : Optional.of(Veto.unsatisfiedLimit(constraint.getName()));

    default:
        throw new SchedulerException(
                "Failed to recognize the constraint type: " + taskConstraint.getSetField());
    }
}

From source file:com.stepstone.sonar.plugin.coldfusion.cflint.xml.LocationAttributes.java

public LocationAttributes(XMLStreamReader stream) {
    file = getAttributeValue("file", stream);
    message = getAttributeValue("message", stream);

    Optional<String> line = getAttributeValue("line", stream);

    if (line.isPresent()) {
        this.line = Optional.of(Integer.parseInt(line.get()));
    } else {/*from w w  w . j a v  a  2  s .c o  m*/
        this.line = Optional.absent();
    }
}

From source file:io.crate.analyze.KillAnalyzedStatement.java

public KillAnalyzedStatement() {
    jobId = Optional.absent();
}

From source file:org.eclipse.buildship.core.util.binding.Validators.java

public static Validator<File> optionalDirectoryValidator(final String prefix) {
    return new Validator<File>() {

        @Override/*  w  ww.j ava 2s  .  co m*/
        public Optional<String> validate(File file) {
            if (file == null) {
                return Optional.absent();
            } else if (!file.exists()) {
                return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_DoesNotExist, prefix));
            } else if (!file.isDirectory()) {
                return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_MustBeDirectory, prefix));
            } else {
                return Optional.absent();
            }
        }
    };
}

From source file:retrofit.processor.GwtCompatibility.java

GwtCompatibility(TypeElement type) {
    Optional<AnnotationMirror> gwtCompatibleAnnotation = Optional.absent();
    List<? extends AnnotationMirror> annotations = type.getAnnotationMirrors();
    for (AnnotationMirror annotation : annotations) {
        Name name = annotation.getAnnotationType().asElement().getSimpleName();
        if (name.contentEquals("GwtCompatible")) {
            gwtCompatibleAnnotation = Optional.of(annotation);
        }/*from w  w w.  j  av  a 2 s.  c o  m*/
    }
    this.gwtCompatibleAnnotation = gwtCompatibleAnnotation;
}

From source file:org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy.java

@Override
public Optional<MappedDependency> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }/*from   w  w  w .  ja v a 2s  .  c o  m*/

    String expectedClass = getOpenType().getClassName();
    String realClass = value.getClass().getName();
    Preconditions.checkArgument(realClass.equals(expectedClass),
            "Type mismatch, expected " + expectedClass + " but was " + realClass);
    Util.checkType(value, ObjectName.class);

    ObjectName on = (ObjectName) value;

    String refName = ObjectNameUtil.getReferenceName(on);

    //we want to use the exact service name that was configured in xml so services that are referencing it can be resolved
    return Optional.of(new MappedDependency(namespace,
            QName.create(ObjectNameUtil.getServiceQName(on)).getLocalName(), refName));
}

From source file:io.crate.sql.tree.AllColumns.java

public AllColumns() {
    prefix = Optional.absent();
}