Package com.jalios.util
Class ObjectIntTreeMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.TreeMap
-
- com.jalios.util.ObjectIntTreeMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map
,java.util.NavigableMap
,java.util.SortedMap
public class ObjectIntTreeMap extends java.util.TreeMap
This class is a map which binds key Object to int value.This class is NOT thread safe, synchronize read and write operation when used in multi-threaded context if you really need features provided by this collection.
In multithreaded context, it may be wiser to use alternative thread safe and type safe collection such asConcurrentHashMap<YourType, Integer>
.- Version:
- $Revision: 107554 $
- Author:
- Olivier Dedieu
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ObjectIntTreeMap.GreaterComparator
A Comparator that sort TreeMap of ObjectIntTreeMap by Max Valueprotected static class
ObjectIntTreeMap.KeyComparator
A Comparator that sort TreeMap of ObjectIntTreeMap by Key Valueprotected static class
ObjectIntTreeMap.LowerComparator
A Comparator that sort TreeMap of ObjectIntTreeMap by Min Valuestatic class
ObjectIntTreeMap.ObjectComparator
A Comparator that allow ObjectyIntTreeMap to sort multiple kind of Objectprotected static class
ObjectIntTreeMap.SortedKeyComparator
A Comparator that sort TreeMap of ObjectIntTreeMap by Key Value sorted using a sorted List
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
REVISION
-
Constructor Summary
Constructors Constructor Description ObjectIntTreeMap()
Default convenient constructorObjectIntTreeMap(ObjectIntTreeMap oitm)
A constructor working with a comparatorObjectIntTreeMap(java.util.Comparator c)
A constructor working with a comparator
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getAverage()
Return the Average value of the Map or 0 if Map is Emptyint
getAverage(int level)
Return the Average value of the Map or 0 if Map is Emptyint
getAverageCount()
Return the Average value of the Map or 0 if Map is Emptyint
getAverageCount(int level)
Return the Average value of the Map or 0 if Map is Emptyint
getAverageCount(int level, int deep)
Return the Average value of the Map or 0 if Map is Emptyint
getAverageSum()
This method sum all average at level N-1ObjectIntTreeMap
getConsolidatedMap(int level)
This method return an ObjectIntTreeMap consolidated at a given level.protected ObjectIntTreeMap
getConsolidatedMap(int level, ObjectIntTreeMap workingMap)
int
getCount()
Return the Count value of the Map or Integer.MIN_VALUE if Map is Emptyint
getCount(int level)
Return the Count value of the Map or 0 if Map is Emptyint
getCount(int level, int boundary)
Return the Count value of the Map or 0 if Map is Emptyint
getCount(int level, int boundary, int single)
Return the Count value of the Map or 0 if Map is Emptystatic java.util.Comparator
getGreaterComparator()
Sort ObjectIntTreeMap from larger to smallerint
getInt(java.lang.Object key, int defaultValue)
Returns the value to which this map maps the specified key.static java.util.Comparator
getLowerComparator()
Sort ObjectIntTreeMap from smaller to largerint
getMax()
Return the Max value of the Map or Integer.MIN_VALUE if Map is Emptyint
getMax(int level)
Return the Max value of the Map or Integer.MIN_VALUE if Map is Emptyint
getMaxCount()
Return the Max size value of the Map or Integer.MIN_VALUE if Map is Emptyint
getMaxCount(int level)
Return the Max value of the Map or Integer.MIN_VALUE if Map is Emptyint
getMaxCount(int level, int deep)
Return the Max size value of the Map or Integer.MIN_VALUE if Map is Empty Map A > Map B > Map C level: 0 deep : 1 will count min C between Aint
getMin()
Return the Min value of the Map or Integer.MAX_VALUE if Map is Emptyint
getMin(int level)
Return the Min value of the Map or Integer.MAX_VALUE if Map is Emptyint
getMinCount()
Return the Min size value of the Map or Integer.MAX_VALUE if Map is Emptyint
getMinCount(int level)
Return the Min value of the Map or Integer.MAX_VALUE if Map is Emptyint
getMinCount(int level, int deep)
Return the Min size value of the Map or Integer.MAX_VALUE if Map is Emptystatic java.util.Comparator
getSortedKeyComparator(java.lang.String[] sort)
Sort ObjectIntTreeMap ordered by a predifined Liststatic java.util.Comparator
getSortedKeyComparator(java.util.List sort)
Sort ObjectIntTreeMap ordered by a predifined Liststatic java.util.SortedSet
getSortedMapEntrySet(java.util.Map map, java.util.Comparator comparator)
This method return a Sorted Set of Map.Entryint
getSum()
Return the Sum value of the Map or 0 if Map is Emptyint
getSum(int level, java.lang.String key)
Return the sum of a given key at a given levelint
getSum(int level, java.util.Set keySet, java.util.Map map)
Return the sum of given keys at a given levelvoid
inc(java.lang.Object key)
Increments the value associated with the specified key.void
inc(java.lang.Object key, int quantity)
Incremente the value associated with the specified key.void
inc(java.lang.String key, ObjectIntTreeMap map)
Increments the value associated with the specified key.void
incAll(ObjectIntTreeMap map)
Incremente all the values of the specified ObjectIntTreeMap.boolean
isMultiMap()
Return true if the ObjectIntTreeMap contains ObjectIntTreeMap Return false if the ObjectIntTreeMap contains int[]void
put(java.lang.Object key, int value)
Associates the specified value with the specified key in this map.java.lang.String
toString()
Special implementation of toString()-
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
-
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ObjectIntTreeMap
public ObjectIntTreeMap()
Default convenient constructor
-
ObjectIntTreeMap
public ObjectIntTreeMap(java.util.Comparator c)
A constructor working with a comparator- Parameters:
c
- the Comparator
-
ObjectIntTreeMap
public ObjectIntTreeMap(ObjectIntTreeMap oitm)
A constructor working with a comparator- Parameters:
oitm
- the Comparator
-
-
Method Detail
-
put
public void put(java.lang.Object key, int value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.- Parameters:
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
-
inc
public void inc(java.lang.Object key, int quantity)
Incremente the value associated with the specified key. If this key did not exist, it is created and the value is set to quantity.- Parameters:
key
- key for which the specified value must be incremented.quantity
- the quantity to increment
-
incAll
public void incAll(ObjectIntTreeMap map)
Incremente all the values of the specified ObjectIntTreeMap. If a key did not exist, it is created and the value is set to quantity. If the value is an ObjectIntTreeMap the job is done recursively.- Parameters:
map
- ObjectIntTreeMap to work with
-
inc
public void inc(java.lang.String key, ObjectIntTreeMap map)
Increments the value associated with the specified key. If this key did not exist, it is create.- Parameters:
key
- key for which the specified value must be incremented.map
- the ObjectIntTreeMap to inc with
-
inc
public void inc(java.lang.Object key)
Increments the value associated with the specified key. If this key did not exist, it is created and the value is set to '1'.- Parameters:
key
- key for which the specified value must be incremented.
-
getInt
public int getInt(java.lang.Object key, int defaultValue)
Returns the value to which this map maps the specified key. ReturnsdefaultValue
if the map contains no mapping for this key.- Parameters:
key
- key whose associated value is to be returned.defaultValue
- value to return if the map contains no mapping for this key.- Returns:
- the value to which this map maps the specified key, or
defaultValue
if the map contains no mapping for this key.
-
getAverage
public int getAverage(int level)
Return the Average value of the Map or 0 if Map is Empty- Parameters:
level
- the max depth of Maps- Returns:
- int the level
- Since:
- jcms-4.2
-
getAverage
public int getAverage()
Return the Average value of the Map or 0 if Map is Empty- Since:
- jcms-4.2
-
getAverageCount
public int getAverageCount(int level)
Return the Average value of the Map or 0 if Map is Empty- Parameters:
level
- the max depth of Maps- Returns:
- int the level
- Since:
- jcms-5.0.3
-
getAverageCount
public int getAverageCount(int level, int deep)
Return the Average value of the Map or 0 if Map is Empty- Parameters:
level
- the max depth of Mapsdeep
- the level to count- Returns:
- int the level
- Since:
- jcms-5.0.3
-
getAverageCount
public int getAverageCount()
Return the Average value of the Map or 0 if Map is Empty- Since:
- jcms-5.0.3
-
getCount
public int getCount(int level, int boundary)
Return the Count value of the Map or 0 if Map is Empty- Parameters:
level
- the count depth of Mapsboundary
- the max value to return- Returns:
- int the count
- Since:
- jcms-5.0.2
-
getCount
public int getCount(int level, int boundary, int single)
Return the Count value of the Map or 0 if Map is Empty- Parameters:
level
- the count depth of Mapsboundary
- the max value to returnsingle
- the level where to get single content (remove duplicate)- Returns:
- int the count
- Since:
- jcms-5.0.2
-
getCount
public int getCount(int level)
Return the Count value of the Map or 0 if Map is Empty- Parameters:
level
- the count depth of Maps- Returns:
- int the count
- Since:
- jcms-4.2
-
getCount
public int getCount()
Return the Count value of the Map or Integer.MIN_VALUE if Map is Empty- Returns:
- int the count
- Since:
- jcms-4.2
-
getSum
public int getSum()
Return the Sum value of the Map or 0 if Map is Empty- Returns:
- int the sum
- Since:
- jcms-4.2
-
getSum
public int getSum(int level, java.lang.String key)
Return the sum of a given key at a given level- Parameters:
level
- the working levelkey
- the working key- Returns:
- int the sum
-
getSum
public int getSum(int level, java.util.Set keySet, java.util.Map map)
Return the sum of given keys at a given level- Parameters:
level
- the working levelkeySet
- the working keymap
- the working map- Returns:
- int the sum
-
getAverageSum
public int getAverageSum()
This method sum all average at level N-1- Returns:
- int the sum of average
-
getMax
public int getMax(int level)
Return the Max value of the Map or Integer.MIN_VALUE if Map is Empty- Parameters:
level
- the max depth of Maps- Returns:
- int the max
- Since:
- jcms-4.2
-
isMultiMap
public boolean isMultiMap()
Return true if the ObjectIntTreeMap contains ObjectIntTreeMap Return false if the ObjectIntTreeMap contains int[]- Returns:
- boolean
-
getMax
public int getMax()
Return the Max value of the Map or Integer.MIN_VALUE if Map is Empty- Returns:
- int the max
- Since:
- jcms-4.2
-
getMaxCount
public int getMaxCount(int level)
Return the Max value of the Map or Integer.MIN_VALUE if Map is Empty- Parameters:
level
- the max depth of Maps- Returns:
- int the max
- Since:
- jcms-5.0.3
-
getMaxCount
public int getMaxCount(int level, int deep)
Return the Max size value of the Map or Integer.MIN_VALUE if Map is Empty Map A > Map B > Map C level: 0 deep : 1 will count min C between A- Parameters:
level
- the max depth of Mapsdeep
- the depth to count on- Returns:
- int the max
- Since:
- jcms-5.0.3
-
getMaxCount
public int getMaxCount()
Return the Max size value of the Map or Integer.MIN_VALUE if Map is Empty- Since:
- jcms-5.0.3
-
getMin
public int getMin(int level)
Return the Min value of the Map or Integer.MAX_VALUE if Map is Empty- Parameters:
level
- the max depth of Maps- Returns:
- int the min
- Since:
- jcms-4.2
-
getMin
public int getMin()
Return the Min value of the Map or Integer.MAX_VALUE if Map is Empty- Returns:
- int the min
- Since:
- jcms-4.2
-
getMinCount
public int getMinCount(int level)
Return the Min value of the Map or Integer.MAX_VALUE if Map is Empty- Parameters:
level
- the max depth of Maps- Returns:
- int the min
- Since:
- jcms-5.0.3
-
getMinCount
public int getMinCount(int level, int deep)
Return the Min size value of the Map or Integer.MAX_VALUE if Map is Empty- Parameters:
level
-- Returns:
- int the min count
- Since:
- jcms-5.0.3
-
getMinCount
public int getMinCount()
Return the Min size value of the Map or Integer.MAX_VALUE if Map is Empty- Returns:
- int the min count
- Since:
- jcms-5.0.3
-
getSortedMapEntrySet
public static java.util.SortedSet getSortedMapEntrySet(java.util.Map map, java.util.Comparator comparator)
This method return a Sorted Set of Map.Entry- Parameters:
map
- a TreeMap that is an ObjectIntTreeMap or composed by ObjectIntTreeMap.comparator
- the comparator to sort objects.- Returns:
- SortedSet of Map.Entry
- Since:
- jcms-4.2
-
getConsolidatedMap
protected ObjectIntTreeMap getConsolidatedMap(int level, ObjectIntTreeMap workingMap)
- Parameters:
level
- the map level to consolidateworkingMap
- the map to work with- Returns:
- an ObjectIntTreeMap
- See Also:
getConsolidatedMap(int)
-
getConsolidatedMap
public ObjectIntTreeMap getConsolidatedMap(int level)
This method return an ObjectIntTreeMap consolidated at a given level. [Key1 , Key2 , Key3, Key4] [Key2.1, Key2.2, Key2.3, Key2.4] [Key2.2.1, Key2.2.2, Key2.2.3, Key2.2.4] [Val2.2.1, Val2.2.1, Val2.2.1, Val2.2.1] With level=1, this method return a new Map with values of Keyx.y replaced by consolidated values of keys Keyx.y.z- Parameters:
level
- the map level to consolidate- Returns:
- an ObjectIntTreeMap
-
toString
public java.lang.String toString()
Special implementation of toString()- Overrides:
toString
in classjava.util.AbstractMap
-
getGreaterComparator
public static java.util.Comparator getGreaterComparator()
Sort ObjectIntTreeMap from larger to smaller
-
getLowerComparator
public static java.util.Comparator getLowerComparator()
Sort ObjectIntTreeMap from smaller to larger
-
getSortedKeyComparator
public static java.util.Comparator getSortedKeyComparator(java.util.List sort)
Sort ObjectIntTreeMap ordered by a predifined List
-
getSortedKeyComparator
public static java.util.Comparator getSortedKeyComparator(java.lang.String[] sort)
Sort ObjectIntTreeMap ordered by a predifined List
-
-