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.eclipse.buildship.core.util.file.FileUtils.java

/**
 * Derives a {@code File} instance with absolute path from the specified {@code File} instance.
 *
 * @param file the relative or absolute file of the {@code File} instance to derive
 * @return the absolute {@code File} if the file is not {@code null}, otherwise
 * {@link Optional#absent()}// w  ww.jav a 2  s.c  o m
 */
public static Optional<File> getAbsoluteFile(File file) {
    if (file == null) {
        return Optional.absent();
    } else {
        return Optional.of(file.isAbsolute() ? file : file.getAbsoluteFile());
    }
}

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;/*from www .  j  a  v  a  2s . com*/
        next = getOriginalIfPossible(next.get());
    }
    return previous.orNull();
}

From source file:gobblin.runtime.task.TaskUtils.java

/**
 * Parse the {@link TaskFactory} in the state if one is defined.
 *//*from w  ww.ja  va2s  . co  m*/
public static Optional<TaskFactory> getTaskFactory(State state) {
    try {
        if (state.contains(TASK_FACTORY_CLASS)) {
            return Optional.of((TaskFactory) Class.forName(state.getProp(TASK_FACTORY_CLASS)).newInstance());
        } else {
            return Optional.absent();
        }
    } catch (ReflectiveOperationException roe) {
        throw new RuntimeException("Could not create task factory.", roe);
    }
}

From source file:springfox.documentation.spring.web.readers.operation.ModelRefs.java

public static Optional<ModelRef> modelRef(Optional<ResolvedType> type, ModelContext modelContext,
        TypeNameExtractor nameExtractor) {
    if (!type.isPresent()) {
        return Optional.absent();
    }//from  ww  w  . j  av  a  2  s.co m
    return Optional.of(modelRef(type.get(), modelContext, nameExtractor));
}

From source file:org.apache.distributedlog.util.CommandLineUtils.java

public static Optional<Boolean> getOptionalBooleanArg(CommandLine cmdline, String arg) {
    if (cmdline.hasOption(arg)) {
        return Optional.of(true);
    } else {// w w  w. ja v  a  2s . com
        return Optional.absent();
    }
}

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 www  .  j ava2 s.com
        next = getOriginalIfPossible(next.get());
    }
    return previous.orNull();
}

From source file:com.afterkraft.kraftrpg.api.util.DataUtil.java

public static Optional<DataContainer> containerFromExisting(DataView data) {
    return Optional.absent();
}

From source file:org.cg.ftc.ftcClientCodeCompletionExperiments.TreeNamePicker.java

public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Optional<String> prefix = Optional.absent();
            show(getDemoTree(), prefix, new ItemChosenHandler() {

                @Override//from   w  ww  .  j  a va  2 s.c  om
                public void onItemChosen(AbstractCompletion item) {
                    String itemText = item == null ? "<no item>" : item.displayName;
                    String parentText = item != null && item.parent != null ? item.parent.displayName
                            : "<no parent>";
                    System.out.println(String.format("%s - %s", parentText, itemText));

                }

            });
        }
    });
}

From source file:ezbake.frack.submitter.util.ClasspathUtil.java

public static Optional<String> findClassInJar(final File jarFile)
        throws MalformedURLException, ClassNotFoundException {
    log.debug("Looking for class in jar {}", jarFile.getAbsolutePath());
    Optional<String> className = Optional.absent();
    // Get the builder class, have to use a separate classloader
    URLClassLoader contextLoader = new URLClassLoader(new URL[] { jarFile.toURI().toURL() },
            Thread.currentThread().getContextClassLoader());
    final String[] builderClass = new String[] { null };
    Thread finderThread = new Thread(new Runnable() {
        @Override//from   www. j  av a  2s.  c  o m
        public void run() {
            try {
                URL url = jarFile.toURI().toURL();
                URLClassLoader loader = new URLClassLoader(new URL[] { url });
                final Class pipelineBuilder = Thread.currentThread().getContextClassLoader()
                        .loadClass("ezbake.frack.api.PipelineBuilder");

                ConfigurationBuilder builder = new ConfigurationBuilder();
                builder.setUrls(jarFile.toURI().toURL());
                builder.addClassLoader(loader);
                Reflections reflections = new Reflections(builder);
                Set<Class<?>> types = reflections.getSubTypesOf(pipelineBuilder);
                if (types.size() > 0) {
                    Class<?> type = Iterables.getFirst(types, null);
                    if (type != null) {
                        builderClass[0] = type.getCanonicalName();
                    }
                }
            } catch (MalformedURLException e) {
                log.error("Could not access jar file", e);
            } catch (ClassNotFoundException e) {
                log.error(
                        "Could not find builder class in provided jar file, ensure that the pipeline project is dependent on 'frack'");
            }
        }
    });
    finderThread.setContextClassLoader(contextLoader);
    finderThread.start();
    try {
        finderThread.join();
        if (builderClass[0] != null) {
            className = Optional.of(builderClass[0]);
        }
    } catch (InterruptedException e) {
        log.error(String.format("Thread interrupted while attempting to find PipelineBuilder class in %s",
                jarFile.getName()), e);
    }

    return className;
}

From source file:org.dswarm.graph.rdf.nx.utils.NodeTypeUtils.java

public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode,
        final Optional<Boolean> optionalIsType) {

    if (!optionalNode.isPresent()) {

        return Optional.absent();
    }//from w  ww.ja v a  2  s.c  om

    final NodeType nodeType;
    final Node node = optionalNode.get();

    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 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 {

        nodeType = null;
    }

    return Optional.fromNullable(nodeType);
}