Example usage for com.google.common.collect Iterables getFirst

List of usage examples for com.google.common.collect Iterables getFirst

Introduction

In this page you can find the example usage for com.google.common.collect Iterables getFirst.

Prototype

@Nullable
public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue) 

Source Link

Document

Returns the first element in iterable or defaultValue if the iterable is empty.

Usage

From source file:org.wso2.carbon.identity.application.authenticator.fido.u2f.data.messages.AuthenticateRequestData.java

public String getRequestId() {
    return Iterables.getFirst(authenticateRequests, null).getChallenge();
}

From source file:org.polymap.core.mapeditor.tooling.edit.RegularPolygonTool.java

@Override
public void init(IEditorToolSite site) {
    super.init(site);

    // disable deactivation for other tools
    getSite().removeListener(this);

    parentTool = (DigitizeTool) Iterables
            .getFirst(site.filterTools(EditorTools.isEqual(getToolPath().removeLastSegments(1))), null);
    assert parentTool != null;

    // the handler also initializes tool state
    parentTool.addListener(RegularPolygonTool.this);

    // listen to state changes of parentTool
    site.addListener(new ToolingListener() {
        public void toolingChanged(ToolingEvent ev) {
            if (ev.getSource().equals(parentTool)) {
                if (ev.getType() == EventType.TOOL_ACTIVATED) {
                } else if (ev.getType() == EventType.TOOL_DEACTIVATING) {
                    getSite().getMemento().putBoolean(PROP_ACTIVE, isActive());
                }//from ww w .  j ava2s  . c  om
            }
        }
    });
}

From source file:de.faustedition.query.QueryResource.java

@Get("json")
public Representation results() {

    if (LOG.isTraceEnabled()) {
        LOG.trace("Searching for '{}'", queryTerm);
    }/*from  w ww . j  ava 2s  . c o  m*/

    if (QueryTerms.ALLDOCUMENTS.name().equals(queryTerm.toUpperCase())) {

        Iterable<Document> allDocuments = Iterables.filter(graph.getMaterialUnits(), Document.class);

        Iterable<String> allMaterialUnits = Iterables.<Document, String>transform(allDocuments,

                new Function<Document, String>() {
                    @Override
                    public String apply(@Nullable Document input) {

                        return Iterables.getFirst(Arrays.asList(input.getMetadata("uri")), "none");
                    }
                });

        return jsonFactory.map(allMaterialUnits);

    } else
        return null;

}

From source file:io.brooklyn.ambari.agent.AmbariAgentSshDriver.java

@Override
public void install() {
    String parentFQDN = entity.getParent() instanceof AmbariServer
            ? ((AmbariServer) entity.getParent()).getFqdn()
            : "";

    Entity parentHostGroup = Iterables
            .getFirst(Iterables.filter(Entities.ancestors(entity), AmbariHostGroup.class), entity);

    String fqdn = parentFQDN.isEmpty()
            ? String.format("%s-%s.%s", parentHostGroup.getDisplayName().toLowerCase(),
                    entity.getId().toLowerCase(), entity.getConfig(AmbariCluster.DOMAIN_NAME))
            : parentFQDN;/*from  ww  w .  j  a v a 2 s . c om*/

    getEntity().setFqdn(fqdn);
    ImmutableList<String> commands = ImmutableList.<String>builder()
            .add(defaultAmbariInstallHelper.installAmbariRequirements(getMachine()))
            .addAll(BashCommands.setHostname(fqdn)).add(installPackage("ambari-agent")).build();

    newScript(INSTALLING).body.append(commands).failOnNonZeroResultCode().execute();
}

From source file:com.zulily.omicron.Utils.java

private static String getInetHost() {
    try {/*  w  ww  .j av  a 2 s.c  o  m*/
        return Iterables.getFirst(DOT_SPLITTER.split(InetAddress.getLocalHost().getHostName()), "UNKNOWN_HOST");
    } catch (Exception e) {
        return "UNKNOWN_HOST";
    }
}

