/** {@inheritDoc} */ @Override public int hashCode() { // Allow for multiple hash calculations to avoid // synchronization cost. Note that array of IDs don't change. if (hash == Integer.MIN_VALUE) hash = ids.hashCode(); return hash; }
/** * Creates node predicate that evaluates to {@code true} for all provided nodes. Implementation * will make a defensive copy. * * @param nodes Optional grid nodes. If none provided - predicate will always return {@code * false}. */ public GridNodePredicate(@Nullable GridNode... nodes) { if (F.isEmpty(nodes)) ids = Collections.emptySet(); else if (nodes.length == 1) ids = Collections.singleton(nodes[0].id()); else { ids = new HashSet<>(nodes.length); for (GridNode n : nodes) ids.add(n.id()); } }
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof GridNodePredicate)) return false; GridNodePredicate it = (GridNodePredicate) o; return ids.equals(it.ids); }
/** {@inheritDoc} */ @Override public boolean apply(GridNode n) { assert n != null; return ids.contains(n.id()); }
/** {@inheritDoc} */ @Override public Iterator<UUID> iterator() { return ids.iterator(); }