/** * @param p Predicate. * @param n Node. * @return {@code True} if filter passed or empty. */ private boolean apply(GridPredicate<N>[] p, N n) { return F.isAll(n, p); }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) @Override public boolean contains(Object o) { if (!(o instanceof GridCacheEntryImpl)) return false; GridCacheEntry<K,V> e = (GridCacheEntry<K, V>)o; return F.isAll(e, filter) && set.contains(e); } }
/** {@inheritDoc} */ @SuppressWarnings({"SuspiciousMethodCalls"}) @Override public boolean contains(Object o) { GridCacheEntry<K, V> e = map.get(o); return e != null && F.isAll(e, filter); } }
@Override public boolean apply(GridDistributedCacheEntry<K, V> e) { return F.isAll(e.key(), keyFilter); } }
/** * @param map Map (out parameter). * @param dep Deployment. * @param p Predicate. */ private void tasks(Map<String, Class<? extends GridComputeTask<?, ?>>> map, GridDeployment dep, GridPredicate<? super Class<? extends GridComputeTask<?, ?>>>[] p) { assert map != null; assert dep != null; for (Map.Entry<String, Class<?>> clsEntry : dep.deployedClassMap().entrySet()) { if (GridComputeTask.class.isAssignableFrom(clsEntry.getValue())) { Class<? extends GridComputeTask<?, ?>> taskCls = (Class<? extends GridComputeTask<?, ?>>)clsEntry.getValue(); if (F.isAll(taskCls, p)) map.put(clsEntry.getKey(), taskCls); } } }
/** * Converts array of integers into list. * * @param arr Array of integers. * @param p Optional predicate array. * @return List of integers. */ public static List<Integer> toIntList(@Nullable int[] arr, GridPredicate<Integer>... p) { if (arr == null || arr.length == 0) return Collections.emptyList(); List<Integer> ret = new ArrayList<>(arr.length); if (F.isEmpty(p)) for (int i : arr) ret.add(i); else { for (int i : arr) if (F.isAll(i, p)) ret.add(i); } return ret; }
/** {@inheritDoc} */ @SuppressWarnings({"SuspiciousMethodCalls"}) @Override public boolean remove(Object o) { GridCacheEntry<K, V> e = map.get(o); if (e == null || !F.isAll(e, filter)) return false; map.remove(o); try { e.removex(); } catch (GridException ex) { throw new GridRuntimeException(ex); } return true; }
/** {@inheritDoc} */ @Override public boolean contains(Object o) { A.notNull(o, "o"); for (GridCacheEntry<K, V> e : map.values()) if (F.isAll(e, filter) && F.eq(e.getValue(), o)) return true; return false; } }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) @Override public boolean remove(Object o) { if (!(o instanceof GridCacheEntryImpl)) return false; GridCacheEntry<K, V> e = (GridCacheEntry<K,V>)o; if (F.isAll(e, filter) && set.remove(e)) { try { e.removex(); } catch (GridException ex) { throw new GridRuntimeException(ex); } return true; } return false; }
/** * Gets event predicate that returns {@code true} only if event id is one of the given. * Note that if array of provided ids is empty this method returns predicate that * evaluates to {@code false} when applying. * * @param ids Event ids. * @return Event predicate. */ public static GridPredicate<GridEvent> eventId(@Nullable final GridUuid... ids) { return isEmpty(ids) ? F.<GridEvent>alwaysFalse() : new GridPredicate<GridEvent>() { // Don't set peer deploy aware as UUID is loaded by // system class loader. @Override public boolean apply(GridEvent e) { assert e != null; return F.isAll(e.id(), in(ids)); } }; }
/** {@inheritDoc} */ @Override public boolean remove(Object o) { A.notNull(o, "o"); boolean rmv = false; for (Iterator<GridCacheEntry<K, V>> it = map.values().iterator(); it.hasNext();) { GridCacheEntry<K, V> e = it.next(); if (F.isAll(e, filter) && F.eq(o, e.getValue())) { it.remove(); try { e.removex(); } catch (GridException ex) { throw new GridRuntimeException(ex); } rmv = true; } } return rmv; }
/** {@inheritDoc} */ @Override public boolean apply(GridCacheEntry<K, V> e) { if (kvFilter != null) { if (!kvFilter.apply(e.getKey(), e.peek())) return false; } return F.isAll(e, entryFilter); } }
if (!F.isAll(e, p)) res.put(e.getKey(), e.getValue());
/** * @param e Entry to verify. * @param noNulls Flag indicating whether filter should accept nulls or not. * @return {@code True} if filter passed. */ boolean isAll(GridCacheEntry<K, V> e, boolean noNulls) { GridCacheFlag[] f = cctx.forceLocalRead(); try { return F.isAll(e, entryFilter(noNulls)); } finally { cctx.forceFlags(f); } }
@Override public boolean apply(GridCacheEntry<K, V> e) { GridCacheVersion ver = (GridCacheVersion)e.version(); return info.version().equals(ver) && F.isAll(info.filter()); } });
/** * Same as {@link GridFunc#isAll(Object, GridPredicate[])}, but safely unwraps * exceptions. * * @param e Element. * @param p Predicates. * @param <E> Element type. * @return {@code True} if predicates passed. * @throws GridException If failed. */ @SuppressWarnings({"ErrorNotRethrown"}) public <E> boolean isAll(E e, @Nullable GridPredicate<? super E>[] p) throws GridException { if (F.isEmpty(p)) return true; // We should allow only local read-only operations within filter checking. GridCacheFlag[] oldFlags = forceFlags(FLAG_LOCAL_READ); try { boolean pass = F.isAll(e, p); if (log.isDebugEnabled()) log.debug("Evaluated filters for entry [pass=" + pass + ", entry=" + e + ", filters=" + Arrays.toString(p) + ']'); return pass; } catch (RuntimeException ex) { throw U.cast(ex); } finally { forceFlags(oldFlags); } }
/** {@inheritDoc} */ @SuppressWarnings({"RedundantTypeArguments"}) @Nullable @Override public GridTuple<V> peek(boolean failFast, K key, GridPredicate<GridCacheEntry<K, V>>[] filter) throws GridCacheFilterFailedException { GridCacheTxEntry<K, V> e = txMap == null ? null : txMap.get(key); if (e != null) { // We should look at tx entry previous value. If this is a user peek then previous // value is the same as value. If this is a filter evaluation peek then previous value holds // value visible to filter while value contains value enlisted for write. if (!F.isAll(e.cached().wrap(false), filter)) return e.hasPreviousValue() ? F.t(CU.<V>failed(failFast, e.previousValue())) : null; return e.hasPreviousValue() ? F.t(e.previousValue()) : null; } return null; }
/** * Checks for key containment. * * @param k Key to check. * @return {@code True} if key is in the map. */ boolean containsKey(K k) { GridCacheEntryEx<K, V> e = ctx.cache().peekEx(k); try { return e != null && !e.obsolete() && (!e.deleted() || e.lockedByThread()) && F.isAll(e.wrap(false), filter); } catch (GridCacheEntryRemovedException ignore) { return false; } }