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:org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.CompositeAttributeMappingStrategy.java

@Override
public Optional<Map<String, Object>> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }/*w w w.  j a  v a 2s.  c om*/

    Util.checkType(value, CompositeDataSupport.class);

    CompositeDataSupport compositeData = (CompositeDataSupport) value;
    CompositeType currentType = compositeData.getCompositeType();
    CompositeType expectedType = getOpenType();

    Set<String> expectedCompositeTypeKeys = expectedType.keySet();
    Set<String> currentCompositeTypeKeys = currentType.keySet();
    Preconditions.checkArgument(expectedCompositeTypeKeys.equals(currentCompositeTypeKeys),
            "Composite type mismatch, expected composite type with attributes " + expectedCompositeTypeKeys
                    + " but was " + currentCompositeTypeKeys);

    Map<String, Object> retVal = Maps.newHashMap();

    for (String jmxName : jmxToJavaNameMapping.keySet()) {
        Optional<?> mapped = mapInnerAttribute(compositeData, jmxName, expectedType.getDescription(jmxName));
        if (mapped.isPresent()) {
            retVal.put(jmxToJavaNameMapping.get(jmxName), mapped.get());
        }
    }

    return Optional.of(retVal);
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.resolving.EnumAttributeResolvingStrategy.java

@Override
public Optional<Object> parseAttribute(String attrName, Object value) throws NetconfDocumentedException {
    if (value == null) {
        return Optional.absent();
    }/*from  ww  w . j  av  a 2s.c o  m*/

    Util.checkType(value, Map.class);
    Map<?, ?> valueMap = (Map<?, ?>) value;
    Preconditions.checkArgument(valueMap.size() == 1,
            "Unexpected value size " + value + " should be just 1 foe enum");
    final Object innerValue = valueMap.values().iterator().next();
    Util.checkType(innerValue, String.class);

    final String className = getOpenType().getTypeName();
    final Object parsedValue = enumResolver.fromYang(className, ((String) innerValue));

    LOG.debug("Attribute {} : {} parsed to enum type {} with value {}", attrName, innerValue, getOpenType(),
            parsedValue);
    return Optional.of(parsedValue);
}

From source file:com.eucalyptus.auth.AccessKeys.java

/**
 * Get the type for an access key.//w  w  w  .  ja va2 s  . com
 *
 * @param key The key to get the type of
 * @return The optional key type
 */
@Nonnull
public static Optional<TemporaryKeyType> getKeyType(@Nonnull final AccessKey key) {
    Optional<TemporaryKeyType> type = Optional.absent();
    if (key instanceof TemporaryAccessKey) {
        type = Optional.of(((TemporaryAccessKey) key).getType());
    }
    return type;
}

From source file:org.whispersystems.websocket.session.WebSocketSessionContext.java

public <T> Optional<T> getAuthenticated(Class<T> clazz) {
    if (clazz.isInstance(authenticated)) {
        return Optional.fromNullable(clazz.cast(authenticated));
    }/*  w  w  w . ja  va  2s. c  o  m*/

    return Optional.absent();
}

From source file:com.infobip.jira.IssueKey.java

/**
 * Generates {@link IssueKey} from {@link Commit changesets} message.
 *
 * @param changeset containing message with Jira issue key
 *
 * @return first {@link IssueKey} that could be extracted, else {@link Optional#absent()}
 *//*from   w w w  .  j a va 2  s.  c om*/
public static Optional<IssueKey> from(Commit changeset) {

    Matcher matcher = pattern.matcher(changeset.getMessage());

    if (!matcher.find()) {
        return Optional.absent();
    }

    return Optional.of(new IssueKey(new ProjectKey(matcher.group(1)), new IssueId(matcher.group(2))));
}

From source file:hihex.cs.updates.UpdateReadyReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (!sLastDownloadId.isPresent()) {
        return;// w  ww  .ja va  2 s .  co m
    }
    final long expectedDownloadId = sLastDownloadId.get();
    final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, expectedDownloadId - 1);

    if (downloadId != expectedDownloadId) {
        return;
    }

    sLastDownloadId = Optional.absent();

    final DownloadManager downloadManager = (DownloadManager) context
            .getSystemService(Context.DOWNLOAD_SERVICE);
    final DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(downloadId);
    final Cursor cursor = downloadManager.query(query);
    if (!cursor.moveToFirst()) {
        return;
    }

    final int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
    if (cursor.getInt(statusIndex) != DownloadManager.STATUS_SUCCESSFUL) {
        return;
    }

    final int localFilenameIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME);
    final String localFilename = cursor.getString(localFilenameIndex);

    final Intent installIntent = new Intent(Intent.ACTION_VIEW);
    installIntent.setDataAndType(Uri.fromFile(new File(localFilename)),
            "application/vnd.android.package-archive");
    installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(installIntent);
}

From source file:org.apache.usergrid.corepersistence.pipeline.read.CursorSeek.java

/**
 * Get the seek value to use when searching
 * @return//from w  w  w.j a v  a 2s .  co m
 */
public Optional<C> getSeekValue() {
    final Optional<C> toReturn = seek;

    seek = Optional.absent();

    return toReturn;
}

From source file:io.macgyver.ssh.PubKeyCredentials.java

private Optional<File> locateKeyFile(String username) {
    String home = System.getProperty("user.home", ".");
    File f = new File(home, ".ssh/id_rsa");
    if (f.exists()) {
        return Optional.of(f);
    }/*w w w . j  av a  2  s  .  c  om*/

    f = new File(home, ".ssh/id_dsa");
    if (f.exists()) {
        return Optional.of(f);
    }

    return Optional.absent();
}

From source file:org.whispersystems.websocket.messages.protobuf.ProtobufWebSocketResponseMessage.java

@Override
public Optional<byte[]> getBody() {
    if (message.hasBody()) {
        return Optional.of(message.getBody().toByteArray());
    } else {//from  ww  w . j  ava 2 s.co  m
        return Optional.absent();
    }
}

From source file:com.github.tomakehurst.wiremock.http.ContentTypeHeader.java

public Optional<String> encodingPart() {
    for (int i = 1; i < parts.length; i++) {
        if (parts[i].matches("\\s*charset\\s*=.*")) {
            return Optional.of(parts[i].split("=")[1].replace("\"", ""));
        }/*w ww .  j ava2s  . c  om*/
    }

    return Optional.absent();
}