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:flipkart.mongo.replicator.core.model.ReplicaSetConfig.java

public Optional<Node> findNode(String host, int port) {
    for (Node node : nodes) {
        if (node.host.equals(host) && node.port == port) {
            return Optional.of(node);
        }/* ww  w . j a  v a 2  s .  com*/
    }
    return Optional.absent();
}

From source file:org.sosy_lab.cpachecker.core.algorithm.testgen.util.CFAUtils2.java

/**
 * same as {@link #getAlternativeLeavingEdge(CFAEdge)}, but allows specification of the given edge.
 * Its expected that wrongEdge is a leaving edge of node, but its not checked.
 * @param decidingNode/* ww  w. j a  v  a2s .  co  m*/
 * @param wrongEdge
 * @return
 */
public static Optional<CFAEdge> getAlternativeLeavingEdge(CFANode node, CFAEdge wrongEdge) {
    for (CFAEdge cfaEdge : CFAUtils.leavingEdges(node)) {
        if (cfaEdge.equals(wrongEdge)) {
            continue;
        } else {
            return Optional.of(cfaEdge);
        }
    }
    return Optional.absent();
}

From source file:org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.UnionCompositeAttributeMappingStrategy.java

@Override
protected Optional<?> mapInnerAttribute(CompositeDataSupport compositeData, String jmxName,
        String description) {/*from   w  w  w . jav a  2s  . c  o m*/
    if (!description.equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)) {
        return Optional.absent();
    }
    return super.mapInnerAttribute(compositeData, jmxName, description);
}

From source file:org.gradle.api.reporting.model.internal.BasicStringNodeDescriptor.java

@Override
public Optional<String> value(ModelNode modelNode) {
    if (modelNode.getLinkCount() == 0) {
        MutableModelNode modelElementNode = (MutableModelNode) modelNode;
        Object privateData = modelElementNode.getPrivateData();
        return Optional.of(privateData.toString());
    }/* ww w.  j av a2 s  . c  o  m*/
    return Optional.absent();
}

From source file:org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference.java

public PBXFileReference(String name, String path, SourceTree sourceTree) {
    super(name, path, sourceTree);

    // this is necessary to prevent O(n^2) behavior in xcode project loading
    String fileType = FileTypes.FILE_EXTENSION_TO_UTI.get(Files.getFileExtension(name));
    explicitFileType = Optional.fromNullable(fileType);
    lastKnownFileType = Optional.absent();
}

From source file:cc.ilo.cc.ilo.pipeline.producer.IterableProducer.java

@Override
public synchronized Optional<T> getNext() throws InterruptedException {
    if (iterator.hasNext() && !stopped) {
        return Optional.of(iterator.next());
    } else {/*  w  w w .  j  ava 2  s.  c o  m*/
        return Optional.absent();
    }
}

From source file:org.gradle.api.internal.project.RelativeBuildScriptLocationTransformer.java

@Override
public Optional<String> transform(ProjectInternal project) {
    Transformer<String, File> stringFileTransformer = RelativeFileNameTransformer.from(project.getProjectDir());
    File file = project.getBuildScriptSource().getResource().getFile();
    if (null != file) {
        return Optional.of(File.separatorChar + stringFileTransformer.transform(file));
    }/* w w w .java  2 s .  c o  m*/
    return Optional.absent();
}

From source file:org.wisepersist.UserDao.java

@NonTransactional
public Optional<User> findByEmail(String email) {
    TypedQuery<User> query = em().createQuery("SELECT user FROM User user WHERE user.email=:email", User.class);
    query.setParameter("email", email);
    List<User> users = query.getResultList();
    if (users.size() > 0) {
        return Optional.of(users.get(0));
    }//  w  w  w.  j a va  2s  .  c  om
    return Optional.absent();
}

From source file:com.arpnetworking.tsdcore.model.AggregationMessage.java

/**
 * Deserialize message from <code>Buffer</code>.
 *
 * TODO(vkoskela): The header and message need to be versioned [MAI-133].
 *
 * @param data The <code>Buffer</code> containing the serialized message.
 * @return The deserialized <code>AggregationMessage</code> or absent if
 * the <code>Buffer</code> could not be deserialized.
 *///from w w w .j a  v a 2  s  .co  m
public static Optional<AggregationMessage> deserialize(final ByteString data) {
    int position = 0;
    // Make sure we have enough data to get the size
    if (data.length() < HEADER_SIZE_IN_BYTES) {
        return Optional.absent();
    }

    // Deserialize and validate buffer length
    final ByteIterator reader = data.iterator();
    final int length = reader.getInt(ByteOrder.BIG_ENDIAN);
    position += INTEGER_SIZE_IN_BYTES;
    if (data.length() < length) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace(String.format("we only have %d of %d bytes.", data.length(), length));
        }
        return Optional.absent();
    }

    // Deserialize message type
    final byte type = reader.getByte();
    position += BYTE_SIZE_IN_BYTES;

    final byte subType;
    if (typeHasSubtype(type)) {
        subType = reader.getByte();
        position += BYTE_SIZE_IN_BYTES;
    } else {
        subType = 0x00;
    }

    // Obtain the serialized payload
    final byte[] payloadBytes = new byte[length - position];
    reader.getBytes(payloadBytes);

    // Deserialize the message based on the type
    try {
        switch (type) {
        case 0x01:
            return Optional.of(new AggregationMessage(Messages.HostIdentification.parseFrom(payloadBytes)));
        case 0x03:
            return Optional.of(new AggregationMessage(Messages.HeartbeatRecord.parseFrom(payloadBytes)));
        case 0x04:
            return Optional.of(new AggregationMessage(Messages.StatisticSetRecord.parseFrom(payloadBytes)));
        case 0x05:
            // 0x05 is the message type for all supporting data
            switch (subType) {
            case 0x01:
                return Optional
                        .of(new AggregationMessage(Messages.SamplesSupportingData.parseFrom(payloadBytes)));
            case 0x02:
                return Optional.of(
                        new AggregationMessage(Messages.SparseHistogramSupportingData.parseFrom(payloadBytes)));
            default:
                LOGGER.warn(
                        String.format("Invalid protocol buffer, unknown subtype; type=%s, subtype=%s, bytes=%s",
                                type, subType, Hex.encodeHexString(payloadBytes)));
                return Optional.absent();
            }
        default:
            LOGGER.warn(String.format("Unsupported message type; type=%s", type));
            return Optional.absent();
        }
    } catch (final InvalidProtocolBufferException e) {
        LOGGER.warn(String.format("Invalid protocol buffer; type=%s bytes=%s", type,
                Hex.encodeHexString(payloadBytes)), e);
        return Optional.absent();
    }
}

From source file:org.eclipse.buildship.core.workspace.internal.EclipseVmUtil.java

private static Optional<IVMInstall> findRegisteredVM(String version) {
    Optional<IExecutionEnvironment> possibleExecutionEnvironment = findExecutionEnvironment(version);
    if (!possibleExecutionEnvironment.isPresent()) {
        return Optional.absent();
    }//from w  w w . j a va 2s  .c  om

    IExecutionEnvironment executionEnvironment = possibleExecutionEnvironment.get();
    IVMInstall defaultVm = executionEnvironment.getDefaultVM();
    if (defaultVm != null) {
        return Optional.of(defaultVm);
    } else {
        IVMInstall firstVm = Iterables.getFirst(Arrays.asList(executionEnvironment.getCompatibleVMs()), null);
        return Optional.fromNullable(firstVm);
    }
}