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.github.filosganga.geogson.model.GeometryCollection.java

@Override
public int size() {
    return Iterables.size(geometries);
}

From source file:edu.mit.streamjit.util.bytecode.insts.SwitchInst.java

public BasicBlock put(Constant<Integer> cst, BasicBlock bb) {
    BasicBlock oldVal = get(cst);// www  .  j a v a  2 s  .  c  o m
    int ci = Iterables.indexOf(operands(), Predicates.<Value>equalTo(cst));
    if (ci != -1)
        setOperand(ci + 1, bb);
    else {
        addOperand(Iterables.size(operands()), cst);
        addOperand(Iterables.size(operands()), bb);
    }
    return oldVal;
}

From source file:jflowmap.data.GraphMLReader2.java

public Iterable<Graph> readFromStream(InputStream is) throws IOException {
    try {/* w  ww . j av a2 s .  c o m*/
        XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance();
        XmlDocument doc = builder.parseReader(new InputStreamReader(is, DEFAULT_CHARSET));
        namespace = builder.newNamespace(NAMESPACE);

        dataParser = ParserFactory.getDefaultFactory();

        readKeys(doc.getDocumentElement());

        Iterable<Graph> graphs = readGraphs(doc.getDocumentElement());

        if (Iterables.size(graphs) == 0) {
            throw new IOException("No graphs found");
        }

        return graphs;
    } catch (IOException e) {
        throw e;
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}

From source file:uk.ac.ed.inf.ace.MainThread.java

@Override
public void run() {
    try {/*from   w w  w  . j av a2s  . c o  m*/
        RandomSource randomSource = new RandomSource(engine.getEnvironment().getRandomSeed());

        try (Database initialDatabase = engine.getEnvironment().getDatabase()) {
            initialDatabase.open(randomSource, rebuildDatabase, generateTestData);
        }

        if (databaseQueryMode) {
            return;
        }

        // Use a completion service to wait for all programmes to complete
        Iterable<Programme> programmes = engine.getProgrammes();
        int programmeCount = Iterables.size(programmes);

        if (programmeCount == 0) {
            LOGGER.warning("There are no valid programmes to run.");
        } else {
            CompletionService<Boolean> completionService = new ExecutorCompletionService<>(
                    engine.getThreadPool());
            int queuedTasks = 0;

            for (Programme programme : programmes) {
                completionService.submit(programme.getExecutable(randomSource, analysisOnly));
                queuedTasks++;
            }

            for (int index = 0; index < queuedTasks; index++) {
                completionService.take().get();
            }

            engine.getThreadPool().stop();
            LOGGER.info("All programmes completed");
        }
    } catch (StoppingException exception) {
        stopped();
    } catch (ExecutionException exception) {
        Throwable temp = exception;

        while (true) {
            if (temp == null) {
                break;
            }

            if (temp instanceof StoppingException) {
                stopped();
                return;
            }

            temp = temp.getCause();
        }

        exception(exception);
    } catch (Exception exception) {
        exception(exception);
    }
}

From source file:com.google.errorprone.bugpatterns.RedundantThrows.java

static String oxfordJoin(String on, Iterable<?> pieces) {
    StringBuilder result = new StringBuilder();
    int size = Iterables.size(pieces);
    if (size == 2) {
        return Joiner.on(" and ").join(pieces);
    }/*from ww  w  .  j a  va  2 s . com*/
    int idx = 0;
    for (Object piece : pieces) {
        if (idx > 0) {
            result.append(on);
            if (idx == size - 1) {
                result.append("and ");
            }
        }
        result.append(piece);
        idx++;
    }
    return result.toString();
}

From source file:org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier.java

@Override
public Set<? extends Location> get() {
    Builder<Location> locations = ImmutableSet.builder();
    Iterable<DataCenter> list = Iterables
            .filter(Iterables.transform(sync.getPricingPlanList(), new Function<PricingPlan, DataCenter>() {

                @Override/*  w w  w  . j  a va2  s  .c om*/
                public DataCenter apply(PricingPlan arg0) {
                    return arg0.getDataCenter();
                }

            }), Predicates.<DataCenter>notNull());
    Location provider = Iterables.getOnlyElement(super.get());
    if (Iterables.size(list) == 0)
        locations.add(provider);
    else
        for (DataCenter from : list) {
            LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId())
                    .description(from.getName()).parent(provider);
            if (isoCodesById.containsKey(from.getId()))
                builder.iso3166Codes(isoCodesById.get(from.getId()));
            locations.add(builder.build());
        }
    return locations.build();
}

