List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:com.openlattice.mail.services.MailRenderer.java
protected Set<Email> renderEmail(RenderableEmailRequest emailRequest) { Iterable<String> toAddresses = Iterables.filter(Arrays.asList(emailRequest.getTo()), (String address) -> isNotBlacklisted(address)); logger.info("filtered e-mail addresses that are blacklisted."); if (Iterables.size(toAddresses) < 1) { logger.error("Must include at least one valid e-mail address."); return ImmutableSet.of(); }/*from ww w . j a va2 s.co m*/ String template; try { template = TemplateUtils.loadTemplate(emailRequest.getTemplatePath()); } catch (IOException e) { throw new InvalidTemplateException("Invalid Email Template: " + emailRequest.getTemplatePath(), e); } String templateHtml = TemplateUtils.DEFAULT_TEMPLATE_COMPILER.compile(template) .execute(emailRequest.getTemplateObjs().or(new Object())); /* * when someone invites multiple people, we want to spool an individual invite for each person. as such, we need * to create a multiple Email objects instead of one Email object with multiple "To" fields to avoid having * multiple emails appear in the "To" field in an email client like Gmail. */ Set<Email> emailSet = Sets.newHashSet(); for (String toAddress : toAddresses) { Email email = Email.create().from(emailRequest.getFrom().or(EmailTemplate.getCourierEmailAddress())) .to(toAddress).subject(emailRequest.getSubject().or("")).addHtml(templateHtml); if (emailRequest.getByteArrayAttachment().isPresent()) { ByteArrayAttachment[] attachments = emailRequest.getByteArrayAttachment().get(); for (int i = 0; i < attachments.length; i++) { email.attach(attachments[i]); } } if (emailRequest.getAttachmentPaths().isPresent()) { String[] paths = emailRequest.getAttachmentPaths().get(); for (int i = 0; i < paths.length; i++) { email.attach(EmailAttachment.attachment().file(paths[i])); } } emailSet.add(email); } return emailSet; }
From source file:io.github.hsyyid.essentialcmds.cmdexecutors.GCExecutor.java
@Override public void executeAsync(CommandSource src, CommandContext ctx) { double tps = Sponge.getServer().getTicksPerSecond(); src.sendMessage(Text.of(TextColors.GOLD, "Current TPS: ", TextColors.GRAY, tps)); src.sendMessage(Text.of(TextColors.GOLD, "World Info:")); for (World world : Sponge.getServer().getWorlds()) { int numOfEntities = world.getEntities().size(); int loadedChunks = Iterables.size(world.getLoadedChunks()); src.sendMessage(Text.of()); src.sendMessage(Text.of(TextColors.GREEN, "World: ", world.getName())); src.sendMessage(Text.of(TextColors.GOLD, "Entities: ", TextColors.GRAY, numOfEntities)); src.sendMessage(Text.of(TextColors.GOLD, "Loaded Chunks: ", TextColors.GRAY, loadedChunks)); }//from ww w .j a v a 2 s. c om }
From source file:eu.trentorise.opendata.semantics.exceptions.OpenEntityNotFoundException.java
private static String makeMessage(String msg, Iterable<String> expectedIds, Iterable<String> foundIds) { if (expectedIds == null) { LOG.warning("FOUND NULL EXPECTED IDS, IGNORING THEM!"); return msg; }/*from www . j a v a2 s . c o m*/ if (foundIds == null) { LOG.warning("FOUND NULL FOUND IDS, IGNORING THEM!"); return msg; } String postfix = Iterables.size(expectedIds) > Iterables.size(foundIds) ? " EXPECTED " + Iterables.size(expectedIds) + " RESULTS, BUT FOUND ONLY " + Iterables.size(foundIds) + ". Following ids were not found: " + missingIds(expectedIds, foundIds).toString() : ""; return msg + postfix; }
From source file:com.netxforge.netxstudio.common.model.ComputationContextProvider.java
/** * Get the {@link DateTimeRange period} setting from the computation * context./* w ww .j ava2 s .co m*/ * * @return the period or <code>null</code> if none specified. */ public DateTimeRange periodInContext() { final Iterable<IComputationContext> filter = Iterables.filter(context, new Predicate<IComputationContext>() { public boolean apply(IComputationContext o) { return o.getContext() instanceof DateTimeRange; } }); if (Iterables.size(filter) == 1) { return (DateTimeRange) ((IComputationContext) filter.iterator().next()).getContext(); } return null; }
From source file:com.mycila.guice.ext.injection.Perf.java
private static void perfTestMembers() throws Exception { List<Class<?>> classes = new LinkedList<Class<?>>(); JarFile jarFile = new JarFile(new File("C:\\Program Files\\Java\\jdk1.7.0_15\\jre\\lib\\rt.jar")); Enumeration<JarEntry> enums = jarFile.entries(); while (enums.hasMoreElements()) { JarEntry entry = enums.nextElement(); if (entry.getName().endsWith(".class")) { if (entry.getName().startsWith("javax/swing") || entry.getName().startsWith("java/awt") || entry.getName().startsWith("java/awt")) classes.add(Class .forName(entry.getName().replace('/', '.').substring(0, entry.getName().length() - 6))); }// w w w.j ava 2 s .c o m } System.out.println("classes: " + classes.size()); // start visual VM Thread.sleep(10000); for (int i = 0; i < 100; i++) { System.out.println(Runtime.getRuntime().freeMemory()); long time = System.nanoTime(); for (Class<?> c : classes) { Iterables.size(Reflect.findAllAnnotatedMethods(c, Deprecated.class)); } long end = System.nanoTime(); System.out.println((end - time) + "ns = " + ((end - time) / 1000000) + "ms"); } }
From source file:org.dishevelled.bio.range.entrytree.CenteredRangeTree.java
/** * Create a new centered range tree with the specified range entries. * * @param entries range entries, must not be null *//* w ww . ja v a 2 s . co m*/ private CenteredRangeTree(final Iterable<Entry<C, V>> entries) { checkNotNull(entries); size = Iterables.size(entries); root = createNode(entries); }
From source file:co.cask.cdap.common.namespace.InMemoryNamespaceClient.java
@Override public NamespaceMeta get(final Id.Namespace namespaceId) throws Exception { Iterable<NamespaceMeta> filtered = Iterables.filter(namespaces, new Predicate<NamespaceMeta>() { @Override//from w w w. j a v a 2 s. c o m public boolean apply(NamespaceMeta input) { return input.getName().equals(namespaceId.getId()); } }); if (Iterables.size(filtered) == 0) { throw new NamespaceNotFoundException(namespaceId); } return filtered.iterator().next(); }
From source file:com.medvision360.medrecord.spi.base.BaseValidationReport.java
@Override public String toString() { StringBuilder str = new StringBuilder(); str.append("ValidationReport:"); str.append(isValid() ? "valid" : "invalid"); int total = m_list.size(); Iterable<ValidationResult> errors = getErrors(); int inValid = Iterables.size(errors); str.append(",total=").append(total); str.append(",valid=").append(total - inValid); str.append(",invalid=").append(inValid); str.append(",\n"); for (ValidationResult result : errors) { str.append(" "); str.append(result);//from w w w . j a v a2s . c om str.append(",\n"); } return str.toString(); }
From source file:eu.interedition.collatex.dekker.PhraseMatchDetector.java
public List<List<Match>> detect(Map<Token, VariantGraphVertex> linkedTokens, VariantGraph base, Iterable<Token> tokens) { List<List<Match>> phraseMatches = Lists.newArrayList(); List<VariantGraphVertex> basePhrase = Lists.newArrayList(); List<Token> witnessPhrase = Lists.newArrayList(); VariantGraphVertex previous = base.getStart(); for (Token token : tokens) { if (!linkedTokens.containsKey(token)) { continue; }/*from w ww .j a v a 2s .c o m*/ VariantGraphVertex baseVertex = linkedTokens.get(token); // requirements: // - there should be a directed edge between previous and base vertex // - there may not be a longer path between previous and base vertex boolean directedEdge = directedEdgeBetween(previous, baseVertex); boolean isNear = directedEdge && (Iterables.size(previous.outgoing()) == 1 || Iterables.size(baseVertex.incoming()) == 1); if (!isNear) { if (!basePhrase.isEmpty()) { phraseMatches.add(Match.createPhraseMatch(basePhrase, witnessPhrase)); basePhrase.clear(); witnessPhrase.clear(); } } basePhrase.add(baseVertex); witnessPhrase.add(token); previous = baseVertex; } if (!basePhrase.isEmpty()) { phraseMatches.add(Match.createPhraseMatch(basePhrase, witnessPhrase)); } return phraseMatches; }
From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor.java
/** * @param version openflow version//www . j av a 2 s .com * @param inputPacket input packet * @param datapathid datapath id * @param xid tx id * @return PacketOutInput required by OF Library */ public static PacketOutInput toPacketOutInput(final TransmitPacketInput inputPacket, final short version, final Long xid, final BigInteger datapathid) { LOG.trace("toPacketOutInput for datapathId:{}, xid:{}", datapathid, xid); // Build Port ID from TransmitPacketInput.Ingress PortNumber inPortNr = null; Long bufferId = OFConstants.OFP_NO_BUFFER; Iterable<PathArgument> inArgs = null; PacketOutInputBuilder builder = new PacketOutInputBuilder(); if (inputPacket.getIngress() != null) { inArgs = inputPacket.getIngress().getValue().getPathArguments(); } if (inArgs != null && Iterables.size(inArgs) >= 3) { inPortNr = getPortNumber(Iterables.get(inArgs, 2), version); } else { // The packetOut originated from the controller inPortNr = new PortNumber(0xfffffffdL); } // Build Buffer ID to be NO_OFP_NO_BUFFER if (inputPacket.getBufferId() != null) { bufferId = inputPacket.getBufferId(); } PortNumber outPort = null; NodeConnectorRef outRef = inputPacket.getEgress(); Iterable<PathArgument> outArgs = outRef.getValue().getPathArguments(); if (Iterables.size(outArgs) >= 3) { outPort = getPortNumber(Iterables.get(outArgs, 2), version); } else { // TODO : P4 search for some normal exception new Exception("PORT NR not exist in Egress"); } List<Action> actions = null; List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> inputActions = inputPacket .getAction(); if (inputActions != null) { actions = ActionConvertor.getActions(inputActions, version, datapathid, null); } else { actions = new ArrayList<>(); // TODO VD P! wait for way to move Actions (e.g. augmentation) ActionBuilder aBuild = new ActionBuilder(); OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder(); OutputActionBuilder outputActionBuilder = new OutputActionBuilder(); outputActionBuilder.setPort(outPort); outputActionBuilder.setMaxLength(OFConstants.OFPCML_NO_BUFFER); outputActionCaseBuilder.setOutputAction(outputActionBuilder.build()); aBuild.setActionChoice(outputActionCaseBuilder.build()); actions.add(aBuild.build()); } builder.setAction(actions); builder.setData(inputPacket.getPayload()); builder.setVersion(version); builder.setXid(xid); builder.setInPort(inPortNr); builder.setBufferId(bufferId); // -------------------------------------------------------- return builder.build(); }