Class Counters


  • public final class Counters
    extends Object
    Common methods for reading counters from structured files, creating synchronized and unmodifiable wrappers.
    • Method Detail

      • newCounter

        @SafeVarargs
        public static <T> Counter<T> newCounter​(T... items)

        Creates a new HashMapMultiCounter which is initialized with the given items

        Type Parameters:
        T - the component type of the counter
        Parameters:
        items - the items to add to the counter
        Returns:
        the counter
      • newCounter

        public static <T> Counter<T> newCounter​(Iterable<? extends T> iterable)

        Creates a new HashMapMultiCounter which is initialized with the given items

        Type Parameters:
        T - the component type of the counter
        Parameters:
        iterable - the items to add to the counter
        Returns:
        the counter
      • newCounter

        public static <T> Counter<T> newCounter​(Stream<? extends T> stream)

        Creates a new HashMapMultiCounter which is initialized with the given items

        Type Parameters:
        T - the component type of the counter
        Parameters:
        stream - the items to add to the counter
        Returns:
        the counter
      • newCounter

        public static <T> Counter<T> newCounter​(Map<? extends T,​? extends Number> map)

        Creates a new HashMapMultiCounter which is initialized by merging with the given map

        Type Parameters:
        T - the component type of the counter
        Parameters:
        map - the items and counts to merge with counter
        Returns:
        the counter
      • newCounter

        public static <T> Counter<T> newCounter​(Counter<? extends T> other)

        Creates a new HashMapMultiCounter which is initialized by merging with the given counter

        Type Parameters:
        T - the component type of the counter
        Parameters:
        other - the items and counts to merge with counter
        Returns:
        the counter
      • readCsv

        public static <TYPE> Counter<TYPE> readCsv​(Resource resource,
                                                   Class<TYPE> keyClass)
                                            throws IOException

        Reads a counter from a CSV file.

        Type Parameters:
        TYPE - the component type of the counter
        Parameters:
        resource - the resource that the counter values are read from.
        keyClass - the class of the item type
        Returns:
        the counter
        Throws:
        IOException - Something went wrong reading in the counter.
      • newConcurrentCounter

        public static <TYPE> Counter<TYPE> newConcurrentCounter​(Counter<TYPE> counter)

        Wraps a counter making each method call synchronized.

        Type Parameters:
        TYPE - the item type
        Parameters:
        counter - the counter to wrap
        Returns:
        the wrapped counter
      • newConcurrentCounter

        @SafeVarargs
        public static <T> Counter<T> newConcurrentCounter​(T... items)

        Creates a new ConcurrentHashMapCounter which is initialized with the given items

        Type Parameters:
        T - the component type of the counter
        Parameters:
        items - the items to add to the counter
        Returns:
        the counter
      • newConcurrentCounter

        public static <T> Counter<T> newConcurrentCounter​(Map<? extends T,​? extends Number> map)

        Creates a new ConcurrentHashMapCounter which is initialized by merging with the given map

        Type Parameters:
        T - the component type of the counter
        Parameters:
        map - the items and counts to merge with counter
        Returns:
        the counter
      • newConcurrentCounter

        public static <T> Counter<T> newConcurrentCounter​(Iterable<? extends T> iterable)

        Creates a new ConcurrentHashMapCounter which is initialized with the given items

        Type Parameters:
        T - the component type of the counter
        Parameters:
        iterable - the items to add to the counter
        Returns:
        the counter
      • newConcurrentCounter

        public static <T> Counter<T> newConcurrentCounter​(Stream<? extends T> stream)

        Creates a new ConcurrentHashMapCounter which is initialized with the given items

        Type Parameters:
        T - the component type of the counter
        Parameters:
        stream - the items to add to the counter
        Returns:
        the counter