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

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

Introduction

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

Prototype

@Nullable
public abstract T orNull();

Source Link

Document

Returns the contained instance if it is present; null otherwise.

Usage

From source file:org.sosy_lab.cpachecker.util.LiveVariables.java

public static Optional<LiveVariables> create(final Optional<VariableClassification> variableClassification,
        final List<Pair<ADeclaration, String>> globalsList, final MutableCFA pCFA, final LogManager logger,
        final ShutdownNotifier shutdownNotifier, final Configuration config)
        throws InvalidConfigurationException {
    checkNotNull(variableClassification);
    checkNotNull(globalsList);/*from   w  ww . j  av a  2 s  .  co m*/
    checkNotNull(pCFA);
    checkNotNull(logger);
    checkNotNull(shutdownNotifier);

    // we cannot make any assumptions about c programs where we do not know
    // about the addressed variables
    if (pCFA.getLanguage() == Language.C && !variableClassification.isPresent()) {
        return Optional.absent();
    }

    // we need a cfa with variableClassification, thus we create one now
    CFA cfa = pCFA.makeImmutableCFA(variableClassification);

    // create configuration object, so that we know which analysis strategy should
    // be chosen later on
    LiveVariablesConfiguration liveVarConfig = new LiveVariablesConfiguration(config);

    return create0(variableClassification.orNull(), globalsList, logger, shutdownNotifier, cfa,
            liveVarConfig.evaluationStrategy);
}

From source file:org.jclouds.googlecompute.functions.internal.BaseToPagedIterable.java

@Override
public PagedIterable<T> apply(ListPage<T> input) {
    if (input.nextMarker() == null)
        return PagedIterables.of(input);

    Optional<Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));

    Optional<Object> listOptions = tryFind(request.getInvocation().getArgs(), instanceOf(ListOptions.class));

    assert project.isPresent() : String.format(
            "programming error, method %s should have a string param for the " + "project",
            request.getCaller().get().getInvokable());

    return PagedIterables.advance(input,
            fetchNextPage(project.get().toString(), (ListOptions) listOptions.orNull()));
}

From source file:pt.ist.maidSyncher.domain.dsi.DSIMilestone.java

public GHMilestone getGhMilestone(final GHRepository ghRepository) {
    Optional<GHMilestone> optionalMilestone = Iterables.tryFind(getGhMilestonesSet(),
            new Predicate<GHMilestone>() {
                @Override/*from   w  w  w  .  j  a v  a 2  s  . co  m*/
                public boolean apply(GHMilestone input) {
                    if (input == null)
                        return false;
                    return ObjectUtils.equals(input.getRepository(), ghRepository);
                }
            });
    return optionalMilestone.orNull();
}

From source file:com.on_site.frizzle.debug.LoggingMixin.java

public Object get(String name, Scriptable start) {
    Optional<Object> value = null;
    try {//w  w w  . jav  a  2 s .c om
        value = Optional.fromNullable(delegate.get(name, start));
        return instrument(Object.class, "." + name, value);
    } finally {
        if (value == null) {
            log("{1}.{0} => abrupt", name, start);
        } else {
            if (!(value.orNull() instanceof Function)) {
                log("{1}.{0} => {2}", name, start, value.orNull());
            }
        }
    }
}

From source file:com.google.devtools.build.android.xml.PublicXmlResourceValue.java

@Override
public XmlResourceValue combineWith(XmlResourceValue value) {
    if (!(value instanceof PublicXmlResourceValue)) {
        throw new IllegalArgumentException(value + "is not combinable with " + this);
    }//from w w w . j a v a2s  .  com
    PublicXmlResourceValue other = (PublicXmlResourceValue) value;
    Map<ResourceType, Optional<Integer>> combined = new EnumMap<>(ResourceType.class);
    combined.putAll(typeToId);
    for (Entry<ResourceType, Optional<Integer>> entry : other.typeToId.entrySet()) {
        Optional<Integer> existing = combined.get(entry.getKey());
        if (existing != null && !existing.equals(entry.getValue())) {
            throw new IllegalArgumentException(
                    String.format("Public resource of type %s assigned two different id values 0x%x and 0x%x",
                            entry.getKey(), existing.orNull(), entry.getValue().orNull()));
        }
        combined.put(entry.getKey(), entry.getValue());
    }
    return of(combined);
}

