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

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

Introduction

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

Prototype

public static int size(Iterable<?> iterable) 

Source Link

Document

Returns the number of elements in iterable .

Usage

From source file:com.shin1ogawa.appengine.marketplace.gdata.LicensingAPI.java

/**
 * retrieve the domain's licensing state.
 * @param appId ID of application to do listing to Marketplace
 * @param domain domain name to be investigated
 * @return a map of domain's licensing state
 * <ul>//w w  w.j  a  v a2s . c  om
 * <li><code>id</code></li>
 * <li><code>enabled</code></li>
 * <li><code>state</code>: ACTIVE or UNLICENSED or PENDING</li>
 * </ul>
 * @see <a href="http://code.google.com/googleapps/marketplace/licensing.html#licensed">Check that a Domain is Licensed</a>
 * @throws GDataAPIException 
 */
public Map<String, String> retrieveLicenseStateOfDomain(String appId, String domain) {
    try {
        String url = "http://feedserver-enterprise.googleusercontent.com/license?bq=" + OPEN_SQUARE + "appid"
                + EQUAL + appId + CLOSE_BRACE + OPEN_SQUARE + "domain" + EQUAL + domain + CLOSE_BRACE;
        AppsPropertyService service = new AppsPropertyService(GDataAPIUtil.getApplicationName());
        service.setOAuthCredentials(oauthParams, new OAuthHmacSha1Signer());
        List<Map<String, String>> states = parseLicenseFeed(
                GDataAPIUtil.getXmlWithRetry(service, new URL(url)));
        if (Iterables.size(states) != 1) {
            throw new IllegalStateException("Too many state.");
        }
        return states.get(0);
    } catch (MalformedURLException e) {
        throw new GDataAPIUtil.GDataAPIException(e);
    } catch (SAXException e) {
        throw new GDataAPIUtil.GDataAPIException(e);
    } catch (IOException e) {
        throw new GDataAPIUtil.GDataAPIException(e);
    } catch (ParserConfigurationException e) {
        throw new GDataAPIUtil.GDataAPIException(e);
    } catch (OAuthException e) {
        throw new GDataAPIUtil.GDataAPIException(e);
    }
}

From source file:com.github.msoliter.iroh.container.resolvers.SubclassResolver.java

@Override
public Source resolve(final Field field) {

    /**/*from  ww w  .  j a  v  a 2 s  .  c  om*/
     * Find all potential sources by filter on whether or not a source's
     * type can be assigned to the field's type.
     */
    Iterable<Source> potential = Iterables
            .concat(Collections2.transform(Collections2.filter(sources.keySet(), new Predicate<Class<?>>() {

                @Override
                public boolean apply(Class<?> type) {
                    return field.getType().isAssignableFrom(type);
                }
            }), new Function<Class<?>, Collection<Source>>() {

                @Override
                public Collection<Source> apply(Class<?> type) {
                    return sources.get(type);
                }
            }));

    /**
     * If there isn't exactly one source in the set, check if there's 
     * exactly one overriding source available, in case we're unit testing.
     */
    if (Iterables.size(potential) != 1) {
        Iterable<Source> overriding = Iterables.filter(potential, new Predicate<Source>() {

            @Override
            public boolean apply(Source source) {
                return source.isOverriding();
            }
        });

        if (Iterables.size(overriding) != 1) {
            throw new UnexpectedImplementationCountException(field.getType(),
                    Iterables.transform(potential, new Function<Source, Class<?>>() {

                        @Override
                        public Class<?> apply(Source source) {
                            return source.getType();
                        }
                    }));

        } else {
            return overriding.iterator().next();
        }

    } else {
        return potential.iterator().next();
    }
}

From source file:org.trimou.handlebars.EachHelper.java

@SuppressWarnings("rawtypes")
private void processIterable(Iterable iterable, Options options) {
    int size = Iterables.size(iterable);
    if (size < 1) {
        return;// w  w  w .  j  a v  a 2s. c  o  m
    }
    final Iterator iterator = iterable.iterator();
    int i = 1;
    while (iterator.hasNext()) {
        nextElement(options, iterator.next(), size, i++, initFunction(options), initValueAlias(options));
    }
}

From source file:com.metamx.druid.indexing.common.task.MergeTaskBase.java

protected MergeTaskBase(final String id, final String dataSource, final List<DataSegment> segments) {
    super(/*from  w  w w. j ava 2s . co m*/
            // _not_ the version, just something uniqueish
            id != null ? id
                    : String.format("merge_%s_%s", computeProcessingID(dataSource, segments),
                            new DateTime().toString()),
            dataSource, computeMergedInterval(segments));

    // Verify segment list is nonempty
    Preconditions.checkArgument(segments.size() > 0, "segments nonempty");
    // Verify segments are all in the correct datasource
    Preconditions.checkArgument(Iterables.size(Iterables.filter(segments, new Predicate<DataSegment>() {
        @Override
        public boolean apply(@Nullable DataSegment segment) {
            return segment == null || !segment.getDataSource().equalsIgnoreCase(dataSource);
        }
    })) == 0, "segments in the wrong datasource");
    // Verify segments are all unsharded
    Preconditions.checkArgument(Iterables.size(Iterables.filter(segments, new Predicate<DataSegment>() {
        @Override
        public boolean apply(@Nullable DataSegment segment) {
            return segment == null || !(segment.getShardSpec() instanceof NoneShardSpec);
        }
    })) == 0, "segments without NoneShardSpec");

    this.segments = segments;
}

