Class PacketTypeMultiMap<T>

java.lang.Object
com.comphenix.protocol.concurrent.PacketTypeMultiMap<T>
Type Parameters:
T - the type of elements maintained by this map

public class PacketTypeMultiMap<T> extends Object
A map-like data structure that associates PacketTypes with sets of values. The values are stored in a SortedCopyOnWriteSet, which ensures that the elements are kept in a sorted order based on the ListenerPriority of the ListeningWhitelist, while maintaining their insertion order for elements with equal priorities.

This class is thread-safe for modifications and guarantees a modification-free iteration of associated values per packet type. All read methods work on a lock-free, best-effort principle, ensuring fast access.

  • Constructor Details

    • PacketTypeMultiMap

      public PacketTypeMultiMap()
  • Method Details

    • put

      public void put(ListeningWhitelist key, T value)
      Adds a value to the map, associating it with the PacketTypes contained in the specified ListeningWhitelist. If the value is already present in the set (as determined by equals), it will not be added again.
      Parameters:
      key - the whitelist containing the packet types to associate the value with
      value - the value to be added
      Throws:
      NullPointerException - if the key or value is null
    • remove

      public List<PacketType> remove(ListeningWhitelist key, T value)
      Removes a value from the map, disassociating it from the PacketTypes contained in the specified ListeningWhitelist. If the value is not present, the map remains unchanged.
      Parameters:
      key - the whitelist containing the packet types to disassociate the value from
      value - the value to be removed
      Returns:
      a list of packet types that got removed because they don't have any associated values anymore
      Throws:
      NullPointerException - if the key or value is null
    • getPacketTypes

      public com.google.common.collect.ImmutableSet<PacketType> getPacketTypes()
      Returns an immutable set of all PacketTypes currently in the map.
      Returns:
      an immutable set of packet types
    • contains

      public boolean contains(PacketType packetType)
      Checks if a specified PacketType is contained in the map.
      Parameters:
      packetType - the packet type to check for
      Returns:
      true if the packet type is contained in the map, false otherwise
    • get

      public Iterable<T> get(PacketType packetType)
      Returns an iterable of values associated with a specified PacketType. If no values are associated with the packet type, an empty iterator is returned.
      Parameters:
      packetType - the packet type to retrieve values for
      Returns:
      an iterable of values associated with the packet type
    • values

      public Iterable<T> values()
    • clear

      public void clear()
      Clears all entries from the map.