List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:com.eviware.loadui.ui.fx.views.workspace.CreateNewAgentDialog.java
private void addDetectedAgents() { try {/*from w w w. j a v a2 s . co m*/ AgentDiscovery discovery = BeanInjector.getBeanFuture(AgentDiscovery.class).get(100, TimeUnit.MILLISECONDS); Iterable<AgentReference> newAgents = Iterables.filter(discovery.getDiscoveredAgents(), new Predicate<AgentReference>() { @Override public boolean apply(AgentReference agentReference) { return validateUnique(filterUrl(agentReference.getUrl())); } }); if (!Iterables.isEmpty(newAgents)) { Iterable<Node> agentCheckBoxes = Iterables.transform(newAgents, new Function<AgentReference, Node>() { @Override public Node apply(final AgentReference agentReference) { final CheckBox checkBox = CheckBoxBuilder.create().text(String.format("%s (%s)", agentReference.getDefaultLabel(), agentReference.getUrl())).build(); checkBox.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { if (checkBox.isSelected()) { selectedAgentRefs.add(agentReference); } else { selectedAgentRefs.remove(agentReference); } } }); return checkBox; } }); getItems().addAll(new Label("Agents detected in your network"), ScrollPaneBuilder.create().content(VBoxBuilder.create().spacing(6).padding(new Insets(2)) .children(Lists.newArrayList(agentCheckBoxes)).build()).build()); } } catch (InterruptedException | ExecutionException | TimeoutException e) { // Ignore failure. } }
From source file:com.freiheit.fuava.simplebatch.processor.RetryingProcessor.java
@Override public Iterable<Result<OriginalItem, Output>> process(final Iterable<Result<OriginalItem, Input>> inputs) { final List<Result<OriginalItem, Input>> inputList = ImmutableList.copyOf(inputs); if (inputList.isEmpty()) { return ImmutableList.of(); }// www. ja v a2 s. co m try { return doPersist(inputList); } catch (final java.lang.VirtualMachineError e) { // there is absolutely no way how those types of errors could be handled, rethrow it throw e; } catch (final Throwable t) { if (inputList.size() == 1) { final Result<OriginalItem, Input> result = inputList.get(0); return ImmutableList.of(Result.<OriginalItem, Output>builder(result).failed(t)); } LOG.info("Caught Exception during processing of batch with " + inputList.size() + " items, will RETRY in single item batches", t); final ImmutableList.Builder<Result<OriginalItem, Output>> retriedResults = ImmutableList.builder(); for (final Result<OriginalItem, Input> input : inputList) { final Iterable<Result<OriginalItem, Output>> outputs = process(ImmutableList.of(input)); if (Iterables.isEmpty(outputs)) { throw new IllegalStateException("processing of singletons must never lead to empty lists here"); } retriedResults.addAll(outputs); } return retriedResults.build(); } }
From source file:org.jboss.as.console.client.administration.accesscontrol.ui.Templates.java
static SafeHtml principalPreview(final Principal principal, Iterable<Assignment> includes, Iterable<Assignment> excludes) { SafeHtmlBuilder details = new SafeHtmlBuilder(); details.appendHtmlConstant("<p>"); if (!Iterables.isEmpty(excludes)) { List<Role> excludedRoles = Roles.orderedByName().immutableSortedCopy(distinctRoles(excludes)); details.appendEscaped("Excluded from "); details.appendEscaped(Joiner.on(", ").join(Lists.transform(excludedRoles, Role::getName))); details.appendEscaped("."); details.appendHtmlConstant("<br/>"); }/*from w w w.j a v a 2 s. co m*/ if (!Iterables.isEmpty(includes)) { List<Role> assignedRoles = Roles.orderedByName().immutableSortedCopy(distinctRoles(includes)); details.appendEscaped("Assigned to "); details.appendEscaped(Joiner.on(", ").join(Lists.transform(assignedRoles, Role::getName))); details.appendEscaped("."); } if (Iterables.isEmpty(excludes) && Iterables.isEmpty(includes)) { details.appendEscaped("No roles are assigned to this "); details.appendEscaped(principal.getType() == Principal.Type.USER ? "user" : "group"); details.append('.'); } details.appendHtmlConstant("</p>"); return principal.getType() == Principal.Type.USER ? PREVIEWS.user(principal.getName(), details.toSafeHtml()) : PREVIEWS.group(principal.getName(), details.toSafeHtml()); }
From source file:org.killbill.billing.invoice.calculator.InvoiceCalculatorUtils.java
public static BigDecimal computeChildInvoiceAmount(final Currency currency, @Nullable final Iterable<InvoiceItem> invoiceItems) { final Iterable<InvoiceItem> chargeItems = Iterables.filter(invoiceItems, new Predicate<InvoiceItem>() { @Override/*from ww w .j a va 2s . c o m*/ public boolean apply(@Nullable final InvoiceItem input) { return isCharge(input); } }); if (Iterables.isEmpty(chargeItems)) { // return only credit amount to be subtracted to parent item amount return computeInvoiceAmountCredited(currency, invoiceItems).negate(); } final BigDecimal chargedAmount = computeInvoiceAmountCharged(currency, invoiceItems) .add(computeInvoiceAmountCredited(currency, invoiceItems)) .add(computeInvoiceAmountAdjustedForAccountCredit(currency, invoiceItems)); return KillBillMoney.of(chargedAmount, currency); }
From source file:org.gradle.api.internal.tasks.compile.incremental.SelectiveCompiler.java
@Override public WorkResult execute(JavaCompileSpec spec) { Timer clock = Time.startTimer(); CurrentCompilation currentCompilation = new CurrentCompilation(inputs, spec, classpathSnapshotProvider); RecompilationSpec recompilationSpec = recompilationSpecProvider.provideRecompilationSpec(currentCompilation, previousCompilation);/*from w w w. j a v a 2 s . co m*/ if (recompilationSpec.isFullRebuildNeeded()) { LOG.info("Full recompilation is required because {}. Analysis took {}.", recompilationSpec.getFullRebuildCause(), clock.getElapsed()); return rebuildAllCompiler.execute(spec); } incrementalCompilationInitializer.initializeCompilation(spec, recompilationSpec); if (Iterables.isEmpty(spec.getSourceFiles()) && spec.getClasses().isEmpty()) { LOG.info("None of the classes needs to be compiled! Analysis took {}. ", clock.getElapsed()); return new RecompilationNotNecessary(); } try { return cleaningCompiler.getCompiler().execute(spec); } finally { Collection<String> classesToCompile = recompilationSpec.getClassesToCompile(); LOG.info("Incremental compilation of {} classes completed in {}.", classesToCompile.size(), clock.getElapsed()); LOG.debug("Recompiled classes {}", classesToCompile); } }
From source file:org.apache.metron.stellar.dsl.functions.OrdinalFunctions.java
private static Comparable orderList(Iterable<Comparable> list, BiFunction<Comparable, Comparable, Boolean> eval, String funcName) {//from www .j a v a 2s. c o m if (Iterables.isEmpty(list)) { return null; } Object o = Iterables.getFirst(list, null); Comparable ret = null; for (Object valueVal : list) { if (valueVal == null) { continue; } Comparable value = null; if (!(valueVal instanceof Comparable)) { throw new IllegalStateException( "Noncomparable object type " + valueVal.getClass().getName() + " submitted to " + funcName); } else { value = (Comparable) valueVal; } try { Comparable convertedRet = ConversionUtils.convert(ret, value.getClass()); if (convertedRet == null && ret != null) { throw new IllegalStateException("Incomparable objects were submitted to " + funcName + ": " + ret.getClass() + " is incomparable to " + value.getClass()); } if (ret == null || eval.apply(convertedRet, value)) { ret = value; } } catch (ClassCastException cce) { throw new IllegalStateException( "Incomparable objects were submitted to " + funcName + ": " + cce.getMessage(), cce); } } return ret; }
From source file:org.apache.cassandra.db.lifecycle.Tracker.java
/** * @return a Transaction over the provided sstables if we are able to mark the given @param sstables as compacted, before anyone else */// w w w .j a va2 s. c om public LifecycleTransaction tryModify(Iterable<SSTableReader> sstables, OperationType operationType) { if (Iterables.isEmpty(sstables)) return new LifecycleTransaction(this, operationType, sstables); if (null == apply(permitCompacting(sstables), updateCompacting(emptySet(), sstables))) return null; return new LifecycleTransaction(this, operationType, sstables); }
From source file:com.reprezen.swagedit.editor.outline.OutlineStyledLabelProvider.java
protected Icons getIcon(AbstractNode element) { AbstractNode parent = element.getParent(); if (parent == null) { return Icons.outline_document; }//ww w.j a va2 s. c o m if (parent.isObject()) { if (Iterables.isEmpty(element.elements())) { return Icons.outline_mapping_scalar; } else { return Icons.outline_mapping; } } else if (parent.isArray()) { if (Iterables.isEmpty(element.elements())) { return Icons.outline_scalar; } else { return Icons.outline_sequence; } } else { return Icons.outline_scalar; } }
From source file:org.apache.abdera2.ext.license.LicenseHelper.java
public static boolean hasLicense(Base base, boolean inherited) { Iterable<Link> links = getLicense(base, inherited); return !Iterables.isEmpty(links); }
From source file:com.google.devtools.j2objc.translate.RuntimeAnnotationGenerator.java
/** * Generate a function that returns the 2-dimentional array of annotations for method parameters. *//*from w w w. j a va 2 s. co m*/ public String createParamsFunction(MethodDeclaration method) { List<SingleVariableDeclaration> params = method.getParameters(); // Quick test to see if there are any parameter annotations. boolean hasAnnotations = false; for (SingleVariableDeclaration param : params) { if (!Iterables.isEmpty(TreeUtil.getRuntimeAnnotations(param.getAnnotations()))) { hasAnnotations = true; break; } } if (!hasAnnotations) { return null; } List<Expression> subArrays = new ArrayList<>(); for (SingleVariableDeclaration param : params) { List<Annotation> runtimeAnnotations = TreeUtil.getRuntimeAnnotationsList(param.getAnnotations()); if (runtimeAnnotations.isEmpty()) { subArrays.add(new ArrayCreation(GeneratedTypeBinding.newArrayType(ANNOTATION_TYPE), typeEnv, 0)); } else { subArrays.add(createAnnotations(runtimeAnnotations)); } } return addFunction(createObjectArray(subArrays, GeneratedTypeBinding.newArrayType(ANNOTATION_TYPE))); }