List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.apache.metron.writer.BulkWriterComponent.java
public void commit(Iterable<Tuple> tuples) { tuples.forEach(t -> collector.ack(t)); if (LOG.isDebugEnabled()) { LOG.debug("Acking " + Iterables.size(tuples) + " tuples"); }/*from w w w .j a va 2s . com*/ }
From source file:org.trancecode.xproc.step.TemplateStepProcessor.java
@Override protected void execute(final StepInput input, final StepOutput output) { LOG.trace("start of step"); assert input != null; assert output != null; final XdmNode templateNode = input.readNode(XProcPorts.TEMPLATE); final Iterable<XdmNode> sourceNodeList = input.readNodes(XProcPorts.SOURCE); final int sourcesCount = Iterables.size(sourceNodeList); final XdmNode sourceNode; assert templateNode != null; assert sourceNodeList != null; if (sourcesCount == 1) { sourceNode = Iterables.getOnlyElement(sourceNodeList); } else if (sourcesCount > 1) { throw XProcExceptions.xc0068(input.getLocation()); } else {/*from w w w.j av a2s . co m*/ sourceNode = null; } final Map<QName, String> parameters = input.getParameters(XProcPorts.PARAMETERS); final Processor processor = input.getPipelineContext().getProcessor(); final SaxonBuilder builder = new SaxonBuilder(processor.getUnderlyingConfiguration()); builder.startDocument(); processNode(templateNode, sourceNode, input, builder, processor, parameters); builder.endDocument(); final XdmNode resultNode = builder.getNode(); output.writeNodes(XProcPorts.RESULT, resultNode); LOG.trace("built result:\n{}", resultNode); LOG.trace("end of step"); }
From source file:com.ibm.common.geojson.FeatureCollection.java
public int size() { return Iterables.size(features()); }
From source file:reader.CollectionUtils.java
public static <T extends Number> double average(final Iterable<T> values) { final double sum = sumUp(values); final int size = Iterables.size(values); return sum / size; }
From source file:com.stratio.decision.functions.SaveToCassandraActionExecutionFunction.java
@Override public void process(Iterable<StratioStreamingMessage> messages) throws Exception { Integer partitionSize = maxBatchSize; if (partitionSize <= 0) { partitionSize = Iterables.size(messages); }/*from w w w . j a va2 s. c o m*/ Iterable<List<StratioStreamingMessage>> partitionIterables = Iterables.partition(messages, partitionSize); try { for (List<StratioStreamingMessage> messageList : partitionIterables) { BatchStatement batch = new BatchStatement(batchType); for (StratioStreamingMessage stratioStreamingMessage : messageList) { Set<String> columns = getColumnSet(stratioStreamingMessage.getColumns()); if (tablenames.get(stratioStreamingMessage.getStreamName()) == null) { getCassandraTableOperationsService().createTable(stratioStreamingMessage.getStreamName(), stratioStreamingMessage.getColumns(), TIMESTAMP_FIELD); refreshTablenames(); } if (tablenames.get(stratioStreamingMessage.getStreamName()) != columns.hashCode()) { getCassandraTableOperationsService().alterTable(stratioStreamingMessage.getStreamName(), columns, stratioStreamingMessage.getColumns()); refreshTablenames(); } batch.add(getCassandraTableOperationsService().createInsertStatement( stratioStreamingMessage.getStreamName(), stratioStreamingMessage.getColumns(), TIMESTAMP_FIELD)); } getSession().execute(batch); } } catch (Exception e) { log.error("Error in Cassandra for batch size {}: {}", Iterables.size(partitionIterables), e.getMessage()); } }
From source file:com.google.cloud.dataflow.sdk.runners.worker.DataflowExecutionContext.java
/** * Returns a {@link SideInputReader} based on {@link SideInputInfo} descriptors * and {@link PCollectionView PCollectionViews}. * * <p>If side input source metadata is provided by the service in * {@link SideInputInfo sideInputInfos}, we request * a {@link SideInputReader} from the {@code executionContext} using that info. * If no side input source metadata is provided but the DoFn expects side inputs, as a * fallback, we request a {@link SideInputReader} based only on the expected views. * * <p>These cases are not disjoint: Whenever a {@link DoFn} takes side inputs, * {@code doFnInfo.getSideInputViews()} should be non-empty. * * <p>A note on the behavior of the Dataflow service: Today, the first case corresponds to * batch mode, while the fallback corresponds to streaming mode. *//* ww w.j a v a 2s . co m*/ public SideInputReader getSideInputReader(@Nullable Iterable<? extends SideInputInfo> sideInputInfos, @Nullable Iterable<? extends PCollectionView<?>> views) throws Exception { if (sideInputInfos != null && sideInputInfos.iterator().hasNext()) { return getSideInputReader(sideInputInfos); } else if (views != null && Iterables.size(views) > 0) { return getSideInputReaderForViews(views); } else { return NullSideInputReader.empty(); } }
From source file:springfox.documentation.spring.web.ObjectMapperConfigurer.java
private List<HttpMessageConverter<?>> configureMessageConverters(List<HttpMessageConverter<?>> converters) { Iterable<MappingJackson2HttpMessageConverter> jackson2Converters = jackson2Converters(converters); if (Iterables.size(jackson2Converters) > 0) { for (MappingJackson2HttpMessageConverter each : jackson2Converters) { fireObjectMapperConfiguredEvent(each.getObjectMapper()); }//from w w w. j a va2s .c om } else { converters.add(configuredMessageConverter()); } return newArrayList(converters); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.refresh.SequenceRefreshExtension.java
/** * {@inheritDoc}//from w w w . jav a2 s.c om */ public void beforeRefresh(DDiagram dDiagram) { if (dDiagram instanceof SequenceDDiagram) { currentDiagram = (SequenceDDiagram) dDiagram; Collection<DDiagramElement> nodeEvents = getEventsToSync(currentDiagram); if (nodeEvents.size() != 0) { flags = Maps.newHashMapWithExpectedSize(nodeEvents.size()); for (DDiagramElement elt : nodeEvents) { Iterable<AbsoluteBoundsFilter> flag = Iterables.filter(elt.getGraphicalFilters(), AbsoluteBoundsFilter.class); EObject semanticTarget = elt.getTarget(); if (semanticTarget != null && Iterables.size(flag) == 1) { flags.put(semanticTarget, Iterables.getOnlyElement(flag)); } } } } }
From source file:ucigame.example.Gof2.java
@Override public void draw() { canvas.clear();//from ww w . j a v a 2 s . c o m for (Pair<Integer, Integer> p : FluentIterable.from(world.getTileByRect(topLeft, bottomRight)) .transform(Gof.onlyCoord)) { mapSprite.get("greenBlock1").makeSprite(p.getValue0(), p.getValue1()).draw(); } for (Pair<Integer, Integer> p : click) { mapSprite.get("blueBlock1").makeSprite(p.getValue0(), p.getValue1()).draw(); } console.addMessage("size:" + Iterables.size(world.getTileLst())); console.draw(0, 8, 3); if (!pause) { world = world.crunch(event); } }
From source file:com.medvision360.medrecord.spi.tck.LocatableStoreTCKTestBase.java
public void testBasicCRUD() throws Exception { HierObjectID uid = new HierObjectID(makeUUID()); Locatable orig = makeLocatable(uid); assertFalse(store.has(uid));/*from www. j a v a 2 s . c om*/ Iterable<HierObjectID> hierObjectIDs = store.list(); assertEquals(0, Iterables.size(hierObjectIDs)); Locatable inserted = store.insert(orig); assertEqualish(orig, inserted); try { store.insert(orig); fail("Should not allow inserting the same locatable twice"); } catch (DuplicateException e) { } assertTrue(store.has(uid)); hierObjectIDs = store.list(); assertEquals(1, Iterables.size(hierObjectIDs)); Locatable retrieved = store.get(uid); assertEqualish(orig, retrieved); Locatable modify = makeLocatable(uid); modify.set("/name/value", "modified name"); Locatable modified = store.update(modify); assertEqualish(modify, modified); Locatable modifiedThenRetrieved = store.get(uid); assertEqualish(modify, modifiedThenRetrieved); hierObjectIDs = store.list(); assertEquals(1, Iterables.size(hierObjectIDs)); try { HierObjectID otherUid = new HierObjectID(makeUUID()); Locatable other = makeLocatable(otherUid); store.update(other); fail("Should not allow updating non-existent locatable"); } catch (NotFoundException e) { } assertTrue(store.has(uid)); store.delete(uid); assertFalse(store.has(uid)); hierObjectIDs = store.list(); assertEquals(0, Iterables.size(hierObjectIDs)); // how many versions to expect here is probably a bit implementation-dependent... }