List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:net.sourceforge.cilib.util.selection.recipes.TournamentSelector.java
/** * {@inheritDoc}//from w w w .j av a2 s . c o m */ @Override public PartialSelection<E> on(Iterable<E> iterable) { int size = Iterables.size(iterable); int tournamentSize = Double.valueOf(this.tournamentProportion.getParameter() * size).intValue(); List<E> intermediate = Selection.copyOf(iterable).orderBy(new RandomArrangement(random)) .select(Samples.last(tournamentSize)); return Selection.copyOf(intermediate).orderBy(new SortedArrangement()).orderBy(new ReverseArrangement()); }
From source file:org.opendaylight.controller.sal.schema.service.impl.GlobalBundleScanningSchemaServiceImpl.java
public void start() { checkState(context != null);// w w w.j a va 2 s . c o m LOG.debug("start() starting"); listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class, GlobalBundleScanningSchemaServiceImpl.this); bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, scanner); synchronized (lock) { bundleTracker.open(); LOG.debug("BundleTracker.open() complete"); boolean hasExistingListeners = Iterables.size(listeners.getListeners()) > 0; if (hasExistingListeners) { tryToUpdateSchemaContext(); } } listenerTracker.open(); starting = false; LOG.debug("start() complete"); }
From source file:com.gnapse.common.inflector.Inflectors.java
/** * Inflects all words in the given list, using the specified {@code Inflector}. * * @param inflector the inflector to use to inflect words * @param words the list of words to inflect * @return a new list containing the resulting inflected words */// www. ja v a2 s.com public static List<String> inflectAll(Inflector inflector, Iterable<String> words) { final List<String> result = Lists.newArrayListWithCapacity(Iterables.size(words)); for (String word : words) { result.add(inflector.apply(word)); } return result; }
From source file:com.caiyunworks.crm.business.service.impl.HolidayServiceImpl.java
@Override public int update(Holiday record) throws UnsupportedOperationException, RecordNotExistException, OutOfDateRecordException, RecordAlreadyExistException { Holiday holiday = holidayRepository.findById(record.getId()); if (null == holiday) { if (logger.isWarnEnabled()) { logger.warn("try to update holiday {}, but it does not exist in DB.", record.getId()); }/*from w w w .ja va2s . c o m*/ throw new RecordNotExistException(); } else { if (!holiday.getVersionNumber().equals(record.getVersionNumber())) { if (logger.isWarnEnabled()) { logger.warn("holiday record is out of date, version {}, latest version {}", record.getVersionNumber(), holiday.getVersionNumber()); } throw new OutOfDateRecordException(); } Iterable<Holiday> holidays = holidayRepository.findByNameOrDateRange(record.getName(), record.getStartDate(), record.getEndDate()); if (null == holidays || Iterables.isEmpty(holidays)) { return holidayRepository.update(record); } else { if (Iterables.size(holidays) == 1 && Iterables.get(holidays, 0).getId() == record.getId()) { return holidayRepository.update(record); } else { if (logger.isWarnEnabled()) { logger.warn("try to update holiday {}, but it is already exist in DB.", record); } throw new RecordAlreadyExistException(); } } } }
From source file:org.apache.giraph.comm.messages.SequentialFileMessageStore.java
@Override public void addMessages(MessageStore<I, M> messageStore) throws IOException { // Writes messages to its file if (file.exists()) { if (LOG.isDebugEnabled()) { LOG.debug("addMessages: Deleting " + file); }/*from w ww. jav a2 s .c om*/ file.delete(); } file.createNewFile(); if (LOG.isDebugEnabled()) { LOG.debug("addMessages: Creating " + file); } DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), bufferSize)); int destinationVertexIdCount = Iterables.size(messageStore.getDestinationVertices()); out.writeInt(destinationVertexIdCount); // Since the message store messages might not be sorted, sort them if // necessary SortedSet<I> sortedSet; if (messageStore.getDestinationVertices() instanceof SortedSet) { sortedSet = (SortedSet<I>) messageStore.getDestinationVertices(); } else { sortedSet = Sets.newTreeSet(messageStore.getDestinationVertices()); for (I destinationVertexId : messageStore.getDestinationVertices()) { sortedSet.add(destinationVertexId); } } // Dump the vertices and their messages in a sorted order for (I destinationVertexId : sortedSet) { destinationVertexId.write(out); Iterable<M> messages = messageStore.getVertexMessages(destinationVertexId); int messageCount = Iterables.size(messages); out.writeInt(messageCount); if (LOG.isDebugEnabled()) { LOG.debug("addMessages: For vertex id " + destinationVertexId + ", messages = " + messageCount + " to file " + file); } for (M message : messages) { if (LOG.isDebugEnabled()) { LOG.debug("addMessages: Wrote " + message + " to " + file); } message.write(out); } } } finally { if (out != null) { out.close(); } } }
From source file:org.jclouds.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy.java
@Override public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes) { Reservation<? extends RunningInstance> reservation = createKeyPairAndSecurityGroupsAsNeededThenRunInstances( tag, count, template);/*from w w w. j a v a2 s. co m*/ Iterable<String> ids = transform(reservation, instanceToId); String idsString = Joiner.on(',').join(ids); if (Iterables.size(ids) > 0) { logger.debug("<< started instances(%s)", idsString); all(reservation, instancePresent); logger.debug("<< present instances(%s)", idsString); populateCredentials(reservation); } return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(), transform(reservation, runningInstanceToNodeMetadata), goodNodes, badNodes); }
From source file:org.trancecode.xproc.step.ValidateWithSchemaStepProcessor.java
@Override protected void execute(final StepInput input, final StepOutput output) { final XdmNode sourceDoc = input.readNode(XProcPorts.SOURCE); final boolean useLocalHints = Boolean .parseBoolean(input.getOptionValue(XProcOptions.USE_LOCATION_HINTS, "false")); final boolean tryNamespaces = Boolean .parseBoolean(input.getOptionValue(XProcOptions.TRY_NAMESPACES, "false")); final boolean assertValid = Boolean.parseBoolean(input.getOptionValue(XProcOptions.ASSERT_VALID, "true")); final String mode = input.getOptionValue(XProcOptions.MODE, "strict"); final Iterable<XdmNode> shemas = input.readNodes(XProcPorts.SCHEMA); XdmNode resultNode = sourceDoc;//from w ww. jav a 2s. c o m boolean valid = false; try { final Processor processor = input.getPipelineContext().getProcessor(); final StringReader reader = new StringReader(getXmlDocument(sourceDoc, processor)); final InputSource source = new InputSource(reader); source.setSystemId(sourceDoc.getBaseURI().toASCIIString()); final BuildingContentHandler handler = input.getPipelineContext().getProcessor().newDocumentBuilder() .newBuildingContentHandler(); final SAXResult result = new SAXResult(handler); final SAXSource saxSource = new SAXSource(source); final XMLReader xmlReader = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME); saxSource.setXMLReader(xmlReader); final InputSource sourceSchema = new InputSource(); if (Iterables.size(shemas) > 0) { final XdmNode schema = shemas.iterator().next(); final StringReader stringSchema = new StringReader(getXmlDocument(schema, processor)); sourceSchema.setCharacterStream(stringSchema); sourceSchema.setSystemId(schema.getBaseURI().toASCIIString()); } else { sourceSchema.setCharacterStream(new StringReader("")); } final SAXSource saxSchema = new SAXSource(sourceSchema); valid = validate(saxSource, saxSchema, result, useLocalHints, tryNamespaces); if (valid) { resultNode = handler.getDocumentNode(); } } catch (Exception e) { valid = false; } if (assertValid && !valid) { throw XProcExceptions.xc0053(input.getLocation()); } output.writeNodes(XProcPorts.RESULT, resultNode); }
From source file:org.gradle.model.internal.registry.ModelElementNode.java
@Override public int getLinkCount(Predicate<? super MutableModelNode> predicate) { return Iterables.size(Iterables.filter(links.values(), predicate)); }
From source file:org.apache.druid.indexing.common.task.MergeTaskBase.java
protected void verifyInputSegments(List<DataSegment> segments) { // Verify segments are all unsharded Preconditions.checkArgument(Iterables.size(Iterables.filter(segments, new Predicate<DataSegment>() { @Override// ww w . j a v a 2 s . c o m public boolean apply(@Nullable DataSegment segment) { return segment == null || !(segment.getShardSpec() instanceof NoneShardSpec); } })) == 0, "segments without NoneShardSpec"); }
From source file:edu.mit.streamjit.util.bytecode.insts.CallInst.java
@Override public CallInst clone(Function<Value, Value> operandMap) { Value[] arguments = new Value[Iterables.size(arguments())]; for (int i = 0; i < arguments.length; ++i) arguments[i] = operandMap.apply(getArgument(i)); Method newMethod = (Method) operandMap.apply(getMethod()); MethodType newMethodType = newMethod.isSignaturePolymorphic() ? methodType : newMethod.getType(); return new CallInst(newMethod, newMethodType, arguments); }