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

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

Introduction

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

Prototype

public abstract boolean isPresent();

Source Link

Document

Returns true if this holder contains a (non-null) instance.

Usage

From source file:org.opendaylight.netvirt.openstack.netvirt.NetvirtProvider.java

public static boolean isMasterElected() {
    if (entityOwnershipService != null) {
        Optional<EntityOwnershipState> state = entityOwnershipService.getOwnershipState(ownerInstanceEntity);
        return state.isPresent() && state.get().hasOwner();
    }//  w w w  .ja va 2  s . com
    return false;
}

From source file:org.opendaylight.controller.config.threadpool.util.FlexibleThreadPoolWrapper.java

/**
 * Overriding the queue:/* w ww. j  a  v  a  2s .  c  o m*/
 * ThreadPoolExecutor would not create new threads if the queue is not full, thus adding
 * occurs in RejectedExecutionHandler.
 * This impl saturates threadpool first, then queue. When both are full caller will get blocked.
 */
private static ForwardingBlockingQueue getQueue(Optional<Integer> capacity) {
    final BlockingQueue<Runnable> delegate = capacity.isPresent()
            ? new LinkedBlockingQueue<Runnable>(capacity.get())
            : new LinkedBlockingQueue<Runnable>();
    return new ForwardingBlockingQueue(delegate);
}

From source file:org.sonar.server.computation.measure.BatchMeasureToMeasure.java

private static Optional<Measure> toLevelMeasure(Measure.NewMeasureBuilder builder,
        BatchReport.Measure batchMeasure) {
    if (!batchMeasure.hasStringValue()) {
        return toNoValueMeasure(builder, batchMeasure);
    }/*from   w  w  w .j a v a 2s .c  o  m*/
    Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue());
    if (!level.isPresent()) {
        return toNoValueMeasure(builder, batchMeasure);
    }
    return of(builder.create(level.get()));
}

From source file:org.opennms.newts.rest.Transform.java

private static Map<String, String> unwrapMap(Optional<Map<String, String>> wrapped) {
    if (!wrapped.isPresent())
        return Collections.<String, String>emptyMap();
    return wrapped.get();
}

From source file:com.vmware.photon.controller.apife.utils.PaginationUtils.java

/**
 * Determine the page size to be used.//from   w w w .j a v a 2  s  .  c  om
 *
 * 1. If origPageSize is empty, then the one defined in paginationConfig is to be used.
 * 2. If origPageSize is larger than the maxPageSize defined in paginationConfig, throw exception.
 *
 * @param paginationConfig
 * @param origPageSize
 * @return
 */
public static Optional<Integer> determinePageSize(PaginationConfig paginationConfig,
        Optional<Integer> origPageSize) throws InvalidPageSizeException {

    if (!origPageSize.isPresent()) {
        return Optional.of(paginationConfig.getDefaultPageSize());
    } else if (origPageSize.get() < 1 || origPageSize.get() > paginationConfig.getMaxPageSize()) {
        throw new InvalidPageSizeException(origPageSize.get(), 1, paginationConfig.getMaxPageSize());
    } else {
        return origPageSize;
    }
}

From source file:utils.PasswordManager.java

private static Optional<BasicTextEncryptor> getEncryptor(Optional<String> masterPassword) {
    Optional<BasicTextEncryptor> encryptor;
    if (masterPassword.isPresent()) {
        encryptor = Optional.of(new BasicTextEncryptor());
        try {/* w w  w . j av  a2s.  c o  m*/
            encryptor.get().setPassword(masterPassword.get());
        } catch (Exception e) {
            LOG.error("Failed to set master password for encryptor", e);
            encryptor = Optional.absent();
        }
    } else {
        encryptor = Optional.absent();
    }

    return encryptor;
}

From source file:org.xacml4j.v30.policy.function.AttributeDesignatorFunctions.java

private static AttributeExpType getType(AnyURIExp typeUri) {
    AttributeExpType typeId = (AttributeExpType) typeUri.getEvaluatesTo();
    Optional<AttributeExpType> resolvedType = XacmlTypes.getType(typeUri.getValue().toString());
    if (!resolvedType.isPresent()) {
        throw new XacmlSyntaxException("Unknown XACML type id=\"%s\"", typeId);
    }//  w  w w .  j ava 2  s.c o  m
    return resolvedType.get();
}

From source file:com.google.testing.junit.runner.model.AntXmlResultWriter.java

private static String getFormattedTimestamp(Optional<Interval> runTimeInterval) {
    return !runTimeInterval.isPresent() ? "" : runTimeInterval.get().getStart().toString();
}

From source file:com.google.testing.junit.runner.model.AntXmlResultWriter.java

private static String getFormattedRunTime(Optional<Interval> runTimeInterval) {
    return !runTimeInterval.isPresent() ? "0.0"
            : String.valueOf(runTimeInterval.get().toDurationMillis() / 1000.0D);
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractDataTreeCandidateNode.java

static DataTreeCandidateNode deltaChild(
        final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
        final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData,
        final PathArgument identifier) {

    final Optional<NormalizedNode<?, ?>> maybeNewChild = getChild(newData, identifier);
    final Optional<NormalizedNode<?, ?>> maybeOldChild = getChild(oldData, identifier);
    if (maybeOldChild.isPresent()) {
        final NormalizedNode<?, ?> oldChild = maybeOldChild.get();
        if (maybeNewChild.isPresent()) {
            return AbstractRecursiveCandidateNode.replaceNode(oldChild, maybeNewChild.get());
        }/* ww  w .j  av  a  2  s  .c o m*/
        return AbstractRecursiveCandidateNode.deleteNode(oldChild);
    }

    return maybeNewChild.isPresent() ? AbstractRecursiveCandidateNode.writeNode(maybeNewChild.get()) : null;
}