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

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

Introduction

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

Prototype

public static <T> Optional<T> of(T reference) 

Source Link

Document

Returns an Optional instance containing the given non-null reference.

Usage

From source file:com.dasasian.chok.util.NodeConfigurationLoader.java

public static NodeConfiguration loadConfiguration(int overrideStartPort) throws ClassNotFoundException {
    return loadConfiguration(Optional.of(overrideStartPort), Optional.<File>absent(),
            Optional.<Integer>absent(), Optional.<Class<? extends IMonitor>>absent(),
            Optional.<Integer>absent());
}

From source file:ru.org.linux.tracker.TrackerFilterEnum.java

public static Optional<TrackerFilterEnum> getByValue(String filterAction) {
    if (valuesSet.contains(filterAction)) {
        return Optional.of(TrackerFilterEnum.valueOf(filterAction.toUpperCase()));
    } else {//w w  w. j ava  2  s . c o  m
        return Optional.absent();
    }
}

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

public static Optional<Integer> getOptionalIntegerArg(CommandLine cmdline, String arg)
        throws IllegalArgumentException {
    try {//from ww w  . j  ava  2  s.co  m
        if (cmdline.hasOption(arg)) {
            return Optional.of(Integer.parseInt(cmdline.getOptionValue(arg)));
        } else {
            return Optional.absent();
        }
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException(arg + " is not a number");
    }
}

From source file:org.onos.yangtools.yang.data.impl.codec.StringStringCodec.java

protected StringStringCodec(final StringTypeDefinition typeDef) {
    super(Optional.of(typeDef), String.class);
    typeDef.getLengthConstraints();
}

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

@Override
public Optional<? extends Inline> createInline(Cursor cursor) {
    return Optional.of(new Characters(cursor.getLineAtOffset(), cursor.getOffset(), 1,
            Character.toString(cursor.getChar())));
}

From source file:harp.util.FileUtil.java

/**
 * Find a file with the given base name, searching upward from the given starting directory.
 *
 * @param filename the base filename to look for
 * @param startingPath the starting directory to search upward from
 *
 * @return an {@code Optional} containing the Path of the file if found, or an empty Optional
 *     otherwise/*from www .j av a 2  s  . c  o  m*/
 */
public static Optional<Path> findUpward(String filename, Path startingPath) {
    Preconditions.checkNotNull(filename);
    Preconditions.checkArgument(!filename.contains(File.separator));
    Preconditions.checkArgument(Files.isDirectory(startingPath));
    Path possibleRootDir = startingPath;
    while (possibleRootDir != null) {
        Path possiblePath = possibleRootDir.resolve(filename);
        if (Files.isRegularFile(possiblePath)) {
            return Optional.of(possiblePath);
        } else {
            possibleRootDir = possibleRootDir.getParent();
        }
    }
    return Optional.absent();
}

From source file:com.google.javascript.jscomp.JsCheckerHelper.java

static Optional<String> convertPathToModuleName(String path, Iterable<String> roots) {
    checkArgument(!path.startsWith("/"));
    if (!path.endsWith(".js") && !path.endsWith(".zip")) {
        return Optional.absent();
    }/*from   w  w w .j  a  v a 2 s.c o m*/
    String module = path;
    for (String root : roots) {
        if (module.startsWith(root + "/")) {
            module = module.substring(root.length() + 1);
            break;
        }
    }

    String moduleOrZipName = module.split("!")[0];
    return Optional.of("/" + moduleOrZipName);
}

From source file:org.locationtech.geogig.di.PluginDefaults.java

public PluginDefaults(VersionedFormat objects, VersionedFormat refs, VersionedFormat graph) {
    this.refs = Optional.of(refs);
    this.objects = Optional.of(objects);
    this.graph = Optional.of(graph);
}

From source file:edu.ksu.cis.santos.mdcf.dml.ast.exp.Exp.java

Exp(final Type type) {
    this.type = Optional.of(type);
}

From source file:org.apache.james.transport.mailets.remoteDelivery.ExecutionResult.java

public static ExecutionResult temporaryFailure(Exception e) {
    return new ExecutionResult(ExecutionState.TEMPORARY_FAILURE, Optional.of(e));
}