Class KeyToGroupMap

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.jfree.util.PublicCloneable

    public class KeyToGroupMap
    extends java.lang.Object
    implements java.lang.Cloneable, org.jfree.util.PublicCloneable, java.io.Serializable
    A class that maps keys (instances of Comparable) to groups.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyToGroupMap()
      Creates a new map with a default group named 'Default Group'.
      KeyToGroupMap​(java.lang.Comparable defaultGroup)
      Creates a new map with the specified default group.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Returns a clone of the map.
      boolean equals​(java.lang.Object obj)
      Tests the map for equality against an arbitrary object.
      java.lang.Comparable getGroup​(java.lang.Comparable key)
      Returns the group that a key is mapped to.
      int getGroupCount()
      Returns the number of groups in the map.
      int getGroupIndex​(java.lang.Comparable group)
      Returns the index for the group.
      java.util.List getGroups()
      Returns a list of the groups (always including the default group) in the map.
      int getKeyCount​(java.lang.Comparable group)
      Returns the number of keys mapped to the specified group.
      void mapKeyToGroup​(java.lang.Comparable key, java.lang.Comparable group)
      Maps a key to a group.
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeyToGroupMap

        public KeyToGroupMap()
        Creates a new map with a default group named 'Default Group'.
      • KeyToGroupMap

        public KeyToGroupMap​(java.lang.Comparable defaultGroup)
        Creates a new map with the specified default group.
        Parameters:
        defaultGroup - the default group (null not permitted).
    • Method Detail

      • getGroupCount

        public int getGroupCount()
        Returns the number of groups in the map.
        Returns:
        The number of groups in the map.
      • getGroups

        public java.util.List getGroups()
        Returns a list of the groups (always including the default group) in the map. The returned list is independent of the map, so altering the list will have no effect.
        Returns:
        The groups (never null).
      • getGroupIndex

        public int getGroupIndex​(java.lang.Comparable group)
        Returns the index for the group.
        Parameters:
        group - the group.
        Returns:
        The group index (or -1 if the group is not represented within the map).
      • getGroup

        public java.lang.Comparable getGroup​(java.lang.Comparable key)
        Returns the group that a key is mapped to.
        Parameters:
        key - the key (null not permitted).
        Returns:
        The group (never null, returns the default group if there is no mapping for the specified key).
      • mapKeyToGroup

        public void mapKeyToGroup​(java.lang.Comparable key,
                                  java.lang.Comparable group)
        Maps a key to a group.
        Parameters:
        key - the key (null not permitted).
        group - the group (null permitted, clears any existing mapping).
      • getKeyCount

        public int getKeyCount​(java.lang.Comparable group)
        Returns the number of keys mapped to the specified group. This method won't always return an accurate result for the default group, since explicit mappings are not required for this group.
        Parameters:
        group - the group (null not permitted).
        Returns:
        The key count.
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests the map for equality against an arbitrary object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to test against (null permitted).
        Returns:
        A boolean.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone of the map.
        Specified by:
        clone in interface org.jfree.util.PublicCloneable
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - if there is a problem cloning the map.