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:com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck.java

/**
 * Checks whether a method is annotated with Override annotation.
 * @param ast method parameter definition token.
 * @return true if a method is annotated with Override annotation.
 *///w  ww .java 2 s  . c  o  m
private static boolean isOverriddenMethod(DetailAST ast) {
    boolean overridden = false;

    final DetailAST parent = ast.getParent().getParent();
    final Optional<DetailAST> annotation = Optional.fromNullable(parent.getFirstChild().getFirstChild());

    if (annotation.isPresent() && annotation.get().getType() == TokenTypes.ANNOTATION) {
        final Optional<DetailAST> overrideToken = Optional
                .fromNullable(annotation.get().findFirstToken(TokenTypes.IDENT));
        if (overrideToken.isPresent() && "Override".equals(overrideToken.get().getText())) {
            overridden = true;
        }
    }
    return overridden;
}

From source file:springfox.documentation.schema.Enums.java

static List<String> getEnumValues(final Class<?> subject) {
    return transformUnique(subject.getEnumConstants(), new Function<Object, String>() {
        @Override//from www . j a va  2s.  co  m
        public String apply(Object input) {
            Optional<String> jsonValue = findJsonValueAnnotatedMethod(input)
                    .transform(evaluateJsonValue(input));
            if (jsonValue.isPresent() && !isNullOrEmpty(jsonValue.get())) {
                return jsonValue.get();
            }
            return input.toString();
        }
    });
}

From source file:ec.nbdemetra.ui.demo.impl.TsAbleHandler.java

private static void enableTickFeedback(JButton button) {
    Optional<FakeTsProvider> p = TsProviders.lookup(FakeTsProvider.class, "Fake");
    if (p.isPresent()) {
        Icon icon1 = getIcon(FontAwesome.FA_DATABASE);
        Icon icon2 = FontAwesome.FA_DATABASE.getIcon(Color.ORANGE.darker(),
                FontAwesomeUtils.toSize(ICON_COLOR_16x16));
        p.get().addTickListener(() -> {
            SwingUtilities.invokeLater(() -> {
                if (icon1.equals(button.getClientProperty("stuff"))) {
                    button.putClientProperty("stuff", icon2);
                    button.setIcon(icon2);
                } else {
                    button.putClientProperty("stuff", icon1);
                    button.setIcon(icon1);
                }//from  www.j av a2 s  .  c  o m
            });
        });
    }
}

From source file:org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode.java

public static Optional<UnsignedLong> getVersion(final Optional<StoreMetadataNode> currentMetadata) {
    if (currentMetadata.isPresent()) {
        return Optional.of(currentMetadata.get().getNodeVersion());
    }//  w ww.  j  av  a 2s  . c  o m
    return Optional.absent();
}

From source file:com.replaymod.replaystudio.pathing.serialize.LegacyTimelineConverter.java

private static KeyframeSet[] readAndParse(ReplayFile replayFile) throws IOException {
    Optional<InputStream> optIn = read(replayFile);
    if (!optIn.isPresent()) {
        return null;
    }/*from   w w w.ja v  a2s .c  o m*/
    KeyframeSet[] keyframeSets;
    try (InputStream in = optIn.get()) {
        keyframeSets = parse(in);
    }
    return keyframeSets;
}

From source file:org.inferred.internal.source.ModelUtils.java

/** Returns the {@link TypeElement} corresponding to {@code type}, if there is one. */
public static Optional<TypeElement> maybeAsTypeElement(TypeMirror type) {
    Optional<DeclaredType> declaredType = maybeDeclared(type);
    if (declaredType.isPresent()) {
        return maybeType(declaredType.get().asElement());
    } else {/*  w w  w.  ja  va  2 s.  co  m*/
        return Optional.absent();
    }
}

From source file:org.locationtech.geogig.test.integration.remoting.RemotesIndexTestSupport.java

private static Set<IndexTreeMapping> getIndexMappings(IndexInfo indexInfo, Repository repo,
        Optional<String> ref) {

    if (!ref.isPresent()) {
        return Sets.newHashSet(repo.indexDatabase().resolveIndexedTrees(indexInfo));
    }// w w  w  .  j  a  va 2 s  .  c o m

    Set<IndexTreeMapping> mappings = new HashSet<>();
    List<Ref> branches = getBranches(repo, ref);
    for (Ref branch : branches) {
        List<RevCommit> commits = Lists.newArrayList(repo.command(LogOp.class).addPath(indexInfo.getTreeName())
                .setUntil(branch.getObjectId()).call());
        for (RevCommit c : commits) {
            String treeRef = String.format("%s:%s", c.getId(), indexInfo.getTreeName());
            ObjectId canonicalTreeId = repo.command(RevParse.class).setRefSpec(treeRef).call().get();
            Optional<ObjectId> indexedTree = repo.indexDatabase().resolveIndexedTree(indexInfo,
                    canonicalTreeId);
            String msg = String.format("Expected index at %s:%s", branch.getName(), indexInfo.getTreeName());
            assertTrue(msg, indexedTree.isPresent());
            mappings.add(new IndexTreeMapping(canonicalTreeId, indexedTree.get()));
        }
    }
    return mappings;
}

From source file:org.eclipse.che.ide.ext.java.client.util.JavaUtil.java

public static String resolveFQN(Resource resource) {
    final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);

    if (!srcFolder.isPresent()) {
        throw new IllegalStateException(
                "Fully qualified name can not be resolved for '" + resource.getLocation() + "'");
    }/*from  w  w  w  .  j a v  a 2 s  .co  m*/

    return resolveFQN((Container) srcFolder.get(), resource);
}

From source file:li.klass.fhem.adapter.devices.core.generic.detail.actions.devices.CulHmDetailActionProvider.java

private static boolean supportsHeating(XmlListDevice xmlListDevice) {
    Optional<String> controlMode = xmlListDevice.getState(MODE_STATE_NAME);
    return controlMode.isPresent() && heatingModeFor(controlMode.get()).isPresent();
}

From source file:net.es.nsi.pce.pf.PfUtils.java

private static String getStringValue(String attributeName, AttrConstraints constraints) {
    Optional<String> value = getValue(constraints.getStringAttrConstraint(attributeName));

    if (value.isPresent()) {
        return value.get();
    }/*  w  ww.j  a  v a  2s  . com*/

    throw Exceptions.missingParameter(Point2PointTypes.P2PS, attributeName, null);
}