From source file:org.loadui.testfx.service.finder.impl.NodeFinderImpl.java

public Node node(String query) {
    Set<Node> resultNodes = nodes(query);
    return Iterables.getFirst(resultNodes, null);
}

From source file:com.b2international.commons.dynamic.AbstractDynamicMap.java

@Override
public DynamicValue getFirstPropertyValue(String property) {
    Entry firstEntry = Iterables.getFirst(getProperty(property), null);
    return (firstEntry == null) ? DynamicValue.MISSING : firstEntry.getValue();
}

From source file:org.sonatype.nexus.repository.storage.BucketEntityAdapter.java

@Nullable
Bucket getByRepositoryName(final ODatabaseDocumentTx db, final String repositoryName) {
    Iterable<ODocument> docs = db.command(new OCommandSQL(GET_BY_QUERY)).execute(repositoryName);
    ODocument first = Iterables.getFirst(docs, null);
    return first != null ? readEntity(first) : null;
}

From source file:org.trustedanalytics.cloud.uaa.UaaClient.java

@Override
public Optional<UserIdNamePair> findUserIdByName(String userName) {
    String query = "/Users?attributes=id,userName&filter=userName eq '{name}'";
    Map<String, Object> pathVars = ImmutableMap.of("name", userName);
    UserIdNameList result = uaaRestTemplate.getForObject(uaaBaseUrl + query, UserIdNameList.class, pathVars);
    return Optional.ofNullable(Iterables.getFirst(result.getUsers(), null));
}

From source file:com.ignorelist.kassandra.steam.scraper.HtmlTagLoader.java

@Override
public GameInfo load(Long gameId, EnumSet<TagType> types) {
    GameInfo gameInfo = new GameInfo();
    gameInfo.setId(gameId);/*ww  w .  j a  va2  s. c o m*/
    try {
        if (!types.isEmpty()) {
            InputStream inputStream = cache.get(gameId.toString());
            try {
                Document document = Jsoup.parse(inputStream, Charsets.UTF_8.name(), buildPageUrl(gameId));

                Elements appName = document.select("div.apphub_AppName");
                Element nameElement = Iterables.getFirst(appName, null);
                if (null != nameElement && null != nameElement.text()) {
                    gameInfo.setName(nameElement.text().trim());
                }

                Elements appIconElements = document.select("div.apphub_AppIcon img");
                gameInfo.setIcon(getSrcUri(appIconElements));

                Elements headerImageElements = document.select("img.game_header_image_full");
                gameInfo.setHeaderImage(getSrcUri(headerImageElements));
                final SetMultimap<TagType, String> tags = gameInfo.getTags();

                if (types.contains(TagType.CATEGORY)) {
                    Elements categories = document.select("div#category_block a.name");
                    copyText(categories, tags.get(TagType.CATEGORY));
                }
                if (types.contains(TagType.GENRE)) {
                    Elements genres = document.select("div.details_block a[href*=/genre/]");
                    copyText(genres, tags.get(TagType.GENRE));
                }
                if (types.contains(TagType.USER)) {
                    Elements userTags = document.select("a.app_tag");
                    copyText(Iterables.filter(userTags, Predicates.not(DISPLAY_NONE_PREDICATE)),
                            tags.get(TagType.USER));
                    copyText(Iterables.filter(userTags, DISPLAY_NONE_PREDICATE), tags.get(TagType.USER_HIDDEN));
                }
                if (types.contains(TagType.VR)) {
                    Elements vrSupport = document
                            .select("div.game_area_details_specs a.name[href*=#vrsupport=");
                    copyText(vrSupport, tags.get(TagType.VR));
                }
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        }
    } catch (ExecutionException ex) {
        Logger.getLogger(HtmlTagLoader.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HtmlTagLoader.class.getName()).log(Level.SEVERE, null, ex);
    }

    return gameInfo;
}