下面列出了com.google.common.base.Predicates#and ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
ActiveDevicesBinder(String availableDevicesAttribute, Predicate<Model> triggerSelector) {
super(
availableDevicesAttribute,
Predicates.and(Predicates.not(triggerSelector), Predicates.not(com.iris.model.predicate.Predicates.isDeviceOffline())),
NamespacedKey.representation(AlarmCapability.ATTR_ACTIVEDEVICES, name)
);
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered navigable map.
*/
@GwtIncompatible // NavigableMap
private static <K, V> NavigableMap<K, V> filterFiltered(FilteredEntryNavigableMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(map.entryPredicate, entryPredicate);
return new FilteredEntryNavigableMap<K, V>(map.unfiltered, predicate);
}
@Override
@Deprecated
public List<CatalogEnricherSummary> listEnrichers(@ApiParam(name = "regex", value = "Regular expression to search for") @DefaultValue("") String regex, @ApiParam(name = "fragment", value = "Substring case-insensitive to search for") @DefaultValue("") String fragment, @ApiParam(name = "allVersions", value = "Include all versions (defaults false, only returning the best version)") @DefaultValue("false") boolean includeAllVersions) {
Predicate<RegisteredType> filter =
Predicates.and(
RegisteredTypePredicates.IS_ENRICHER,
RegisteredTypePredicates.disabled(false));
List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, includeAllVersions);
return castList(result, CatalogEnricherSummary.class);
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered map.
*/
private static <K, V> BiMap<K, V> filterFiltered(FilteredEntryBiMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(map.predicate, entryPredicate);
return new FilteredEntryBiMap<K, V>(map.unfiltered(), predicate);
}
/**
* Returns the elements of {@code unfiltered} that satisfy a predicate. The
* returned set is a live view of {@code unfiltered}; changes to one affect
* the other.
*
* <p>The resulting set's iterator does not support {@code remove()}, but all
* other set methods are supported. When given an element that doesn't satisfy
* the predicate, the set's {@code add()} and {@code addAll()} methods throw
* an {@link IllegalArgumentException}. When methods such as {@code
* removeAll()} and {@code clear()} are called on the filtered set, only
* elements that satisfy the filter will be removed from the underlying set.
*
* <p>The returned set isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered set's methods, such as {@code size()}, iterate
* across every element in the underlying set and determine which elements
* satisfy the filter. When a live view is <i>not</i> needed, it may be faster
* to copy {@code Iterables.filter(unfiltered, predicate)} and use the copy.
*
* <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such
* as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
* with equals. (See {@link Iterables#filter(Iterable, Class)} for related
* functionality.)
*/
// TODO(kevinb): how to omit that last sentence when building GWT javadoc?
public static <E> Set<E> filter(Set<E> unfiltered, Predicate<? super E> predicate) {
if (unfiltered instanceof SortedSet) {
return filter((SortedSet<E>) unfiltered, predicate);
}
if (unfiltered instanceof FilteredSet) {
// Support clear(), removeAll(), and retainAll() when filtering a filtered
// collection.
FilteredSet<E> filtered = (FilteredSet<E>) unfiltered;
Predicate<E> combinedPredicate = Predicates.<E>and(filtered.predicate, predicate);
return new FilteredSet<E>((Set<E>) filtered.unfiltered, combinedPredicate);
}
return new FilteredSet<E>(checkNotNull(unfiltered), checkNotNull(predicate));
}
public static Predicate<Document> isPdfAndBlob() {
return Predicates.and(MimeTypeData.APPLICATION_PDF::matches, isBlobSort());
}
private static Predicate<Entry> buildPredicate(Arguments arguments) {
return Predicates.and(matchingPlaces(arguments.places), matchingAddresses(arguments.addresses));
}
@SuppressWarnings({"rawtypes", "unchecked"})
private Predicate<Key> parseIndexFilteringChain(final Map<String,String> options) {
// Create a list to gather up the predicates
List<Predicate<Key>> predicates = Collections.emptyList();
final String functions = (null != options) ? options.get(IndexIterator.INDEX_FILTERING_CLASSES) : StringUtils.EMPTY_STRING;
if ((null != functions) && !functions.isEmpty()) {
try {
for (final String fClassName : StringUtils.splitIterable(functions, ',', true)) {
// Log it
if (log.isTraceEnabled()) {
log.trace("Configuring index-filtering class: " + fClassName);
}
final Class<?> fClass = Class.forName(fClassName);
if (Predicate.class.isAssignableFrom(fClass)) {
// Create and configure the predicate
final Predicate p = (Predicate) fClass.newInstance();
if (p instanceof ConfiguredPredicate) {
((ConfiguredPredicate) p).configure(options);
}
// Initialize a mutable List instance and add the default filter, if defined
if (predicates.isEmpty()) {
predicates = new LinkedList<>();
final Predicate<Key> existingPredicate = fieldIndexKeyDataTypeFilter;
if ((null != existingPredicate) && (((Object) existingPredicate) != Predicates.alwaysTrue())) {
predicates.add(existingPredicate);
}
}
// Add the newly instantiated predicate
predicates.add(p);
} else {
log.error(fClass + " is not a function or predicate. Postprocessing will not be performed.");
return fieldIndexKeyDataTypeFilter;
}
}
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
log.error("Could not instantiate postprocessing chain!", e);
}
}
// Assign the return value
final Predicate<Key> predicate;
if (!predicates.isEmpty()) {
if (predicates.size() == 1) {
predicate = predicates.get(0);
} else {
predicate = Predicates.and(predicates);
}
} else {
predicate = fieldIndexKeyDataTypeFilter;
}
return predicate;
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered map.
*/
private static <K, V> BiMap<K, V> filterFiltered(FilteredEntryBiMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(map.predicate, entryPredicate);
return new FilteredEntryBiMap<K, V>(map.unfiltered(), predicate);
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered map.
*/
private static <K, V> Map<K, V> filterFiltered(AbstractFilteredMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
return new FilteredEntryMap<K, V>(map.unfiltered, Predicates.<Entry<K, V>>and(map.predicate, entryPredicate));
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered sorted map.
*/
private static <K, V> SortedMap<K, V> filterFiltered(FilteredEntrySortedMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(map.predicate, entryPredicate);
return new FilteredEntrySortedMap<K, V>(map.sortedMap(), predicate);
}
@Override
public Collection<Entity> findEntitiesInApplication(Application application, Predicate<? super Entity> filter) {
Predicate<Entity> predicate = Predicates.and(EntityPredicates.applicationIdEqualTo(application.getId()), filter);
return ImmutableList.copyOf(Iterables.filter(entityProxiesById.values(), predicate));
}
/**
* Measures the memory footprint, in bytes, of an object graph. The object
* graph is defined by a root object and whatever object can be reached
* through that, excluding static fields, {@code Class} objects, and
* fields defined in {@code enum}s (all these are considered shared values,
* which should not contribute to the cost of any single object graph), and
* any object for which the user-provided predicate returns {@code false}.
*
* @param rootObject the root object that defines the object graph to be
* measured
* @param objectAcceptor a predicate that returns {@code true} for objects
* to be explored (and treated as part of the object graph), or
* {@code false} to forbid the traversal to traverse the given object
* @return the memory footprint, in bytes, of the object graph
*/
public static long measureBytes(Object rootObject, Predicate<Object> objectAcceptor) {
Preconditions.checkNotNull(objectAcceptor, "predicate");
Predicate<Chain> completePredicate = Predicates.and(ImmutableList.of(
new ObjectExplorer.AtMostOncePredicate(),
ObjectExplorer.notEnumFieldsOrClasses,
Predicates.compose(objectAcceptor, ObjectExplorer.chainToObject)
));
return ObjectExplorer.exploreObject(rootObject,
new MemoryMeasurerVisitor(completePredicate));
}
/**
* Returns the elements of a {@code SortedSet}, {@code unfiltered}, that
* satisfy a predicate. The returned set is a live view of {@code unfiltered};
* changes to one affect the other.
*
* <p>The resulting set's iterator does not support {@code remove()}, but all
* other set methods are supported. When given an element that doesn't satisfy
* the predicate, the set's {@code add()} and {@code addAll()} methods throw
* an {@link IllegalArgumentException}. When methods such as
* {@code removeAll()} and {@code clear()} are called on the filtered set,
* only elements that satisfy the filter will be removed from the underlying
* set.
*
* <p>The returned set isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered set's methods, such as {@code size()}, iterate across
* every element in the underlying set and determine which elements satisfy
* the filter. When a live view is <i>not</i> needed, it may be faster to copy
* {@code Iterables.filter(unfiltered, predicate)} and use the copy.
*
* <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such as
* {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent with
* equals. (See {@link Iterables#filter(Iterable, Class)} for related
* functionality.)
*
* @since 11.0
*/
public static <E> SortedSet<E> filter(SortedSet<E> unfiltered, Predicate<? super E> predicate) {
if (unfiltered instanceof FilteredSet) {
// Support clear(), removeAll(), and retainAll() when filtering a filtered
// collection.
FilteredSet<E> filtered = (FilteredSet<E>) unfiltered;
Predicate<E> combinedPredicate = Predicates.<E>and(filtered.predicate, predicate);
return new FilteredSortedSet<E>((SortedSet<E>) filtered.unfiltered, combinedPredicate);
}
return new FilteredSortedSet<E>(checkNotNull(unfiltered), checkNotNull(predicate));
}
/**
* Returns the elements of a {@code NavigableSet}, {@code unfiltered}, that
* satisfy a predicate. The returned set is a live view of {@code unfiltered};
* changes to one affect the other.
*
* <p>The resulting set's iterator does not support {@code remove()}, but all
* other set methods are supported. When given an element that doesn't satisfy
* the predicate, the set's {@code add()} and {@code addAll()} methods throw
* an {@link IllegalArgumentException}. When methods such as
* {@code removeAll()} and {@code clear()} are called on the filtered set,
* only elements that satisfy the filter will be removed from the underlying
* set.
*
* <p>The returned set isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered set's methods, such as {@code size()}, iterate across
* every element in the underlying set and determine which elements satisfy
* the filter. When a live view is <i>not</i> needed, it may be faster to copy
* {@code Iterables.filter(unfiltered, predicate)} and use the copy.
*
* <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such as
* {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent with
* equals. (See {@link Iterables#filter(Iterable, Class)} for related
* functionality.)
*
* @since 14.0
*/
@GwtIncompatible // NavigableSet
@SuppressWarnings("unchecked")
public static <E> NavigableSet<E> filter(
NavigableSet<E> unfiltered, Predicate<? super E> predicate) {
if (unfiltered instanceof FilteredSet) {
// Support clear(), removeAll(), and retainAll() when filtering a filtered
// collection.
FilteredSet<E> filtered = (FilteredSet<E>) unfiltered;
Predicate<E> combinedPredicate = Predicates.<E>and(filtered.predicate, predicate);
return new FilteredNavigableSet<E>((NavigableSet<E>) filtered.unfiltered, combinedPredicate);
}
return new FilteredNavigableSet<E>(checkNotNull(unfiltered), checkNotNull(predicate));
}
/**
* Creates a predicate that returns {@code true} for a specific state transition.
*
* @param from From state.
* @param to To state.
* @param <T> State type.
* @return A state transition filter.
*/
public static <T> Predicate<Transition<T>> transition(final T from, final T to) {
@SuppressWarnings("unchecked")
Predicate<Transition<T>> fromFilter = from(from);
@SuppressWarnings("unchecked")
Predicate<Transition<T>> toFilter = to(to);
return Predicates.and(fromFilter, toFilter);
}
public AndMessageFilter(Iterable<? extends MessageFilter> filters) {
this.andPredicate = Predicates.and(filters);
}
/**
* Support removal operations when filtering a filtered multimap. Since a filtered multimap has
* iterators that don't support remove, passing one to the FilteredEntryMultimap constructor would
* lead to a multimap whose removal operations would fail. This method combines the predicates to
* avoid that problem.
*/
private static <K, V> SetMultimap<K, V> filterFiltered(FilteredSetMultimap<K, V> multimap, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(multimap.entryPredicate(), entryPredicate);
return new FilteredEntrySetMultimap<K, V>(multimap.unfiltered(), predicate);
}
/**
* Returns a predicate that matches a method with the given name, and parameters that
* {@link org.apache.brooklyn.util.core.flags.TypeCoercions#tryCoerce(Object, com.google.common.reflect.TypeToken)} can process
* from the given list of arguments.
*
* @param methodName name of the method
* @param arguments arguments that is intended to be given
* @return a predicate that will match a compatible method
*/
public static Predicate<Method> matchMultiParameterMethod(final String methodName, final List<?> arguments) {
return Predicates.and(matchMethodByName(methodName), matchMultiParameterMethod(arguments));
}
/**
* Support removal operations when filtering a filtered multimap. Since a
* filtered multimap has iterators that don't support remove, passing one to
* the FilteredEntryMultimap constructor would lead to a multimap whose removal
* operations would fail. This method combines the predicates to avoid that
* problem.
*/
private static <K, V> Multimap<K, V> filterFiltered(FilteredMultimap<K, V> multimap, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.<Entry<K, V>>and(multimap.entryPredicate(), entryPredicate);
return new FilteredEntryMultimap<K, V>(multimap.unfiltered(), predicate);
}