/** {@inheritDoc} */ @Override void onEvent(Event evt, Object[] params) { if (!lsnr.apply(evt)) removeEventListener(this, null); }
/** {@inheritDoc} */ @Nullable @Override public IgniteTxEntry get(Object key) { IgniteTxEntry e = txMap.get(key); return e == null ? null : filter.apply(e) ? e : null; }
/** {@inheritDoc} */ @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { String clsName = desc.getName(); if (clsFilter != null && !clsFilter.apply(clsName)) throw new RuntimeException("Deserialization of class " + clsName + " is disallowed."); return super.resolveClass(desc); } }
/** * Tests if all provided predicates evaluate to {@code true} for given value. Note that * evaluation will be short-circuit when first predicate evaluated to {@code false} is found. * * @param t Value to test. * @param p Optional set of predicates to use for evaluation. If no predicates provides * this method will always return {@code true}. * @param <T> Type of the value and free variable of the predicates. * @return Returns {@code true} if given set of predicates is {@code null}, is empty, or all predicates * evaluate to {@code true} for given value, {@code false} otherwise. */ public static <T> boolean isAll(@Nullable T t, @Nullable IgnitePredicate<? super T>... p) { if (p != null) for (IgnitePredicate<? super T> r : p) if (r != null && !r.apply(t)) return false; return true; }
/** * @param n Node. * @return Whether node belongs to this cluster group. */ private boolean contains(ClusterNode n) { assert n != null; return ids != null ? ids.contains(n.id()) : p == null || p.apply(n); }
/** * Tests if any of provided predicates evaluate to {@code true} for given value. Note * that evaluation will be short-circuit when first predicate evaluated to {@code true} * is found. * * @param t Value to test. * @param p Optional set of predicates to use for evaluation. * @param <T> Type of the value and free variable of the predicates. * @return Returns {@code true} if any of predicates evaluates to {@code true} for given * value, {@code false} otherwise. Returns {@code false} if given set of predicates * is {@code null} or empty. */ @Deprecated public static <T> boolean isAny(@Nullable T t, @Nullable IgnitePredicate<? super T>... p) { if (p != null) for (IgnitePredicate<? super T> r : p) if (r != null && r.apply(t)) return true; return false; }
@Override public boolean apply(T t) { for (int type : types) { if (type == t.type()) return p.apply(t); } return false; } };
/** * Filters values of vector generator using predicate. * * @param predicate Predicate. * @return Vector generator with filtered vectors. */ public default VectorGenerator filter(IgnitePredicate<Vector> predicate) { return () -> { Vector v = null; do { v = get(); } while (!predicate.apply(v)); return v; }; }
/** * Gets fields. * * @param cls Class. * @return Annotated field. */ public List<Field> fields(Class<?> cls) { assert cls != null; List<Field> fieldsList = fields.get(cls); if (fieldsList == null) { fieldsList = new ArrayList<>(); for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) { List<Field> l = new ArrayList<>(); for (Field f : c.getDeclaredFields()) { if (fp == null || fp.apply(f)) { f.setAccessible(true); l.add(f); } } if (!l.isEmpty()) { Collections.sort(l, FIELD_NAME_COMPARATOR); fieldsList.addAll(l); } } fields.putIfAbsent(cls, fieldsList); } return fieldsList; }
@Override public boolean contains(Object o) { if (!(o instanceof GridCacheMapEntry)) return false; GridCacheMapEntry entry = (GridCacheMapEntry)o; return entry.equals(hld.map.get(entry.key())) && p.apply(entry); } };
/** * @param id Node ID. * @return Whether node belongs to this cluster group. */ private boolean contains(UUID id) { assert id != null; if (ids != null) return ids.contains(id); else { ClusterNode n = ctx.discovery().node(id); return n != null && (p == null || p.apply(n)); } }
/** * @param node Node. * @param filter Node filter. * @return {@code True} if node is not client node and pass given filter. */ public static boolean affinityNode(ClusterNode node, IgnitePredicate<ClusterNode> filter) { return !node.isDaemon() && !node.isClient() && filter.apply(node); }
@Override public void onEvent(Event evt) { if (p == null || p.apply((T)evt)) { fut.onDone((T)evt); removeLocalEventListener(this); } } }, F.isEmpty(types) ? EventType.EVTS_ALL : types);
/** * Gets youngest node out of collection of nodes. * * @param c Collection of nodes. * @return Youngest node. */ public static ClusterNode youngest(Collection<ClusterNode> c, @Nullable IgnitePredicate<ClusterNode> p) { ClusterNode youngest = null; long maxOrder = Long.MIN_VALUE; for (ClusterNode n : c) { if ((p == null || p.apply(n)) && n.order() > maxOrder) { youngest = n; maxOrder = n.order(); } } return youngest; }
/** * Partitions input collection in two: first containing elements for which given * predicate evaluates to {@code true} - and second containing the elements for which * predicate evaluates to {@code false}. * * @param c Input collection. * @param p Partitioning predicate. * @param <V> Type of the collection elements. * @return Tuple of two collections: first containing elements for which given predicate * evaluates to {@code true} - and second containing the elements for which predicate * evaluates to {@code false}. */ @Deprecated public static <V> IgniteBiTuple<Collection<V>, Collection<V>> partition(Iterable<? extends V> c, IgnitePredicate<? super V> p) { A.notNull(c, "c", p, "p"); Collection<V> c1 = new LinkedList<>(); Collection<V> c2 = new LinkedList<>(); for (V v : c) { if (p.apply(v)) c1.add(v); else c2.add(v); } return t(c1, c2); }
/** * Gets oldest node out of collection of nodes. * * @param c Collection of nodes. * @return Oldest node. */ public static ClusterNode oldest(Collection<ClusterNode> c, @Nullable IgnitePredicate<ClusterNode> p) { ClusterNode oldest = null; long minOrder = Long.MAX_VALUE; for (ClusterNode n : c) { if ((p == null || p.apply(n)) && n.order() < minOrder) { oldest = n; minOrder = n.order(); } } return oldest; }
/** {@inheritDoc} */ @Override public void check(ResultSet rs) throws SQLException { int cols = rs.getMetaData().getColumnCount(); while (rs.next()) { Object [] rowObjs = new Object[cols]; for (int i = 0; i < cols; ++i) rowObjs[i] = rs.getObject(i + 1); assert rowPredicate.apply(rowObjs) : "Invalid row. [row=" + Arrays.toString(rowObjs) + ']'; } }
/** * Atomically updates value only if passed in predicate returns {@code true}. * * @param p Predicate to check. * @param update Value to set. * @return {@code True} if value was set. */ public boolean checkAndSet(IgnitePredicate<Long> p, long update) { while (true) { long cur = get(); if (p.apply(cur)) { if (compareAndSet(cur, update)) return true; } else return false; } } }
/** * Atomically updates value only if passed in predicate returns {@code true}. * * @param p Predicate to check. * @param update Value to set. * @return {@code True} if value was set. */ public boolean checkAndSet(IgnitePredicate<Integer> p, int update) { while (true) { int cur = get(); if (p.apply(cur)) { if (compareAndSet(cur, update)) return true; } else return false; } } }