java.lang.Object
net.i2p.router.tunnel.pool.ExcluderBase
All Implemented Interfaces:
Iterable<Hash>, Collection<Hash>, Set<Hash>
Direct Known Subclasses:
ClientPeerSelector.IBGWExcluder, ClientPeerSelector.OBEPExcluder, TunnelPeerSelector.ClosestHopExcluder, TunnelPeerSelector.Excluder

abstract class ExcluderBaseextends Object implements Set<Hash>
A Set of Hashes that automatically adds to the Set in the contains(Object) check.

So we don't need to generate the exclude set up front. Less object churn and copying.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Map<Hash,String>
    Maps peer hash to the reason it was excluded, for diagnostic logging.
    protected final Set<Hash>
    The underlying set of excluded hashes.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Automatically check if peer is connected and add the Hash to the set if not.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(Hash h)
    Add the hash to the underlying set.
    boolean
    addAll(Collection<? extends Hash> c)
    Add all of the hashes to the underlying set.
    void
    Remove all hashes from the underlying set.
    abstract boolean
    Automatically check if peer is allowed and add the Hash to the set if not.
    boolean
    Whether the underlying set contains all of the given hashes.
    boolean
    Whether the underlying set equals the given object.
    protected String
    Format exclusion summary grouped by reason (counts only, no peer hashes).
    int
    The hash code of the underlying set.
    boolean
    Whether the underlying set is empty.
    An iterator over the underlying set.
    protected void
    Record why a peer was excluded, for diagnostic logging.
    boolean
    Remove the hash from the underlying set.
    boolean
    Remove all of the given hashes from the underlying set.
    boolean
    Retain only the given hashes in the underlying set.
    int
    The number of hashes in the underlying set.
    The hashes of the underlying set as an array.
    <Hash> Hash[]
    toArray(Hash[] a)
    The hashes of the underlying set in the given array.
    Description of the excluded set and its size.

    Methods inherited from class Object

    clone, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface Iterable

    forEach

    Methods inherited from interface Set

    spliterator
  • Field Details

    • s

      protected final Set<Hash> s
      The underlying set of excluded hashes.
    • _reasons

      protected final Map<Hash,String> _reasons
      Maps peer hash to the reason it was excluded, for diagnostic logging. Populated by subclasses via recordExclusion(Hash, String).
  • Constructor Details

    • ExcluderBase

      protected ExcluderBase(Set<Hash> set)
      Automatically check if peer is connected and add the Hash to the set if not.
      Parameters:
      set - not copied, contents will be modified by all methods
  • Method Details

    • contains

      public abstract boolean contains(Object o)
      Automatically check if peer is allowed and add the Hash to the set if not.
      Specified by:
      contains in interface Collection<Hash>
      Specified by:
      contains in interface Set<Hash>
      Parameters:
      o - a peer hash to look up in the underlying set
      Returns:
      true if peer should be excluded
    • add

      public boolean add(Hash h)
      Add the hash to the underlying set.
      Specified by:
      add in interface Collection<Hash>
      Specified by:
      add in interface Set<Hash>
    • addAll

      public boolean addAll(Collection<? extends Hash> c)
      Add all of the hashes to the underlying set.
      Specified by:
      addAll in interface Collection<Hash>
      Specified by:
      addAll in interface Set<Hash>
    • clear

      public void clear()
      Remove all hashes from the underlying set.
      Specified by:
      clear in interface Collection<Hash>
      Specified by:
      clear in interface Set<Hash>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Whether the underlying set contains all of the given hashes.
      Specified by:
      containsAll in interface Collection<Hash>
      Specified by:
      containsAll in interface Set<Hash>
    • equals

      public boolean equals(Object o)
      Whether the underlying set equals the given object.
      Specified by:
      equals in interface Collection<Hash>
      Specified by:
      equals in interface Set<Hash>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      The hash code of the underlying set.
      Specified by:
      hashCode in interface Collection<Hash>
      Specified by:
      hashCode in interface Set<Hash>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • isEmpty

      public boolean isEmpty()
      Whether the underlying set is empty.
      Specified by:
      isEmpty in interface Collection<Hash>
      Specified by:
      isEmpty in interface Set<Hash>
      Returns:
      true if nothing is currently excluded
    • iterator

      public Iterator<Hash> iterator()
      An iterator over the underlying set.
      Specified by:
      iterator in interface Collection<Hash>
      Specified by:
      iterator in interface Iterable<Hash>
      Specified by:
      iterator in interface Set<Hash>
    • remove

      public boolean remove(Object o)
      Remove the hash from the underlying set.
      Specified by:
      remove in interface Collection<Hash>
      Specified by:
      remove in interface Set<Hash>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Remove all of the given hashes from the underlying set.
      Specified by:
      removeAll in interface Collection<Hash>
      Specified by:
      removeAll in interface Set<Hash>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Retain only the given hashes in the underlying set.
      Specified by:
      retainAll in interface Collection<Hash>
      Specified by:
      retainAll in interface Set<Hash>
    • size

      public int size()
      The number of hashes in the underlying set.
      Specified by:
      size in interface Collection<Hash>
      Specified by:
      size in interface Set<Hash>
    • toArray

      public Object[] toArray()
      The hashes of the underlying set as an array.
      Specified by:
      toArray in interface Collection<Hash>
      Specified by:
      toArray in interface Set<Hash>
    • toArray

      public <Hash> Hash[] toArray(Hash[] a)
      The hashes of the underlying set in the given array.
      Specified by:
      toArray in interface Collection<Hash>
      Specified by:
      toArray in interface Set<Hash>
    • recordExclusion

      protected void recordExclusion(Hash h, String reason)
      Record why a peer was excluded, for diagnostic logging. Each peer is recorded once; subsequent calls for the same peer overwrite the earlier reason.
      Parameters:
      h - the excluded peer
      reason - short reason string like "unreachable" or "not-ibgw"
    • getReasonsSummary

      protected String getReasonsSummary()
      Format exclusion summary grouped by reason (counts only, no peer hashes). Uses raw reason strings from _reasons.
      Returns:
      string like "128 excluded \n* Reason: 50 unreachable, 30 not-ibgw"
    • toString

      public String toString()
      Description of the excluded set and its size.
      Overrides:
      toString in class Object