List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.eclipse.scada.ca.ui.importer.wizard.ImportWizard.java
protected void applyDiff(final IProgressMonitor parentMonitor) throws InterruptedException, ExecutionException { final SubMonitor monitor = SubMonitor.convert(parentMonitor, 100); monitor.setTaskName(Messages.ImportWizard_TaskName); final Collection<DiffEntry> result = this.mergeController.merge(wrap(monitor.newChild(10))); if (result.isEmpty()) { monitor.done();//from w w w . j ava 2 s. c om return; } final Iterable<List<DiffEntry>> splitted = Iterables.partition(result, Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.P_DEFAULT_CHUNK_SIZE)); final SubMonitor sub = monitor.newChild(90); try { final int size = Iterables.size(splitted); sub.beginTask(Messages.ImportWizard_TaskName, size); int pos = 0; for (final Iterable<DiffEntry> i : splitted) { sub.subTask(String.format(Messages.ImportWizard_SubTaskName, pos, size)); final List<DiffEntry> entries = new LinkedList<DiffEntry>(); Iterables.addAll(entries, i); final NotifyFuture<Void> future = this.connection.getConnection().applyDiff(entries, null, new DisplayCallbackHandler(getShell(), "Apply diff", "Confirmation for applying diff is required")); future.get(); pos++; sub.worked(1); } } finally { sub.done(); } }
From source file:iterator.Animator.java
/** * Parse the animation configuration file. * * See the online documentation for more details. The format is generally as shown below: * * <pre>/*from ww w .j a va 2 s. c o m*/ * {@code # comment * ifs file * save directory * frames count * delay ms * iterations thousands * zoom scale centrex centrey * segment frames * transform id field start finish * end} * </pre> * * @see <a href="http://grkvlt.github.io/iterator/">online documentation</a> * @throws IOException * @throws IllegalStateException * @throws NumberFormatException */ public void parse(File config) throws IOException { for (String line : Files.readLines(config, Charsets.UTF_8)) { Iterable<String> tokens = Splitter.on(' ').omitEmptyStrings().trimResults().split(line); if (Iterables.isEmpty(tokens)) continue; String type = Iterables.get(tokens, 0); if (type.equalsIgnoreCase("ifs")) { // ifs file if (Iterables.size(tokens) != 2) { throw new IllegalStateException("Parse error at 'ifs': " + line); } input = new File(Iterables.get(tokens, 1).replace("~", System.getProperty("user.home"))); } else if (type.equalsIgnoreCase("save")) { // save directory if (Iterables.size(tokens) != 2) { throw new IllegalStateException("Parse error at 'save': " + line); } output = new File(Iterables.get(tokens, 1).replace("~", System.getProperty("user.home"))); } else if (type.equalsIgnoreCase("frames")) { // frames count if (Iterables.size(tokens) != 2) { throw new IllegalStateException("Parse error at 'frames': " + line); } frames = Long.valueOf(Iterables.get(tokens, 1)); } else if (type.equalsIgnoreCase("delay")) { // delay ms if (Iterables.size(tokens) != 2) { throw new IllegalStateException("Parse error at 'delay': " + line); } delay = Long.valueOf(Iterables.get(tokens, 1)); } else if (type.equalsIgnoreCase("iterations")) { // iterations thousands if (Iterables.size(tokens) != 2) { throw new IllegalStateException("Parse error at 'iterations': " + line); } iterations = Long.valueOf(Iterables.get(tokens, 1)); } else if (type.equalsIgnoreCase("zoom")) { // zoom scale centrex centrey if (Iterables.size(tokens) != 4) { throw new IllegalStateException("Parse error at 'zoom': " + line); } scale = Float.valueOf(Iterables.get(tokens, 1)); centre = new Point2D.Double(Double.valueOf(Iterables.get(tokens, 2)), Double.valueOf(Iterables.get(tokens, 3))); } else if (type.equalsIgnoreCase("transform")) { // transform id field start finish if (Iterables.size(tokens) != 5) { throw new IllegalStateException("Parse error at 'transform': " + line); } Change change = new Change(); change.transform = Integer.valueOf(Iterables.get(tokens, 1)); String field = Iterables.get(tokens, 2).toLowerCase(); if (field.length() == 1 && CharMatcher.anyOf("xywhr").matches(field.charAt(0))) { change.field = field.charAt(0); } else { throw new IllegalStateException("Parse error at 'transform' field: " + line); } change.start = Double.valueOf(Iterables.get(tokens, 3)); change.end = Double.valueOf(Iterables.get(tokens, 4)); list.add(change); } else if (type.equalsIgnoreCase("segment")) { // segment frames? if (Iterables.size(tokens) == 2) { segment = Long.valueOf(Iterables.get(tokens, 1)); } else { segment = frames; } list.clear(); } else if (type.equalsIgnoreCase("end")) { // end if (Iterables.size(tokens) != 1) { throw new IllegalStateException("Parse error at 'end': " + line); } segments.put(ImmutableList.copyOf(list), segment); } else if (type.startsWith("#")) { // # comment continue; } else { throw new IllegalStateException("Parse error: " + line); } } // Deal with single segment case (no 'segment' or 'end' token) if (segments.isEmpty() && list.size() > 0) { segments.put(ImmutableList.copyOf(list), frames); } }
From source file:com.paulosalem.openfieldflow.domain.ParticleAgent.java
protected void updateContext(Iterable<Agent> all) { neighbors = Iterables.size(all); }
From source file:org.openscada.ca.ui.importer.wizard.ImportWizard.java
protected void applyDiff(final IProgressMonitor parentMonitor) throws InterruptedException, ExecutionException { final SubMonitor monitor = SubMonitor.convert(parentMonitor, 100); monitor.setTaskName(Messages.ImportWizard_TaskName); final Collection<DiffEntry> result = this.mergeController.merge(monitor.newChild(10)); if (result.isEmpty()) { monitor.done();/*w ww . j a v a2 s . com*/ return; } final Iterable<List<DiffEntry>> splitted = Iterables.partition(result, Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.P_DEFAULT_CHUNK_SIZE)); final SubMonitor sub = monitor.newChild(90); try { final int size = Iterables.size(splitted); sub.beginTask(Messages.ImportWizard_TaskName, size); int pos = 0; for (final Iterable<DiffEntry> i : splitted) { sub.subTask(String.format(Messages.ImportWizard_SubTaskName, pos, size)); final List<DiffEntry> entries = new LinkedList<DiffEntry>(); Iterables.addAll(entries, i); final NotifyFuture<Void> future = this.connection.getConnection().applyDiff(entries, null, new DisplayCallbackHandler(getShell(), "Apply diff", "Confirmation for applying diff is required")); future.get(); pos++; sub.worked(1); } } finally { sub.done(); } }
From source file:com.facebook.buck.features.apple.project.ProjectGeneratorTestUtils.java
public static <T extends PBXBuildPhase> T getSingletonPhaseByType(PBXTarget target, Class<T> cls) { Iterable<PBXBuildPhase> buildPhases = Iterables.filter(target.getBuildPhases(), cls::isInstance); assertEquals("Build phase should be singleton", 1, Iterables.size(buildPhases)); @SuppressWarnings("unchecked") T element = (T) Iterables.getOnlyElement(buildPhases); return element; }
From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.Implementations.CNodeDeleter.java
/** * Removes an instruction from a code node. * * @param parent Parent window used for dialogs. * @param graph The graph the node belongs to. * @param node Node to remove the instruction from. * @param instruction Instruction to remove. *//* w ww . java2s . co m*/ public static void deleteInstruction(final JFrame parent, final ZyGraph graph, final NaviNode node, final INaviInstruction instruction) { if (JOptionPane.YES_OPTION == CMessageBox.showYesNoCancelQuestion(parent, String.format("Do you really want to delete the instruction '%s' from the code node?", instruction.getInstructionString()))) { final INaviCodeNode rawNode = (INaviCodeNode) node.getRawNode(); // final Iterable<INaviInstruction> instructions = rawNode.getInstructions(); if (!rawNode.hasInstruction(instruction)) { CMessageBox.showError(parent, "The instruction is not part of the code node"); return; } if (Iterables.size(rawNode.getInstructions()) == 1) { connectParentsWithChildren(graph.getRawView(), node.getRawNode()); graph.deleteNodes(Lists.newArrayList(node)); } else { ((INaviCodeNode) node.getRawNode()).removeInstruction(instruction); } } }
From source file:org.wso2.carbon.uuf.api.auth.InMemorySessionManager.java
/** * {@inheritDoc} */ @Override public int getCount() { return Iterables.size(cache); }
From source file:org.apache.cassandra.service.RowDataResolver.java
static ColumnFamily resolveSuperset(Iterable<ColumnFamily> versions, long now) { assert Iterables.size(versions) > 0; ColumnFamily resolved = null;// w ww .j av a 2s . c om for (ColumnFamily cf : versions) { if (cf == null) continue; if (resolved == null) resolved = cf.cloneMeShallow(); else resolved.delete(cf); } if (resolved == null) return null; // mimic the collectCollatedColumn + removeDeleted path that getColumnFamily takes. // this will handle removing columns and subcolumns that are suppressed by a row or // supercolumn tombstone. QueryFilter filter = new QueryFilter(null, resolved.metadata().cfName, new IdentityQueryFilter(), now); List<CloseableIterator<Cell>> iters = new ArrayList<>(Iterables.size(versions)); for (ColumnFamily version : versions) if (version != null) iters.add(FBUtilities.closeableIterator(version.iterator())); filter.collateColumns(resolved, iters, Integer.MIN_VALUE); return ColumnFamilyStore.removeDeleted(resolved, Integer.MIN_VALUE); }
From source file:org.obiba.magma.type.LineStringType.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2s .com*/ public int compare(Value o1, Value o2) { if (o1.isNull() && o2.isNull()) return 0; if (o1.isNull()) return -1; if (o2.isNull()) return 1; Iterable<Coordinate> line1 = (Iterable<Coordinate>) o1.getValue(); Iterable<Coordinate> line2 = (Iterable<Coordinate>) o2.getValue(); if (Iterables.size(line1) == Iterables.size(line2)) { if (Iterables.elementsEqual(line1, line2)) return 0; return -1; } if (Iterables.size(line1) < Iterables.size(line2)) { return -1; } return 1; }
From source file:org.opendaylight.netconf.cli.writer.impl.NodeCliSerializerDispatcher.java
private static void checkOnlyOneSerializedElement(final Iterable<?> elements, final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> dataContainerChild) { final int size = Iterables.size(elements); Preconditions.checkArgument(size == 1, "Unexpected count of elements for entry serialized from: %s, should be 1, was: %s", dataContainerChild, size);//from w w w .ja v a2 s . c o m }