From source file:org.eclipse.buildship.ui.launch.ProjectSettingsTab.java

@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
    GradleDistributionWrapper gradleDistribution = this.gradleProjectSettingsComposite
            .getGradleDistributionGroup().getGradleDistribution();
    Optional<String> error = this.gradleDistributionValidator.validate(gradleDistribution);
    if (!error.isPresent()) {
        error = this.gradleUserHomeValidator
                .validate(this.gradleProjectSettingsComposite.getGradleUserHomeGroup().getGradleUserHome());
    }/*from   ww  w  .  j  av a 2  s  .co  m*/
    setErrorMessage(error.orNull());
    return !error.isPresent();
}

From source file:org.geogit.api.porcelain.RemoteListOp.java

/**
 * Executes the remote-list operation./*from  www .j a  v  a2s  . c o m*/
 * 
 * @return {@code List<Remote>} of all remotes found in the config database, may be empty.
 */
@Override
public ImmutableList<Remote> call() {
    List<String> remotes = config.getAllSubsections("remote");
    List<Remote> allRemotes = new ArrayList<Remote>();
    for (String remoteName : remotes) {
        String remoteSection = "remote." + remoteName;
        Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
        Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
        Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
        Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
        if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
            Optional<String> remotePushURL = config.get(remoteSection + ".pushurl");
            allRemotes.add(new Remote(remoteName, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()),
                    remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull()));
        }

    }
    return ImmutableList.copyOf(allRemotes);
}

From source file:com.on_site.frizzle.debug.LoggingMixin.java

public Object get(int index, Scriptable start) {
    Optional<Object> value = null;
    try {/*w ww .  j a v  a  2  s.  c  o  m*/
        value = Optional.fromNullable(delegate.get(index, start));
        return instrument(Object.class, "[" + index + "]", value);
    } finally {
        if (value == null) {
            log("{1}[{0}] => abrupt", index, start);
        } else {
            if (!(value.orNull() instanceof Function)) {
                log("{1}[{0}] => {2}", index, start, value.orNull());
            }
        }
    }
}

From source file:org.locationtech.geogig.storage.fs.FileRefDatabase.java

@Override
public String toString() {
    Optional<URL> envHome = new ResolveGeogigDir(platform).call();
    return String.format("%s[geogig dir: %s]", getClass().getSimpleName(), envHome.orNull());
}

From source file:org.geogit.api.porcelain.RemoteRemoveOp.java

/**
 * Executes the remote-remove operation.
 * //from  w  w  w .jav a2 s  .  co  m
 * @return the {@link Remote} that was removed, or {@link Optional#absent()} if the remote
 *         didn't exist.
 */
@Override
public Remote call() {
    if (name == null || name.isEmpty()) {
        throw new RemoteException(StatusCode.MISSING_NAME);
    }
    List<String> allRemotes = config.getAllSubsections("remote");
    if (!allRemotes.contains(name)) {
        throw new RemoteException(StatusCode.REMOTE_NOT_FOUND);
    }

    Remote remote = null;
    String remoteSection = "remote." + name;
    Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
    Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
    Optional<String> remotePushURL = Optional.absent();
    Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
    Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
    if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
        remotePushURL = config.get(remoteSection + ".pushurl");
    }

    remote = new Remote(name, remoteFetchURL.or(""), remotePushURL.or(remoteFetchURL.or("")),
            remoteFetch.or(""), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull());

    config.removeSection(remoteSection);

    // Remove refs
    final ImmutableSet<Ref> localRemoteRefs = command(LsRemote.class).retrieveLocalRefs(true)
            .setRemote(Suppliers.ofInstance(Optional.of(remote))).call();

    for (Ref localRef : localRemoteRefs) {
        command(UpdateRef.class).setDelete(true).setName(localRef.getName()).call();
    }

    return remote;
}