List of usage examples for com.google.common.collect Iterables contains
public static boolean contains(Iterable<?> iterable, @Nullable Object element)
From source file:edu.umn.msi.tropix.common.test.EasyMockUtils.java
public static <T, S extends Iterable<T>> S hasSameUniqueElements(final Iterable<? extends T> iterable) { final IArgumentMatcher argMatcher = new IArgumentMatcher() { public void appendTo(final StringBuffer buffer) { buffer.append("Incorrect elements found"); }// www .j av a 2 s.co m public boolean matches(final Object arg) { @SuppressWarnings("unchecked") final Iterable<T> input = (S) arg; for (final T object : input) { if (!Iterables.contains(iterable, object)) { return false; } } for (final T object : iterable) { if (!Iterables.contains(input, object)) { return false; } } return true; } }; EasyMock.reportMatcher(argMatcher); return null; }
From source file:org.jclouds.azurecompute.arm.compute.AzureComputeServiceAdapter.java
@Override public Iterable<Location> listLocations() { final Iterable<String> vmLocations = FluentIterable .from(api.getResourceProviderApi().get("Microsoft.Compute")) .filter(new Predicate<ResourceProviderMetaData>() { @Override/* w w w.j ava2s . c o m*/ public boolean apply(ResourceProviderMetaData input) { return input.resourceType().equals("virtualMachines"); } }).transformAndConcat(new Function<ResourceProviderMetaData, Iterable<String>>() { @Override public Iterable<String> apply(ResourceProviderMetaData resourceProviderMetaData) { return resourceProviderMetaData.locations(); } }); List<Location> locations = FluentIterable.from(api.getLocationApi().list()) .filter(new Predicate<Location>() { @Override public boolean apply(Location location) { return Iterables.contains(vmLocations, location.displayName()); } }).filter(new Predicate<Location>() { @Override public boolean apply(Location location) { return regionIds.get().isEmpty() ? true : regionIds.get().contains(location.name()); } }).toList(); return locations; }
From source file:com.netflix.metacat.main.services.impl.MViewServiceImpl.java
/** * Validate the qualified name./*from w w w .j av a 2 s .co m*/ * Validate if the catalog is one of the catalogs that support views. * Assumes that the "franklinviews" database name already exists in the given catalog. */ private Session validateAndGetSession(final QualifiedName name) { Preconditions.checkNotNull(name, "name cannot be null"); Preconditions.checkState(name.isViewDefinition(), "name %s is not for a view", name); if (!Iterables.contains(SUPPORTED_SOURCES, name.getCatalogName())) { throw new MetacatNotSupportedException( String.format("This catalog (%s) doesn't support views", name.getCatalogName())); } return sessionProvider.getSession(name); }
From source file:org.renjin.primitives.Attributes.java
@Internal public static boolean inherits(SEXP exp, StringVector what) { StringVector classes = getClass(exp); for (String whatClass : what) { if (Iterables.contains(classes, whatClass)) { return true; }/*from w ww . ja v a2 s . co m*/ } return false; }
From source file:org.renjin.primitives.Attributes.java
@Internal public static boolean inherits(SEXP exp, String what) { return Iterables.contains(getClass(exp), what); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultOpenAnswerDefinitionPanel.java
private DataField createAutoCompleteDataField(ValueMap arguments) { final OpenAnswerDefinitionSuggestion suggestion = new OpenAnswerDefinitionSuggestion( getOpenAnswerDefinition());// ww w.j ava 2 s.c o m final AbstractAutoCompleteDataProvider provider = suggestion .getSuggestionSource() == OpenAnswerDefinitionSuggestion.Source.ITEMS_LIST ? new ItemListDataProvider() : new VariableDataProvider(); final IAutoCompleteDataConverter converter = new IAutoCompleteDataConverter() { private static final long serialVersionUID = 1L; @Override public Data getModelObject(String key) { return DataBuilder.buildText(key); } @Override public String getKey(Data data) { return data.getValueAsString(); } @Override public String getDisplayValue(Data data, String partial) { String key = getKey(data); String label = provider.localizeChoice(key); String display = Strings.escapeMarkup(key, true).toString(); if (Strings.isEmpty(label) == false) { display = display + " : " + Strings.escapeMarkup(label); } return highlightMatches(partial, display); } private String highlightMatches(String partial, String mayContain) { if (mayContain == null) return null; if (Strings.isEmpty(partial)) return mayContain; // The pattern we want is "(tylenol|extra|strength)" StringBuilder pattern = new StringBuilder("("); Joiner.on("|").appendTo(pattern, Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings().split(partial)); pattern.append(")"); Matcher matcher = Pattern.compile(pattern.toString(), Pattern.CASE_INSENSITIVE).matcher(mayContain); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, "<span class='match'>" + Strings.escapeMarkup(matcher.group(0), true) + "</span>"); } matcher.appendTail(sb); return sb.toString(); } }; DataField f = new DataField("open", new PropertyModel<Data>(this, "data"), DataType.TEXT, provider, converter, new AutoCompleteSettings().setAdjustInputWidth(false)); if (suggestion.getNewValueAllowed() == false) { f.add(new AbstractValidator<Data>() { private static final long serialVersionUID = 1L; @Override protected void onValidate(IValidatable<Data> validatable) { Data value = validatable.getValue(); if (value != null && value.getValue() != null && Iterables.contains(provider.getChoices(value.getValueAsString()), value) == false) { error(validatable, "NotASuggestedValue"); } } }); } return f; }
From source file:org.eclipse.che.ide.part.explorer.project.NewProjectExplorerViewImpl.java
@Override public void reloadChildren(List<Node> nodes, final Object selectAfter, final boolean callAction) { if (nodes == null || nodes.isEmpty()) { nodeManager.getProjects().then(selectAfter(selectAfter)); return;/*from w w w .ja va2 s .c o m*/ } List<Node> rootNodes = tree.getRootNodes(); boolean rootNodeFound = false; for (Node nodeToReload : nodes) { if (Iterables.contains(rootNodes, nodeToReload)) { rootNodeFound = true; break; } } if (rootNodeFound) { for (Node rootNode : rootNodes) { tree.getNodeLoader().loadChildren(rootNode); } } else { for (Node nodeToReload : nodes) { tree.getNodeLoader().loadChildren(nodeToReload); } if (nodes.size() == 1 && selectAfter != null) { tree.addExpandHandler(new ExpandNodeHandler() { @Override public void onExpand(ExpandNodeEvent event) { List<Node> children = tree.getNodeStorage().getChildren(event.getNode()); for (Node child : children) { if (child instanceof HasDataObject<?> && ((HasDataObject<?>) child).getData().equals(selectAfter)) { tree.getSelectionModel().select(child, false); if (callAction && child instanceof HasAction) { ((HasAction) child).actionPerformed(); } return; } } } }); } } }
From source file:org.jclouds.azurecompute.compute.AzureComputeServiceAdapter.java
@Override public Iterable<Deployment> listNodesByIds(final Iterable<String> ids) { return Iterables.filter(listNodes(), new Predicate<Deployment>() { @Override// w w w . j av a 2s . c o m public boolean apply(final Deployment input) { return Iterables.contains(ids, input.name()); } }); }
From source file:org.killbill.billing.invoice.InvoiceDispatcher.java
private void filterInvoiceItemsForDryRun(final Iterable<UUID> filteredSubscriptionIdsForDryRun, final Invoice invoice) { if (!filteredSubscriptionIdsForDryRun.iterator().hasNext()) { return;/*from w ww . j a v a 2 s .c o m*/ } final Iterator<InvoiceItem> it = invoice.getInvoiceItems().iterator(); while (it.hasNext()) { final InvoiceItem cur = it.next(); if (!Iterables.contains(filteredSubscriptionIdsForDryRun, cur.getSubscriptionId())) { it.remove(); } } }
From source file:org.eclipse.emf.compare.internal.utils.ComparisonUtil.java
/** * When merging a {@link Diff}, returns the associated diffs of the sub diffs of the diff, and all sub * diffs (see {@link DiffUtil#getSubDiffs(boolean)}) of these associated diffs. * <p>/*from w w w . ja va 2 s . com*/ * The associated diffs of a diff are : * <p> * - {@link Diff#getRequiredBy()} if the source of the diff is the left side and the direction of the * merge is right to left. * </p> * <p> * - {@link Diff#getRequiredBy()} if the source of the diff is the right side and the direction of the * merge is left to right. * </p> * <p> * - {@link Diff#getRequires()} if the source of the diff is the left side and the direction of the merge * is left to right. * </p> * <p> * - {@link Diff#getRequires()} if the source of the diff is the right side and the direction of the merge * is right to left. * </p> * </p> * * @param diffRoot * the given diff. * @param subDiffs * the iterable of sub diffs for which we want the associated diffs. * @param processedDiffs * a set of diffs which have been already processed. * @param leftToRight * the direction of merge. * @param firstLevelOnly * to get only the first level of subDiffs. * @return an iterable containing the associated diffs of these given sub diffs, and all sub diffs of * these associated diffs. * @since 3.0 */ private static Iterable<Diff> getAssociatedDiffs(final Diff diffRoot, Iterable<Diff> subDiffs, LinkedHashSet<Diff> processedDiffs, boolean leftToRight, boolean firstLevelOnly) { Collection<Diff> associatedDiffs = new LinkedHashSet<Diff>(); for (Diff diff : subDiffs) { final Collection<Diff> reqs = new LinkedHashSet<Diff>(); if (leftToRight) { if (diff.getSource() == DifferenceSource.LEFT) { reqs.addAll(diff.getRequires()); } else { reqs.addAll(diff.getRequiredBy()); } } else { if (diff.getSource() == DifferenceSource.LEFT) { reqs.addAll(diff.getRequiredBy()); } else { reqs.addAll(diff.getRequires()); } } reqs.remove(diffRoot); associatedDiffs.addAll(reqs); associatedDiffs.addAll(diff.getRefines()); for (Diff req : reqs) { if (!Iterables.contains(subDiffs, req) && !processedDiffs.contains(req)) { processedDiffs.add(req); addAll(associatedDiffs, getSubDiffs(leftToRight, firstLevelOnly, processedDiffs).apply(req)); } } } return associatedDiffs; }