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:org.onos.yangtools.yang.data.api.schema.tree.spi.LazyContainerNode.java

@Override
public Optional<TreeNode> getChild(final PathArgument key) {
    // We do not cache the instantiated node as it is dirt cheap
    final Optional<NormalizedNode<?, ?>> child = castData().getChild(key);
    if (child.isPresent()) {
        return Optional.of(TreeNodeFactory.createTreeNode(child.get(), getVersion()));
    }//from   www  . j a v a2  s  .c  o m

    return Optional.absent();
}

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

@Override
public Optional<MappedDependency> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }/*ww w. j  av a2  s .com*/

    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);

    return Optional.of(new MappedDependency(namespace, serviceName, refName));
}

From source file:net.diogobohm.timed.impl.codec.TaskCodecImpl.java

@Override
public Task decode(DBTask task, Activity activity, Project project, Set<Tag> tags) {
    Date start = null;//  w  w  w. ja v a2s  .  c  o m
    Optional<Date> end = Optional.absent();
    String description = task.getDescription();

    try {
        start = DATETIME_FORMATTER.parse(task.getStartDateTime());
        if (task.getFinishDateTime() != null) {
            end = Optional.of(DATETIME_FORMATTER.parse(task.getFinishDateTime()));
        }
    } catch (ParseException ex) {
        ex.printStackTrace();
    }

    return new Task(activity, project, start, end, description, tags);
}

From source file:serposcope.helpers.CookieEncryptionOverride.java

public void update(NinjaProperties properties) throws IllegalArgumentException, IllegalAccessException {
    Optional<SecretKeySpec> secretKeySpec = Optional.absent();

    if (properties.getBooleanWithDefault(NinjaConstant.applicationCookieEncrypted, false)) {

        String secret = properties.getOrDie(NinjaConstant.applicationSecret);
        try {/*w  w  w  .  ja  v  a  2  s.  co m*/
            int maxKeyLengthBits = Cipher.getMaxAllowedKeyLength(ALGORITHM);
            if (maxKeyLengthBits == Integer.MAX_VALUE) {
                maxKeyLengthBits = 256;
            }

            secretKeySpec = Optional
                    .of(new SecretKeySpec(secret.getBytes(), 0, maxKeyLengthBits / Byte.SIZE, ALGORITHM));

            LOG.info("Ninja session encryption is using {} / {} bit.", secretKeySpec.get().getAlgorithm(),
                    maxKeyLengthBits);

        } catch (Exception exception) {
            LOG.error("Can not create class to encrypt cookie.", exception);
            throw new RuntimeException(exception);
        }

    } else {
        secretKeySpec = Optional.absent();
    }

    setSecretKeySpec(secretKeySpec);
}

From source file:org.eclipse.emf.eson.generators.GeneratorHelper.java

/**
 * Find the first occurrence of content of a certain type.
 * // w  w  w .ja va 2  s . c  o  m
 * This helper intentionally, for optional performance, does NOT traverse the entire Resource, but only the first level.
 * 
 * @param resource EMF Resource
 * @param klass Java class to find in first level of getContents() of Resource
 * @return Guava optional
 */
public <T extends EObject> Optional<T> getFirstRootContentOfType(Resource resource, Class<T> klass) {
    if (!resource.isLoaded())
        return Optional.absent();

    EList<EObject> contents = resource.getContents();
    for (EObject eObject : contents) {
        if (klass.isInstance(eObject)) {
            return Optional.of(klass.cast(eObject));
        }
    }
    return Optional.absent();
}

From source file:com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits.java

@Override
public Optional<Integer> getPolyhedronVertexLimit() {
    return Optional.absent();
}

From source file:org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl.java

public GenericAttributeDiffImpl(@Nullable Optional<?> oldValue, @Nullable Optional<?> newValue) {
    if (oldValue == null) {
        this.oldValue = Optional.absent();
    } else {//from ww  w .  j a  v  a 2 s  .  co  m
        this.oldValue = oldValue;
    }

    if (newValue == null) {
        this.newValue = Optional.absent();
    } else {
        this.newValue = newValue;
    }
}

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

@Override
public Optional<? extends Inline> createInline(Cursor cursor) {
    char c = cursor.getChar();
    if (c == '&') {
        Matcher matcher = cursor.matcher(pattern);
        if (matcher.matches()) {
            String ent = matcher.group(1);
            return Optional
                    .of(new HtmlEntity(cursor.getLineAtOffset(), cursor.getOffset(), ent.length() + 2, ent));
        }//ww  w .  ja  v a 2s .  co  m
    }
    return Optional.absent();
}

From source file:gobblin.data.management.copy.replication.CopyRouteGeneratorOptimizer.java

@Override
public Optional<CopyRoute> getPullRoute(ReplicationConfiguration rc, EndPoint copyTo) {
    if (rc.getCopyMode() == ReplicationCopyMode.PUSH)
        return Optional.absent();

    DataFlowTopology topology = rc.getDataFlowToplogy();
    List<DataFlowTopology.DataFlowPath> paths = topology.getDataFlowPaths();

    for (DataFlowTopology.DataFlowPath p : paths) {
        List<CopyRoute> routes = p.getCopyRoutes();
        if (routes.isEmpty()) {
            continue;
        }/*from w ww .  j  a va 2  s .  co  m*/

        if (routes.get(0).getCopyTo().equals(copyTo)) {
            return getOptimizedCopyRoute(routes);
        }
    }

    return Optional.absent();
}

From source file:com.github.kevints.mesos.scheduler.server.LibprocessServletUtils.java

static Optional<PID> getSenderPid(HttpServletRequest req) {
    Optional<String> libprocessFrom = Optional.fromNullable(req.getHeader("X-Libprocess-From"));
    if (libprocessFrom.isPresent()) {
        try {//from   w  ww  .  j a  va  2s  . co m
            return Optional.of(PID.fromString(libprocessFrom.get()));
        } catch (IllegalArgumentException e) {
            return Optional.absent();
        }
    }

    Optional<String> userAgent = Optional.fromNullable(req.getHeader("User-Agent"));
    if (userAgent.isPresent()) {
        List<String> pid = Splitter.on("libprocess/").omitEmptyStrings().splitToList(userAgent.get());
        if (pid.size() != 1) {
            return Optional.absent();
        } else {
            try {
                return Optional.of(PID.fromString(pid.get(0)));
            } catch (IllegalArgumentException e) {
                return Optional.absent();
            }
        }
    }

    return Optional.absent();
}