Java Code Examples for com.google.common.base.Predicates#and()

The following examples show how to use com.google.common.base.Predicates#and() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlarmStateMachine.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
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)
	);
}
 
Example 2
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: CatalogResource.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: LocalEntityManager.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@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));
}
 
Example 6
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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));
}
 
Example 7
Source File: DocumentPredicates.java    From estatio with Apache License 2.0 4 votes vote down vote up
public static Predicate<Document> isPdfAndBlob() {
    return Predicates.and(MimeTypeData.APPLICATION_PDF::matches, isBlobSort());
}
 
Example 8
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: Main.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private static Predicate<Entry> buildPredicate(Arguments arguments) {
   return Predicates.and(matchingPlaces(arguments.places), matchingAddresses(arguments.addresses));
}
 
Example 10
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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));
}
 
Example 11
Source File: TLDQueryIterator.java    From datawave with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 12
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: MemoryMeasurer.java    From memory-measurer with Apache License 2.0 3 votes vote down vote up
/**
 * 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));
}
 
Example 14
Source File: StateMachine.java    From attic-aurora with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * 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));
}
 
Example 16
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * 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));
}
 
Example 17
Source File: MethodCoercions.java    From brooklyn-server with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example 18
Source File: Multimaps.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: AndMessageFilter.java    From suro with Apache License 2.0 2 votes vote down vote up
public AndMessageFilter(Iterable<? extends MessageFilter> filters) {

        this.andPredicate = Predicates.and(filters);
	}
 
Example 20
Source File: Multimaps.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}