Example usage for org.apache.commons.collections IteratorUtils toList

List of usage examples for org.apache.commons.collections IteratorUtils toList

Introduction

In this page you can find the example usage for org.apache.commons.collections IteratorUtils toList.

Prototype

public static List toList(Iterator iterator) 

Source Link

Document

Gets a list based on an iterator.

Usage

From source file:ec.edu.espe.distribuidas.factnosql.test.consultarProductos.java

public static void main(String[] args) {
    PersistenceManager persistence = new PersistenceManager();

    Iterator<PersonasSum> aggregate = persistence.context().createAggregation(Factura.class)
            .group("persona", Group.grouping("count", new Accumulator("$sum", 1)),
                    Group.grouping("cedula", Group.first("valor")),
                    Group.grouping("persona", Group.first("persona")))
            .aggregate(PersonasSum.class);
    List<PersonasSum> presonasS = IteratorUtils.toList(aggregate);
    for (PersonasSum p : presonasS)
        System.out.println(p);/*  w ww  . ja  v  a  2s  .  com*/

}

From source file:ec.edu.espe.distribuidas.factnosql.test.consultaTotalVentas.java

public static void main(String[] args) throws ParseException {
    PersistenceManager persistence = new PersistenceManager();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Query q = persistence.context().createQuery(Factura.class).field("fechaEmision")
            .equal(sdf.parse("2016-01-27"));
    Iterator<VentasDiarias> aggregate = persistence.context().createAggregation(Factura.class)
            .group("fechaEmision", Group.grouping("total", Group.sum("total")),
                    Group.grouping("count", new Accumulator("$sum", 1)),
                    Group.grouping("fechaEmision", Group.first("fechaEmision")))
            .aggregate(VentasDiarias.class);
    List<VentasDiarias> totalVentas = IteratorUtils.toList(aggregate);
    for (VentasDiarias p : totalVentas)
        System.out.println(p);/* w w w  .j a  va  2 s .  co m*/

}

From source file:ec.edu.espe.distribuidas.factnosql.test.consultaPersonas.java

public static void main(String[] args) throws ParseException {
    PersistenceManager persistence = new PersistenceManager();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Query q = persistence.context().createQuery(Factura.class).field("fechaEmision")
            .equal(sdf.parse("2016-01-27"));
    Iterator<ProductoSum> aggregate = persistence.context().createAggregation(Factura.class).match(q)
            .unwind("detalle")
            .group("detalle.producto", Group.grouping("count", Group.sum("detalle.cantidad")),
                    Group.grouping("fecha", Group.first("fechaEmision")),
                    Group.grouping("codigo", Group.first("detalle.codigo")))
            .aggregate(ProductoSum.class);
    List<ProductoSum> presonasS = IteratorUtils.toList(aggregate);
    for (ProductoSum p : presonasS)
        System.out.println(p);/*w ww  .  jav a 2 s.co  m*/

}

From source file:de.qaware.chronix.spark.api.java.ExternalizeTestData.java

/**
 * @param args optional first argument: file to serialize to. A default file name is provided.
 * @throws SolrServerException/*  ww  w  . j  a va  2 s .c om*/
 * @throws FileNotFoundException
 */
public static void main(String[] args) throws SolrServerException, IOException {

    ChronixSparkLoader chronixSparkLoader = new ChronixSparkLoader();
    ChronixYAMLConfiguration config = chronixSparkLoader.getConfig();

    String file = (args.length >= 1) ? args[0] : config.getTestdataFile();

    Path filePath = Paths.get(file);
    Files.deleteIfExists(filePath);
    Output output = new Output(new DeflaterOutputStream(new FileOutputStream(filePath.toString())));
    System.out.println("Opening test data file: " + filePath.toString());

    ChronixSparkContext cSparkContext = null;

    //Create target file
    try {
        //Create Chronix Spark context
        cSparkContext = chronixSparkLoader.createChronixSparkContext();

        //Read data into ChronixRDD
        SolrQuery query = new SolrQuery(config.getSolrReferenceQuery());
        ChronixRDD rdd = cSparkContext.queryChronixChunks(query, config.getZookeeperHost(),
                config.getChronixCollection(), config.getStorage());

        System.out.println("Writing " + rdd.count() + " time series into test data file.");

        //Loop through result and serialize it to disk
        Kryo kryo = new Kryo();
        List<MetricTimeSeries> mtsList = IteratorUtils.toList(rdd.iterator());
        System.out.println("Writing objects...");
        kryo.writeObject(output, mtsList);
        output.flush();
        System.out.println("Objects written.");
    } finally {
        output.close();
        if (cSparkContext != null) {
            cSparkContext.getSparkContext().close();
        }
        System.out.println("Test data file written successfully!");
    }
}

From source file:com.amalto.core.storage.CachedResults.java

public static StorageResults from(StorageResults otherResults) {
    return new CachedResults(IteratorUtils.toList(otherResults.iterator()));
}

From source file:com.syncleus.tinkermapdb.ExampleTest.java

@Test
public void testMapDBGraph() throws IOException {

    MapGraph m = new MapGraph();
    m.addEdge(null, m.addVertex("x"), m.addVertex("y"), "xy");
    assertEquals(2, IteratorUtils.toList(m.getVertices().iterator()).size());
    assertEquals(1, IteratorUtils.toList(m.getEdges().iterator()).size());

}

From source file:com.br.helpdesk.service.BaseService.java

public List<T> findAll() {
    return IteratorUtils.toList(getRepository().findAll().iterator());
}

From source file:br.ifes.poo2.chess.cln.cdp.players.factories.PlayerComputer.java

public String play(Color color, Game game) {
    Iterator<Piece> iterator = game.getPiecesOfPlayer(color);
    List<Piece> listOfPieces = IteratorUtils.toList(iterator);
    List<Position> positions;
    int rand;/*from w  w w .j av a 2 s. c  o  m*/
    Piece piece;

    Position positionAux;
    int count = 0;
    while (count < 50) {
        if (listOfPieces.size() > 0) {
            rand = (int) (Math.random() * (listOfPieces.size() - 1));
            piece = listOfPieces.get(rand);

            positions = piece.getPath(game.getChessBoard(), piece.getPosition());

            if (positions.size() > 0) {
                rand = (int) (Math.random() * (positions.size() - 1));
                positionAux = positions.get(rand);

                return "" + piece.getPosition().getColumn() + piece.getPosition().getLine()
                        + positionAux.getColumn() + positionAux.getLine();
            }

        }
        count++;
    }
    return "desistir";
}

From source file:com.br.helpdesk.controller.ClientController.java

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody List<Client> getAllClients() {
    return IteratorUtils.toList(clientRepository.findAll().iterator());
}

From source file:net.cpollet.jixture.fixtures.TestCleaningFixture.java

@Test
public void getClassesToDeleteReturnsClassListWithoutDuplicates() {
    // GIVEN//from  w  w  w .  j a v  a  2s. com
    CleaningFixture fixture = new CleaningFixture(String.class, Integer.class, String.class);

    // WHEN + THEN
    List classesToDelete = IteratorUtils.toList(fixture.getClassesToDeleteIterator());
    assertThat(classesToDelete) //
            .hasSize(2) //
            .containsExactly(String.class, Integer.class);
}