From source file:todoapp.app.viewmodels.analysis.ToDoItemsByCategoryViewModel.java

private static int countIn(final Iterable<ToDoItem> items, final Subcategory subcategory) {
    return Iterables.size(Iterables.filter(items, ToDoItem.Predicates.thoseSubcategorised(subcategory)));
}

From source file:sf.net.experimaestro.manager.plans.OrderBy.java

public int size() {
    return operators == null ? Iterables.size(order.items()) : operators.size();
}

From source file:com.eucalyptus.autoscaling.common.AutoScalingResourceName.java

public static AutoScalingResourceName parse(final String resourceName, @Nullable final Type type)
        throws InvalidResourceNameException {
    if (!resourceName.startsWith(prefix)) {
        throw new InvalidResourceNameException(resourceName);
    }//w  w w. ja va  2 s  . c  o m

    final Iterable<String> nameParts = nameSpliter.split(resourceName);
    final int namePartCount = Iterables.size(nameParts);
    if (namePartCount < 8 || namePartCount > 9) {
        throw new InvalidResourceNameException(resourceName);
    }

    if (!"autoscaling".equals(Iterables.get(nameParts, PART_SERVICE))) {
        throw new InvalidResourceNameException(resourceName);
    }

    if (type != null && !type.name().equals(Iterables.get(nameParts, PART_RELATIVE_ID_TYPE))) {
        throw new InvalidResourceNameException(resourceName);
    }

    return new AutoScalingResourceName(resourceName, Iterables.get(nameParts, PART_SERVICE),
            Iterables.get(nameParts, PART_NAMESPACE), Iterables.get(nameParts, PART_RELATIVE_ID_TYPE),
            Iterables.get(nameParts, PART_RELATIVE_ID_UUID), Iterables.get(nameParts, PART_RELATIVE_NAME_1),
            namePartCount > PART_RELATIVE_NAME_2 ? Iterables.get(nameParts, PART_RELATIVE_NAME_2) : null);
}

From source file:org.eclipse.elk.tree.intermediate.LevelHeightProcessor.java

/**
 * Set the height property for each node in the current level and for their children. The height
 * is the height of the tallest node in the level.
 * /*from  ww  w.j  ava  2s . c o  m*/
 * @param currentLevel
 *            the list of TNode at the same level, for which the neighbors and siblings should
 *            be determined
 * @param progressMonitor
 *            the current progress monitor
 */
private void setNeighbors(final Iterable<TNode> currentLevel, final IElkProgressMonitor progressMonitor) {
    /** only do something in filled levels */
    if (!Iterables.isEmpty(currentLevel)) {
        /** create subtask for recursive descent */
        IElkProgressMonitor sT = progressMonitor.subTask(Iterables.size(currentLevel) / numberOfNodes);

        sT.begin("Set neighbors in level", 1f);

        /** build empty iterator */
        Iterable<TNode> nextLevel = new Iterable<TNode>() {

            public Iterator<TNode> iterator() {
                return Iterators.emptyIterator();
            }
        };

        double height = 0d;

        for (TNode cN : currentLevel) {
            /** append the children of the current node to the next level */
            nextLevel = Iterables.concat(nextLevel, cN.getChildren());
            /** check if the node is the tallest node so far */
            if (height < cN.getSize().y) {
                height = cN.getSize().y;
            }
        }
        for (TNode cN : currentLevel) {
            /** set the level height for the node */
            cN.setProperty(Properties.LEVELHEIGHT, height);
        }

        /** add amount of work units to the whole task */
        sT.done();

        /** determine neighbors by bfs and for the whole graph */
        setNeighbors(nextLevel, progressMonitor);
    }

}