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:com.facebook.buck.apple.AppleInfoPlistParsing.java

/**
 * Extracts the bundle ID (CFBundleIdentifier) from an Info.plist, returning it if present.
 *///from w ww  . j  a  v a 2  s  . co  m
public static Optional<String> getBundleIdFromPlistStream(InputStream inputStream) throws IOException {
    NSDictionary infoPlist;
    try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
        try {
            infoPlist = (NSDictionary) PropertyListParser.parse(bufferedInputStream);
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    NSObject bundleId = infoPlist.objectForKey("CFBundleIdentifier");
    if (bundleId == null) {
        return Optional.absent();
    } else {
        return Optional.of(bundleId.toString());
    }
}

From source file:com.google.gerrit.server.notedb.rebuild.StatusChangeEvent.java

static Optional<StatusChangeEvent> parseFromMessage(ChangeMessage message, Change change, Change noteDbChange) {
    String msg = message.getMessage();
    if (msg == null) {
        return Optional.absent();
    }//from  w  w w .j  a  v  a2  s .com
    for (Map.Entry<Change.Status, Pattern> e : PATTERNS.entrySet()) {
        if (e.getValue().matcher(msg).matches()) {
            return Optional.of(new StatusChangeEvent(message, change, noteDbChange, e.getKey()));
        }
    }
    return Optional.absent();
}

From source file:org.fabrician.enabler.util.BuildCmdOptions.java

public static Optional<String> build(RuntimeContextVariable var) {
    try {/*from w w  w.  ja v a2 s  .c o  m*/
        BuildCmdOptions val = valueOf(var.getName());
        if (var.getTypeInt() != RuntimeContextVariable.OBJECT_TYPE) {
            String currentValue = StringUtils.trimToEmpty((String) var.getValue());
            // empty value means the option is not valid and would be skipped
            // so that we accept the default
            if (!currentValue.isEmpty()) {
                if (val.isBooleanType) {
                    Boolean b = BooleanUtils.toBooleanObject(currentValue);
                    if (b != val.defaultBooleanValue) {
                        return Optional.of(" " + val.optionSwitch + " ");
                    }
                } else {
                    return Optional.of(" " + val.optionSwitch + " " + currentValue);
                }
            }
        }

    } catch (Exception ex) {

    }
    return Optional.absent();
}

From source file:io.urmia.util.ArgumentParseUtil.java

static Optional<String> getArgument(String[] args, String shortName, String longName) {
    int i = 0;//from   w  w  w.j a v a 2 s .  c o m

    while (i < args.length && args[i].startsWith("-")) {
        String arg = args[i++];

        if (arg.equals(shortName) || arg.equals(longName))
            if (i < args.length)
                return Optional.fromNullable(args[i]);
    }

    return Optional.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  a va  2  s . c  o m
        return Optional.absent();
    }
}

From source file:org.jclouds.aws.filters.FormSignerUtils.java

/**
 * Get the version from a @ApiVersionOverride() annotation on an API method or its owning class.
 * @param request The API request for the method.
 * @return An optional of the value of the annotation.
 *///from  w w  w  . j ava  2s  .c  o m
public static Optional<String> getAnnotatedApiVersion(HttpRequest request) {
    if (request instanceof GeneratedHttpRequest) {
        GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
        return getAnnotatedApiVersion(generatedRequest.getInvocation());
    } else {
        return Optional.absent();
    }
}

From source file:org.eclipse.recommenders.utils.rcp.UUIDHelper.java

private static Optional<String> lookupUUIDFromStore() {
    final RecommendersUtilsPlugin plugin = RecommendersUtilsPlugin.getDefault();
    final IPreferenceStore prefStore = plugin.getPreferenceStore();
    final String uuid = prefStore.getString(PreferencesInitalizer.PROP_UUID);
    if (Strings.isNullOrEmpty(uuid)) {
        return Optional.absent();
    }// w  w  w.  j av  a 2 s  . c  om
    return Optional.fromNullable(uuid);
}

From source file:org.sonar.server.permission.ws.WsProjectRef.java

public static Optional<WsProjectRef> newOptionalWsProjectRef(@Nullable String uuid, @Nullable String key) {
    if (uuid == null && key == null) {
        return Optional.absent();
    }/*from w ww.  ja v  a  2s  . c  om*/

    return Optional.of(new WsProjectRef(uuid, key));
}

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

public static Optional<Integer> getOptionalIntegerArg(CommandLine cmdline, String arg)
        throws IllegalArgumentException {
    try {//from www  . ja v a  2  s.  c  om
        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:im.dadoo.cas.server.service.SignService.java

public Optional<User> signin(String name, String password) {
    Optional<User> user = this.userDao.findByName(name);
    if (user.isPresent() && user.get().getPassword().equals(password)) {
        return user;
    } else {//from   w ww.  ja  va2s. c o  m
        return Optional.absent();
    }
}