Package com.gengoai.collection.counter
Class MultiCounters
- java.lang.Object
-
- com.gengoai.collection.counter.MultiCounters
-
public final class MultiCounters extends Object
Common methods for reading multi-counters from structured files, creating synchronized and unmodifiable wrappers.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K1,K2>
MultiCounter<K1,K2>newConcurrentMultiCounter(MultiCounter<K1,K2> multiCounter)
Creates a new ConcurrentHashMapMultiCounter using the given multi counter.static <K1,K2>
MultiCounter<K1,K2>newConcurrentMultiCounter(Iterable<? extends Map.Entry<? extends K1,? extends K2>> entries)
Creates a new ConcurrentHashMapMultiCounter using the given map entries.static <K1,K2>
MultiCounter<K1,K2>newConcurrentMultiCounter(Map.Entry<? extends K1,? extends K2>... entries)
Creates a new ConcurrentHashMapMultiCounter using the given map entries.static <K1,K2>
MultiCounter<K1,K2>newConcurrentMultiCounter(Map<? extends Map.Entry<? extends K1,? extends K2>,? extends Number> map)
Creates a new ConcurrentHashMapMultiCounter using the given map.static <K1,K2>
MultiCounter<K1,K2>newMultiCounter(MultiCounter<? extends K1,? extends K2> counter)
Creates a copy of the specified multi-counterstatic <K1,K2>
MultiCounter<K1,K2>newMultiCounter(Iterable<? extends Map.Entry<? extends K1,? extends K2>> entries)
Creates a new MultiCounter using the given map entries.static <K1,K2>
MultiCounter<K1,K2>newMultiCounter(Map.Entry<? extends K1,? extends K2>... entries)
Creates a new MultiCounter using the given map entries.static <K1,K2>
MultiCounter<K1,K2>newMultiCounter(Map<? extends Map.Entry<? extends K1,? extends K2>,? extends Number> map)
Creates a new MultiCounter using the given map.static <K1,K2>
MultiCounter<K1,K2>readCsv(Resource resource, Class<K1> key1Class, Class<K2> key2Class)
Reads a multi-counter from a CSV file.
-
-
-
Method Detail
-
newMultiCounter
public static <K1,K2> MultiCounter<K1,K2> newMultiCounter(MultiCounter<? extends K1,? extends K2> counter)
Creates a copy of the specified multi-counter- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
counter
- the counter to copy- Returns:
- A new MultiCounter that is a copy of the given MultiCounter
-
newMultiCounter
@SafeVarargs public static <K1,K2> MultiCounter<K1,K2> newMultiCounter(Map.Entry<? extends K1,? extends K2>... entries)
Creates a new MultiCounter using the given map entries.- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
entries
- the entries to increment in the counter.- Returns:
- A new MultiCounter with counts of the given entries
-
newMultiCounter
public static <K1,K2> MultiCounter<K1,K2> newMultiCounter(Iterable<? extends Map.Entry<? extends K1,? extends K2>> entries)
Creates a new MultiCounter using the given map entries.- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
entries
- the entries to increment in the counter.- Returns:
- A new MultiCounter with counts of the given entries
-
newMultiCounter
public static <K1,K2> MultiCounter<K1,K2> newMultiCounter(Map<? extends Map.Entry<? extends K1,? extends K2>,? extends Number> map)
Creates a new MultiCounter using the given map.- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
map
- A map whose keys are the entries of the counter and values are the counts.- Returns:
- A new MultiCounter with counts of the given entries
-
newConcurrentMultiCounter
public static <K1,K2> MultiCounter<K1,K2> newConcurrentMultiCounter(MultiCounter<K1,K2> multiCounter)
Creates a new ConcurrentHashMapMultiCounter using the given multi counter.
- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
multiCounter
- the multi counter to wrap- Returns:
- the synchronized multi-counter
-
newConcurrentMultiCounter
@SafeVarargs public static <K1,K2> MultiCounter<K1,K2> newConcurrentMultiCounter(Map.Entry<? extends K1,? extends K2>... entries)
Creates a new ConcurrentHashMapMultiCounter using the given map entries.- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
entries
- the entries to increment in the counter.- Returns:
- A new MultiCounter with counts of the given entries
-
newConcurrentMultiCounter
public static <K1,K2> MultiCounter<K1,K2> newConcurrentMultiCounter(Iterable<? extends Map.Entry<? extends K1,? extends K2>> entries)
Creates a new ConcurrentHashMapMultiCounter using the given map entries.- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
entries
- the entries to increment in the counter.- Returns:
- A new MultiCounter with counts of the given entries
-
newConcurrentMultiCounter
public static <K1,K2> MultiCounter<K1,K2> newConcurrentMultiCounter(Map<? extends Map.Entry<? extends K1,? extends K2>,? extends Number> map)
Creates a new ConcurrentHashMapMultiCounter using the given map.- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
map
- A map whose keys are the entries of the counter and values are the counts.- Returns:
- A new MultiCounter with counts of the given entries
-
readCsv
public static <K1,K2> MultiCounter<K1,K2> readCsv(Resource resource, Class<K1> key1Class, Class<K2> key2Class) throws IOException
Reads a multi-counter from a CSV file.
- Type Parameters:
K1
- the component type of the first keyK2
- the component type of the second key- Parameters:
resource
- the resource that the counter values are read from.key1Class
- the class of first keykey2Class
- the class of the second key- Returns:
- the new MultiCounter
- Throws:
IOException
- Something went wrong reading in the counter.
-
-