コード例 #1
0
  /** {@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;
  }
コード例 #2
0
  /**
   * 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());
    }
  }
コード例 #3
0
  /** {@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);
  }
コード例 #4
0
  /** {@inheritDoc} */
  @Override
  public boolean apply(GridNode n) {
    assert n != null;

    return ids.contains(n.id());
  }
コード例 #5
0
 /** {@inheritDoc} */
 @Override
 public Iterator<UUID> iterator() {
   return ids.iterator();
 }