Package org.jfree.data
Class KeyToGroupMap
- java.lang.Object
-
- org.jfree.data.KeyToGroupMap
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,PublicCloneable
public class KeyToGroupMap extends java.lang.Object implements java.lang.Cloneable, PublicCloneable, java.io.Serializable
A class that maps keys (instances ofComparable) to groups.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ComparabledefaultGroupThe default group.private java.util.ListgroupsThe groups.private java.util.MapkeyToGroupMapA mapping between keys and groups.private static longserialVersionUIDFor serialization.
-
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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Returns a clone of the map.private static java.lang.Objectclone(java.lang.Object object)Attempts to clone the specified object using reflection.private static java.util.Collectionclone(java.util.Collection list)Returns a clone of the list.booleanequals(java.lang.Object obj)Tests the map for equality against an arbitrary object.java.lang.ComparablegetGroup(java.lang.Comparable key)Returns the group that a key is mapped to.intgetGroupCount()Returns the number of groups in the map.intgetGroupIndex(java.lang.Comparable group)Returns the index for the group.java.util.ListgetGroups()Returns a list of the groups (always including the default group) in the map.intgetKeyCount(java.lang.Comparable group)Returns the number of keys mapped to the specified group.voidmapKeyToGroup(java.lang.Comparable key, java.lang.Comparable group)Maps a key to a group.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
defaultGroup
private java.lang.Comparable defaultGroup
The default group.
-
groups
private java.util.List groups
The groups.
-
keyToGroupMap
private java.util.Map keyToGroupMap
A mapping between keys and groups.
-
-
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 (nullnot 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 (nullnot 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 (nullnot permitted).group- the group (nullpermitted, 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 (nullnot permitted).- Returns:
- The key count.
-
equals
public boolean equals(java.lang.Object obj)
Tests the map for equality against an arbitrary object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to test against (nullpermitted).- Returns:
- A boolean.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a clone of the map.- Specified by:
clonein interfacePublicCloneable- Overrides:
clonein classjava.lang.Object- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException- if there is a problem cloning the map.
-
clone
private static java.lang.Object clone(java.lang.Object object)
Attempts to clone the specified object using reflection.- Parameters:
object- the object (nullpermitted).- Returns:
- The cloned object, or the original object if cloning failed.
-
clone
private static java.util.Collection clone(java.util.Collection list) throws java.lang.CloneNotSupportedExceptionReturns a clone of the list.- Parameters:
list- the list.- Returns:
- A clone of the list.
- Throws:
java.lang.CloneNotSupportedException- if the list could not be cloned.
-
-