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

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

Introduction

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

Prototype

public static <T> T getOnlyElement(Iterable<T> iterable) 

Source Link

Document

Returns the single element contained in iterable .

Usage

From source file:org.jclouds.cloudtransformer.openstack.GenericComputeServiceContextToOpenstackComputeServiceContext.java

public static NodeMetadata getDevstackNode(ComputeServiceContext ctx) {
    return Iterables
            .getOnlyElement(ctx.getComputeService().listNodesDetailsMatching(new Predicate<ComputeMetadata>() {
                @Override//w w w  . j a v a 2 s .  com
                public boolean apply(ComputeMetadata input) {
                    checkArgument(input instanceof NodeMetadata);
                    return ((NodeMetadata) input).getGroup().equals("devstack");
                }
            }));
}

From source file:org.sonar.plugins.scmactivity.PreviousSha1Finder.java

public String find(Resource resource) {
    List<Measure> measures = timeMachine.getMeasures(queryPreviousHash(resource));
    if (measures.isEmpty()) {
        return "";
    }/*from  www. ja  va  2 s .  c om*/

    return Iterables.getOnlyElement(measures).getData();
}

From source file:com.squareup.wire.ConsoleWireLogger.java

@Override
public void artifact(Path outputPath, FileSpec kotlinFile) {
    TypeSpec typeSpec = (TypeSpec) Iterables.getOnlyElement(kotlinFile.getMembers());
    if (quiet) {/*from  w  ww .  j a v  a 2  s  .  co  m*/
        System.out.printf("%s.%s%n", kotlinFile.getPackageName(), typeSpec.getName());
    } else {
        System.out.printf("Writing %s.%s to %s%n", kotlinFile.getPackageName(), typeSpec.getName(), outputPath);
    }
}

From source file:org.jclouds.gogrid.functions.ParseServerFromJsonResponse.java

@Override
public Server apply(HttpResponse arg0) {
    return Iterables.getOnlyElement(parser.apply(arg0));
}

From source file:com.google.gerrit.server.account.GroupBackends.java

/**
 * Runs {@link GroupBackend#suggest(String, Project)} and filters the result to return
 * the best suggestion, or null if one does not exist.
 *
 * @param groupBackend the group backend
 * @param name the name for which to suggest groups
 * @param project the project for which to suggest groups
 * @return the best single GroupReference suggestion
 *///  w  w  w .jav  a2 s  .  c  om
@Nullable
public static GroupReference findBestSuggestion(GroupBackend groupBackend, String name,
        @Nullable ProjectControl project) {
    Collection<GroupReference> refs = groupBackend.suggest(name, project);
    if (refs.size() == 1) {
        return Iterables.getOnlyElement(refs);
    }

    for (GroupReference ref : refs) {
        if (isExactSuggestion(ref, name)) {
            return ref;
        }
    }
    return null;
}

From source file:org.fuusio.api.nfc.SmartPosterRecord.java

public static SmartPosterRecord parse(final NdefRecord[] recordsRaw) {
    try {// ww  w.j  a v a2 s  .c  om
        final Iterable<ParsedNdefRecord> records = getRecords(recordsRaw);
        final UriRecord uri = Iterables.getOnlyElement(Iterables.filter(records, UriRecord.class));
        final TextRecord title = getFirstIfExists(records, TextRecord.class);
        final RecommendedAction action = parseRecommendedAction(recordsRaw);
        final String type = parseType(recordsRaw);
        return new SmartPosterRecord(uri, title, action, type);
    } catch (final NoSuchElementException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.jclouds.profitbricks.compute.function.LocationToLocation.java

@Override
public org.jclouds.domain.Location apply(Location in) {
    return new LocationBuilder().id(in.getId()).description(in.getDescription()).scope(LocationScope.REGION)
            .parent(Iterables.getOnlyElement(justProvider.get())).build();
}

From source file:org.jclouds.fujitsu.fgcp.xml.internal.GetPublicIPAttributesResponse.java

@Override
public Object getElement() {
    return Iterables.getOnlyElement(publicIPs);
}

From source file:com.android.build.gradle.integration.common.utils.DeviceHelper.java

public static IDevice getIDevice() throws DeviceException {
    return Iterables.getOnlyElement(getIDevices());
}

From source file:org.apache.whirr.service.TagBuilder.java

public static <T extends NodeMetadata> NodeMetadata getSingleNodeInRole(final String roleAbreviation,
        Collection<T> nodes) {
    return Iterables.getOnlyElement(Collections2.filter(nodes, new Predicate<NodeMetadata>() {
        @Override/*from w  w  w .j a  va 2s . c  o  m*/
        public boolean apply(NodeMetadata metadata) {
            return Iterables.contains(rolesFromTag(metadata.getTag()), roleAbreviation);
        }
    }));
}