List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.apache.mahout.clustering.streaming.tools.ResplitSequenceFiles.java
private void run(PrintWriter printWriter) throws IOException { conf = new Configuration(); SequenceFileDirIterable<Writable, Writable> inputIterable = new SequenceFileDirIterable<Writable, Writable>( new Path(inputFile), PathType.LIST, conf); fs = FileSystem.get(conf);/* ww w .ja va2s .co m*/ int numEntries = Iterables.size(inputIterable); int numEntriesPerSplit = numEntries / numSplits; int numEntriesLastSplit = numEntriesPerSplit + numEntries - numEntriesPerSplit * numSplits; Iterator<Pair<Writable, Writable>> inputIterator = inputIterable.iterator(); printWriter.printf("Writing %d splits\n", numSplits); for (int i = 0; i < numSplits - 1; ++i) { printWriter.printf("Writing split %d\n", i); writeSplit(inputIterator, i, numEntriesPerSplit); } printWriter.printf("Writing split %d\n", numSplits - 1); writeSplit(inputIterator, numSplits - 1, numEntriesLastSplit); }
From source file:org.richfaces.component.DeclarativeTreeDataModelWalker.java
private void setupDataModelContext(Object key) { if (modelData instanceof Iterable<?>) { Iterable<?> iterable = (Iterable<?>) modelData; Integer index = (Integer) key; if (index < Iterables.size(iterable)) { data = Iterables.get(iterable, index); } else {/*from www .j a v a2 s.c o m*/ data = null; } } else { data = ((Map<?, ?>) modelData).get(key); } }
From source file:com.lyndir.lanterna.view.TextView.java
public void setText(final String text) { this.text = text; // Update offset in case text lines shrank beyond the current offset. textOffset = Math.min(textOffset, Iterables.size(getTextLines())); }
From source file:org.thiesen.collections.set.impl.AbstractDelegatingImmutableSet.java
@Override public boolean hasSingleValueOnly() { return Iterables.size(_set) == 1; }
From source file:io.druid.indexing.common.task.MergeTaskBase.java
protected MergeTaskBase(final String id, final String dataSource, final List<DataSegment> segments, Map<String, Object> context) { super(/*from w w w. ja va2 s . c o m*/ // _not_ the version, just something uniqueish id != null ? id : String.format("merge_%s_%s", computeProcessingID(dataSource, segments), new DateTime().toString()), dataSource, computeMergedInterval(segments), context); // 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.jclouds.scriptbuilder.domain.AppendFile.java
protected AppendFile(String path, Iterable<String> lines, String delimiter, boolean expandVariables) { this.path = checkNotNull(path, "PATH"); this.lines = checkNotNull(lines, "lines"); this.delimiter = checkNotNull(delimiter, "delimiter"); checkState(Iterables.size(lines) > 0, "you must pass something to execute"); this.expandVariables = expandVariables; }
From source file:com.google.javascript.rhino.testing.Asserts.java
public static <T extends JSType, S extends JSType> void assertTypeCollectionEquals(Iterable<T> a, Iterable<S> b) {/*from w w w.j a va 2s . c om*/ assertThat(b).hasSize(Iterables.size(a)); Iterator<T> aIterator = a.iterator(); Iterator<S> bIterator = b.iterator(); while (aIterator.hasNext()) { assertTypeEquals(aIterator.next(), bIterator.next()); } }
From source file:org.apache.mahout.math.neighborhood.Searcher.java
public List<List<WeightedThing<Vector>>> search(Iterable<? extends Vector> queries, int limit) { List<List<WeightedThing<Vector>>> results = Lists.newArrayListWithExpectedSize(Iterables.size(queries)); for (Vector query : queries) { results.add(search(query, limit)); }/*from w w w .j a va 2s. c om*/ return results; }
From source file:org.jclouds.cloudstack.functions.CreatePortForwardingRulesForIP.java
public Set<IPForwardingRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<IPForwardingRule>of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getNATClient().createIPForwardingRule(ip.getId(), protocol, port); logger.debug(">> creating IP forwarding rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response);/*from www. j av a 2 s . co m*/ } Builder<IPForwardingRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { IPForwardingRule rule = blockUntilJobCompletesAndReturnResult.<IPForwardingRule>apply(response); rules.add(rule); getIPForwardingRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); }
From source file:com.google.devtools.build.lib.actions.ArtifactIdRegistry.java
@Override public ImmutableList<Artifact> lookupArtifactsByIds(Iterable<Integer> artifactIds) { int size = Iterables.size(artifactIds); Artifact[] result = new Artifact[size]; int i = 0;/*from w ww . j av a 2 s .c om*/ artifactIdsLock.readLock().lock(); try { for (int artifactId : artifactIds) { result[i] = serializedArtifactList.get(artifactId); i++; } } finally { artifactIdsLock.readLock().unlock(); } return ImmutableList.copyOf(result); }