List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.jboss.as.console.client.administration.accesscontrol.ui.MemberColumn.java
@SuppressWarnings({ "unchecked", "Convert2MethodRef" }) public MemberColumn(final AccessControlStore accessControlStore, final Dispatcher circuit, final AccessControlFinder presenter, final ColumnManager columnManager, final Supplier<Role> selectedRole, final Supplier<Boolean> include, final String token) { super(FinderId.ACCESS_CONTROL, Console.CONSTANTS.member(), new Display<Assignment>() { @Override// w w w.j a va2s. co m public boolean isFolder(final Assignment data) { return false; } @Override public SafeHtml render(final String baseCss, final Assignment data) { return Templates.memberItem(baseCss, data.getPrincipal()); } @Override public String rowCss(final Assignment data) { return ""; } }, new ProvidesKey<Assignment>() { @Override public Object getKey(final Assignment item) { return item.getId(); } }, token); setShowSize(true); setPreviewFactory((data, callback) -> callback.onSuccess(Templates.memberPreview(data, Iterables.size(accessControlStore.getAssignments(data.getPrincipal(), include.get()))))); setTopMenuItems(new MenuDelegate<>(Console.CONSTANTS.common_label_add(), item -> presenter.launchAddMemberDialog(selectedRole.get(), include.get()), MenuDelegate.Role.Operation)); setMenuItems(new MenuDelegate<>(Console.CONSTANTS.common_label_delete(), item -> Feedback.confirm(Console.CONSTANTS.common_label_areYouSure(), Console.MESSAGES.deleteTitle(item.getPrincipal().getName()), isConfirmed -> { if (isConfirmed) { circuit.dispatch(new RemoveAssignment(item, ROLE_TO_PRINCIPAL)); } }), MenuDelegate.Role.Operation)); addSelectionChangeHandler(event -> { columnManager.reduceColumnsTo(4); if (hasSelectedItem()) { columnManager.updateActiveSelection(asWidget()); } }); }
From source file:org.killbill.billing.plugin.analytics.dao.factory.BusinessAccountFactory.java
public BusinessAccountModelDao createBusinessAccount(final BusinessContextFactory businessContextFactory) throws AnalyticsRefreshException { final Account account = businessContextFactory.getAccount(); // Retrieve the account creation audit log final AuditLog creationAuditLog = businessContextFactory.getAccountCreationAuditLog(); // Retrieve the account balance // Note: since we retrieve the invoices below, we could compute it ourselves and avoid fetching the invoices // twice, but that way the computation logic is owned by invoice final BigDecimal accountBalance = businessContextFactory.getAccountBalance(); // Retrieve invoices information Invoice oldestUnpaidInvoice = null;//from w ww.jav a2s . co m Invoice lastInvoice = null; final Iterable<Invoice> invoices = businessContextFactory.getAccountInvoices(); for (final Invoice invoice : invoices) { if (BigDecimal.ZERO.compareTo(invoice.getBalance()) < 0 && (oldestUnpaidInvoice == null || invoice.getInvoiceDate().isBefore(oldestUnpaidInvoice.getInvoiceDate()))) { oldestUnpaidInvoice = invoice; } if (lastInvoice == null || invoice.getInvoiceDate().isAfter(lastInvoice.getInvoiceDate())) { lastInvoice = invoice; } } // Retrieve payments information final Iterable<Payment> payments = businessContextFactory.getAccountPayments(); final PaymentTransaction lastCaptureOrPurchaseTransaction = PaymentUtils .findLastPaymentTransaction(payments, TransactionType.CAPTURE, TransactionType.PURCHASE); // Retrieve bundles information final Iterable<SubscriptionBundle> bundles = businessContextFactory.getAccountBundles(); final int nbActiveBundles = Iterables .size(Iterables.<SubscriptionBundle>filter(bundles, new Predicate<SubscriptionBundle>() { @Override public boolean apply(final SubscriptionBundle bundle) { return Iterables.size(Iterables.<Subscription>filter(bundle.getSubscriptions(), new Predicate<Subscription>() { @Override public boolean apply(final Subscription subscription) { // Bundle is active iff its base entitlement is not cancelled return ProductCategory.BASE .equals(subscription.getLastActiveProductCategory()) && !subscription.getState().equals(EntitlementState.CANCELLED); } })) > 0; } })); final Long accountRecordId = businessContextFactory.getAccountRecordId(); final Long tenantRecordId = businessContextFactory.getTenantRecordId(); final ReportGroup reportGroup = businessContextFactory.getReportGroup(); final CurrencyConverter converter = businessContextFactory.getCurrencyConverter(); return new BusinessAccountModelDao(account, accountRecordId, accountBalance, oldestUnpaidInvoice, lastInvoice, lastCaptureOrPurchaseTransaction, nbActiveBundles, converter, creationAuditLog, tenantRecordId, reportGroup); }
From source file:org.opendaylight.controller.md.sal.dom.broker.impl.DOMConcurrentDataCommitCoordinator.java
@Override public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction transaction, Iterable<DOMStoreThreePhaseCommitCohort> cohorts) { Preconditions.checkArgument(transaction != null, "Transaction must not be null."); Preconditions.checkArgument(cohorts != null, "Cohorts must not be null."); LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier()); final int cohortSize = Iterables.size(cohorts); final AsyncNotifyingSettableFuture clientSubmitFuture = new AsyncNotifyingSettableFuture( clientFutureCallbackExecutor); doCanCommit(clientSubmitFuture, transaction, cohorts, cohortSize); return MappingCheckedFuture.create(clientSubmitFuture, TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER); }
From source file:com.github.jeluard.stone.storage.journalio.JournalIOStorage.java
/** * @param maximumSize /* w w w . j a v a2 s .com*/ * @param journal life-cycle is not handled here, expect a fully {@link Journal#open()} {@code journal} * @param writeCallback */ public JournalIOStorage(final int maximumSize, final Journal journal, final WriteCallback writeCallback) throws IOException { super(maximumSize); this.journal = Preconditions.checkNotNull(journal, "null journal"); this.writeCallback = Preconditions.checkNotNull(writeCallback, "null writeCallback"); this.writes = new AtomicInteger(Iterables.size(all())); }
From source file:eu.interedition.collatex.nmerge.graph.suffixtree.SuffixTree.java
/** * Starts Ukkonen's construction algorithm by calling SPA n times, where * n is the length of the source string. * * @param str the source string is a sequence of unsigned characters * (maximum of 256 different symbols). In the original algorithm '$' * was a special character. However,http://www.abc.net.au/news/ in Yona's * version it is appended at the end of the input string and then never used. *//*from w ww.ja v a 2 s .c o m*/ @SuppressWarnings("unchecked") public SuffixTree(Iterable<T> str, Comparator<T> comparator, T terminal) { this.comparator = comparator; int phase; // added to make 1-character suffix trees work this.virtualEnd = 1; this.length = Iterables.size(str) + 1; this.source = (T[]) Array.newInstance(terminal.getClass(), length + 1); int i = 0; for (T t : str) { this.source[++i] = t; } // the terminal ('$') is never examined but assumed to be there this.source[length] = terminal; this.root = new SuffixTreeNode(null, 0, 0, 0); this.root.largestSuffix = null; // initializing algorithm parameters ExtensionParam ep = new ExtensionParam(); ep.extension = 2; ep.repeatedExtension = 0; phase = 2; // allocating first node, child of the root (phase 0), the longest // path node this.root.children = new SuffixTreeNode(root, 1, length, 1); final SuffixTreePosition position = new SuffixTreePosition(root, 0); // Ukkonen's algorithm begins here for (; phase < length; phase++) { // perform Single Phase Algorithm singlePhase(position, phase, ep); } }
From source file:net.sourceforge.cilib.util.selection.recipes.RankBasedSelector.java
/** * {@inheritDoc}//w ww . ja va2 s . co m */ @Override public PartialSelection<E> on(Iterable<E> iterable) { int size = Iterables.size(iterable); List<E> list = Selection.copyOf(iterable).orderBy(new SortedArrangement()) .select(Samples.last(random.nextInt(size) + 1)); return Selection.copyOf(list).orderBy(new RandomArrangement(random)); }
From source file:jflowmap.views.map.PGeoMap.java
public List<Rectangle2D> createAreasForNodesWithoutCoords(Iterable<Node> nodesWithoutCoords) { int num = Iterables.size(nodesWithoutCoords); if (num <= 0) { return Collections.emptyList(); }/*from w w w .j ava2s .c om*/ List<Rectangle2D> rects = Lists.newArrayList(); int maxPerRow = 4; int numPerRow = Math.min(maxPerRow, num); int r = num % numPerRow; Rectangle2D bounds = getBoundingBox(); double rwidth = bounds.getWidth() * 0.7 / (maxPerRow - 1); double rheight = (bounds.getHeight() / 10); double topMargin = bounds.getHeight() / 5; for (int i = 0; i < num; i++) { final int numInThisRow = (i >= (num - r) ? r : numPerRow); double hcentering = (bounds.getWidth() - (numInThisRow - 1) * rwidth) / 2; double x = hcentering + bounds.getMinX() + (i % numPerRow) * rwidth; double y = bounds.getMaxY() + topMargin + Math.floor(i / numPerRow) * rheight; Rectangle2D rect = new Double(x - rwidth / 2, y - rheight / 3, rwidth, rheight); rect = GeomUtils.growRectByRelativeSize(rect, -0.05, -0.1, -0.05, -0.1); rects.add(rect); } assert (rects.size() == num); return rects; }
From source file:r.lang.primitive.parse.DeparsingVisitor.java
public <T> void appendVector(Iterable<T> values, Function<T, String> deparser) { if (Iterables.size(values) == 1) { deparsed.append(deparser.apply(values.iterator().next())); } else {//from w ww. j a va 2 s . c o m Joiner.on(", ").appendTo(deparsed, transform(values, deparser)); } }
From source file:com.reprezen.swagedit.model.AbstractNode.java
/** * Returns the number of elements contained by this node. * * @return size of children */ public int size() { return Iterables.size(elements()); }
From source file:org.jboss.hal.ballroom.LabelBuilder.java
/** * Turns a list of names from the management model into a human readable enumeration wrapped in quotes and * separated with commas. The last name is separated with the specified conjunction. * * @return The list of names as human readable string or an empty string if the names are null or empty. *///from ww w.jav a 2 s . c o m public String enumeration(Iterable<String> names, String conjunction) { String enumeration = ""; if (names != null && !Iterables.isEmpty(names)) { int size = Iterables.size(names); if (size == 1) { return QUOTE + label(names.iterator().next()) + QUOTE; } else if (size == 2) { return QUOTE + label(Iterables.getFirst(names, "")) + QUOTE + SPACE + conjunction + SPACE + QUOTE + label(Iterables.getLast(names)) + QUOTE; } else { String last = Iterables.getLast(names); LinkedList<String> allButLast = new LinkedList<>(); Iterables.addAll(allButLast, names); allButLast.removeLast(); enumeration = allButLast.stream().map(name -> QUOTE + label(name) + QUOTE) .collect(Collectors.joining(", ")); enumeration = enumeration + SPACE + conjunction + SPACE + QUOTE + label(last) + QUOTE; } } return enumeration; }