From source file:org.obm.xml.AcceptDifferentNamespaceXMLUnit.java

private static String getNodeNameWithoutNamespace(String nodeName) {
    Iterable<String> splitedName = Splitter.on(':').omitEmptyStrings().split(nodeName);
    if (Iterables.size(splitedName) == 2) {
        nodeName = Iterables.get(splitedName, 1);
    } else {/* w  ww .j  a  v a  2s. c o m*/
        throw new IllegalArgumentException("The node name is illegal : " + nodeName);
    }
    return nodeName;
}

From source file:org.erlide.ui.util.ETreeNode.java

/**
 * Returns whether the tree has any children.
 *
 * @return <code>true</code> if its array of children is not
 *         <code>null</code> and is non-empty; <code>false</code> otherwise.
 *//*from www .  jav a  2  s.c o m*/
public boolean hasChildren() {
    return children != null && Iterables.size(children) > 0;
}

From source file:org.thiesen.collections.set.impl.AbstractDelegatingMutableSet.java

@Override
public boolean hasSingleValueOnly() {
    return Iterables.size(delegate()) == 1;
}

From source file:com.facebook.buck.core.model.actiongraph.computation.SerialActionGraphFactory.java

@Override
public ActionGraphAndBuilder create(TargetNodeToBuildRuleTransformer transformer, TargetGraph targetGraph,
        ActionGraphCreationLifecycleListener actionGraphCreationLifecycleListener) {
    // TODO: Reduce duplication between the serial and parallel creation methods.
    ActionGraphBuilder graphBuilder = new SingleThreadedActionGraphBuilder(targetGraph, transformer,
            cellProvider);// ww  w.  j av  a2  s  .  c  o m

    actionGraphCreationLifecycleListener.onCreate(graphBuilder);

    LOG.debug("start target graph walk");
    new AbstractBottomUpTraversal<TargetNode<?>, RuntimeException>(targetGraph) {
        @Override
        public void visit(TargetNode<?> node) {
            if (shouldInstrumentGraphBuilding) {
                Clock clock = new DefaultClock();
                try (Scope ignored = ActionGraphPerfStatEvent.start(clock, eventBus,
                        () -> Iterables.size(graphBuilder.getBuildRules()),
                        () -> StreamSupport.stream(graphBuilder.getBuildRules().spliterator(), true)
                                .filter(rule -> rule instanceof NoopBuildRule
                                        || rule instanceof NoopBuildRuleWithDeclaredAndExtraDeps)
                                .count(),
                        node.getDescription().getClass().getName(),
                        node.getBuildTarget().getFullyQualifiedName())) {
                    graphBuilder.requireRule(node.getBuildTarget());
                }
            } else {
                graphBuilder.requireRule(node.getBuildTarget());
            }
        }
    }.traverse();
    LOG.debug("end target graph walk");

    return ActionGraphAndBuilder.builder().setActionGraph(new ActionGraph(graphBuilder.getBuildRules()))
            .setActionGraphBuilder(graphBuilder).build();
}

From source file:co.cask.cdap.internal.app.runtime.webapp.ServePathGenerator.java

private String findPath(String hostHeader, String path, String query) {
    // First try firstPathPart/src/restPath
    Iterable<String> pathParts = Splitter.on('/').limit(2).split(path);
    String servePath;/* w  ww.  ja  v a  2  s.  c  o  m*/
    if (Iterables.size(pathParts) > 1) {
        String part1 = Iterables.get(pathParts, 1);
        if (part1.startsWith(GATEWAY_PATH_V3) || part1.equals("status")) {
            return constructPath(part1, query);
        }

        servePath = String.format("%s/%s/%s%s%s", baseDir, hostHeader, Iterables.get(pathParts, 0), SRC_PATH,
                Iterables.get(pathParts, 1));
        if (fileExists.apply(servePath)) {
            return servePath;
        }

    } else if (Iterables.size(pathParts) == 1) {
        servePath = String.format("%s/%s/%s%s%s", baseDir, hostHeader, Iterables.get(pathParts, 0), SRC_PATH,
                "index.html");
        if (fileExists.apply(servePath)) {
            return servePath;
        }
    }

    // Next try src/path
    if (path.startsWith(GATEWAY_PATH_V3) || path.equals("status")) {
        return constructPath(path, query);
    }

    path = path.isEmpty() ? "index.html" : path;
    servePath = String.format("%s/%s%s%s", baseDir, hostHeader, SRC_PATH, path);
    if (fileExists.apply(servePath)) {
        return servePath;
    }

    return null;
}

From source file:org.apache.aurora.scheduler.base.Tasks.java

/**
 * Get the latest active task or the latest inactive task if no active task exists.
 *
 * @param tasks a collection of tasks//from www .  ja  v  a 2s.  c o m
 * @return the task that transitioned most recently.
 */
public static IScheduledTask getLatestActiveTask(Iterable<IScheduledTask> tasks) {
    Preconditions.checkArgument(Iterables.size(tasks) != 0);

    return Ordering.explicit(ORDERED_TASK_STATUSES).onResultOf(IScheduledTask::getStatus)
            .compound(LATEST_ACTIVITY).max(tasks);
}