List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.thiesen.jiffs.jobs.preprocessor.Preprocessor.java
@Override public void execute() { final Iterable<StoryDBO> unprocessed = _storyDAO.findWithoutPreprocesing(); System.out.println("Preprocessing " + Iterables.size(unprocessed) + " stories"); for (final StoryDBO story : unprocessed) { EXECUTOR.submit(new Runnable() { @Override//w ww.java 2 s . c om public void run() { preproecessText(story); } }); } EXECUTOR.shutdown(); try { EXECUTOR.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException e) { Thread.interrupted(); } }
From source file:org.erlide.ui.util.ETreeNode.java
/** * Returns the child nodes. Empty arrays are converted to <code>null</code> * before being returned.//from www.j a va 2s . c o m * * @return The child nodes; may be <code>null</code>, but never empty. There * should be no <code>null</code> children in the array. */ public Iterable<ETreeNode> getChildren() { if (children != null && Iterables.size(children) == 0) { return null; } return children; }
From source file:r.base.special.SwitchFunction.java
@Override public SEXP apply(Context context, Environment rho, FunctionCall call, PairList args) { EvalException.check(call.length() > 1, "argument \"EXPR\" is missing"); SEXP expr = context.evaluate(call.getArgument(0), rho); EvalException.check(expr.length() == 1, "EXPR must return a length 1 vector"); PromisePairList branchPromises = (PromisePairList) context.evaluate(call.getArgument(1), rho); Iterable<PairList.Node> branches = branchPromises.nodes(); if (expr instanceof StringVector) { String name = ((StringVector) expr).getElementAsString(0); if (StringVector.isNA(name)) { context.setInvisibleFlag();// www .ja v a 2 s . c o m return Null.INSTANCE; } SEXP partialMatch = null; int partialMatchCount = 0; for (PairList.Node node : branches) { if (node.hasTag()) { String branchName = node.getTag().getPrintName(); if (branchName.equals(name)) { return context.evaluate(nextNonMissing(node), rho); } else if (branchName.startsWith(name)) { partialMatch = nextNonMissing(node); partialMatchCount++; } } } if (partialMatchCount == 1) { return context.evaluate(partialMatch, rho); } else if (Iterables.size(branches) > 0) { PairList.Node last = Iterables.getLast(branches); if (!last.hasTag()) { return context.evaluate(last.getValue(), rho); } } } else if (expr instanceof AtomicVector) { int branchIndex = ((AtomicVector) expr).getElementAsInt(0); if (branchIndex >= 1 && branchIndex <= Iterables.size(branches)) { return context.evaluate(Iterables.get(branches, branchIndex - 1).getValue(), rho); } } return Null.INSTANCE; }
From source file:com.google.javascript.jscomp.PrebuildDependencyInfo.java
void prebuild(Iterable<CompilerInput> allInputs) { ThreadFactory threadFactory = new ThreadFactory() { @Override/* ww w . ja v a 2 s. c o m*/ public Thread newThread(Runnable r) { Thread t = new Thread(null, r, "jscompiler-PrebuildDependencyInfo", CompilerExecutor.COMPILER_STACK_SIZE); t.setDaemon(true); // Do not prevent the JVM from exiting. return t; } }; ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(numParallelThreads, numParallelThreads, Integer.MAX_VALUE, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); ListeningExecutorService executorService = MoreExecutors.listeningDecorator(poolExecutor); List<ListenableFuture<?>> futureList = new ArrayList<>(Iterables.size(allInputs)); // TODO(moz): Support canceling all parsing on the first halting error for (final CompilerInput input : allInputs) { futureList.add(executorService.submit(new Runnable() { @Override public void run() { input.getDependencyInfo(); } })); } poolExecutor.shutdown(); try { Futures.allAsList(futureList).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
From source file:dagger2.internal.codegen.writer.Snippet.java
public static Snippet memberSelectSnippet(Iterable<? extends Object> selectors) { return format(Joiner.on('.').join(Collections.nCopies(Iterables.size(selectors), "%s")), selectors); }
From source file:org.asoem.greyfish.core.actions.ResourceConsumptionAction.java
@Override protected ImmutableACLMessage.Builder<A> createCFP(final AgentContext<A> context) { final A receiver = Iterables.get(sensedMates, RandomGenerators.rng().nextInt(Iterables.size(sensedMates))); sensedMates = ImmutableList.of();/* w ww . java 2 s.c o m*/ return ImmutableACLMessage.<A>builder().sender(context.agent()).performative(ACLPerformative.CFP) .ontology(getOntology()) // Choose only one receiver. Adding evaluates possible candidates as receivers will decrease the performance in high density populations! .addReceiver(receiver) .content(new ResourceRequestMessage(call(requestAmount, this), call(classification, this))); }
From source file:org.jclouds.examples.rackspace.clouddns.DeleteDomains.java
private void deleteAllDomains() throws TimeoutException { System.out.format("Delete Domains%n"); Set<Domain> allDomains = dnsApi.getDomainApi().list().concat().toSet(); Iterable<Domain> topLevelDomains = Iterables.filter(allDomains, IS_DOMAIN); Iterable<Integer> topLevelDomainIds = Iterables.transform(topLevelDomains, GET_DOMAIN_ID); awaitComplete(dnsApi, dnsApi.getDomainApi().delete(topLevelDomainIds, true)); System.out.format(" Deleted %s top level domains and all subdomains%n", Iterables.size(topLevelDomainIds)); }
From source file:org.jclouds.azurecompute.compute.functions.internal.OperatingSystems.java
public static Function<OSImage, String> version() { return new Function<OSImage, String>() { @Override/*ww w . jav a2 s. co m*/ public String apply(final OSImage osImage) { if (osImage.category().matches("Canonical|OpenLogic")) { return Iterables.get(Splitter.on(" ").split(osImage.label()), 2); } else if (osImage.category().matches(SUSE)) { if (osImage.label().startsWith(OPENSUSE)) { return osImage.label().substring(OPENSUSE.length() + 1); } if (osImage.label().startsWith(SUSE)) { return Iterables.get(Splitter.on("-").split(osImage.name()), 4); } } else if (osImage.category().matches(MICROSOFT)) { if (osImage.label().startsWith(WINDOWS_SERVER)) { return osImage.label().substring(WINDOWS_SERVER.length() + 1); } if (osImage.label().startsWith(MICROSOFT_SQL_SERVER)) { return osImage.label().substring(MICROSOFT_SQL_SERVER.length() + 1); } } else if (osImage.category().matches("RightScale with Linux|Public ")) { final Iterable<String> splittedLabel = Splitter.on("-").split(osImage.label()); if (Iterables.size(splittedLabel) > 2) { return Iterables.get(splittedLabel, 2); } } return null; } }; }
From source file:eu.numberfour.n4js.ui.preferences.ExternalLibraryTreeContentProvider.java
@Override public void updateChildCount(final Object element, final int currentChildCount) { if (treeViewerRef.isPresent()) { final TreeViewer treeViewer = treeViewerRef.get(); if (element instanceof Iterable) { treeViewer.setChildCount(element, Iterables.size((Iterable<?>) element)); } else if (element instanceof URI) { treeViewer.setChildCount(element, Iterables.size(getProjects((URI) element))); } else {/*w ww. ja v a 2 s . c om*/ treeViewer.setChildCount(element, 0); } } }
From source file:com.smbtec.xo.tinkerpop.blueprints.impl.TinkerPopRepositoryImpl.java
@Override public <T> long count(Class<T> type) { EntityTypeMetadata<VertexMetadata> entityTypeMetadata = xoSession.getEntityMetadata(type); String label = entityTypeMetadata.getDatastoreMetadata().getDiscriminator(); Iterable<Vertex> vertices = graph.query().has(TinkerPopVertexManager.getDiscriminatorPropertyKey(label)) .vertices();//from w w w .ja v a2 s. c om return Iterables.size(vertices); }