Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.ensembl.util
Class FrequencyCounter

    java.lang.Object
      java.util.AbstractMap
          java.util.HashMap
              org.ensembl.util.FrequencyCounter

All Implemented Interfaces:
  java.lang.Cloneable, java.util.Map, java.io.Serializable

public class FrequencyCounter
extends java.util.HashMap

Convenience class that can be used to count the number of times a key is added.

Author:
  Craig Melsopp
See Also:
  Serialized Form

Constructor Summary
`FrequencyCounter()`
`FrequencyCounter(int initialCapacity, float loadFactor)`

Method Summary
`void` | `addOrIncrement(java.lang.Object key)` If object is not currently a key in the map it is added as a key pointing to a Counter instance with a value of 1.
`void` | `addOrIncrementAll(java.util.List list)` Calls addOrIncrement(Object) for each item in list.
`int` | `getCount(java.lang.Object o)` Number of times _o_ has been added to this frequency counter.
`java.lang.Object` | `getMostFrequent()` Returns the most frequently added key.

Methods inherited from class java.util.HashMap
`clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values`

Methods inherited from class java.util.AbstractMap
`equals, hashCode, toString`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.util.Map
`equals, hashCode`

Constructor Detail

### FrequencyCounter

    public FrequencyCounter()

### FrequencyCounter

    public FrequencyCounter(int initialCapacity,
                            float loadFactor)

Parameters:
  `initialCapacity` -
  `loadFactor` -

Method Detail

### addOrIncrement

    public void addOrIncrement(java.lang.Object key)

  If object is not currently a key in the map it is added as a key pointing to a Counter instance with a value of 1.

  Parameters:
    `key` - key to be added or to have it's Counter incremented.
  See Also:
    `Counter`

### getMostFrequent

    public java.lang.Object getMostFrequent()

  Returns the most frequently added key. If two or more keys have been added the same (most) number of times then any of these could be returned.

  Returns:
    most frequent key or null if none in map.

### getCount

    public int getCount(java.lang.Object o)

  Number of times _o_ has been added to this frequency counter.

  Parameters:
    `o` - object.
  Returns:
    frequency that object occured, or 0 if unkown object.

### addOrIncrementAll

    public void addOrIncrementAll(java.util.List list)

  Calls addOrIncrement(Object) for each item in list.

  Parameters:
    `list` - zero or more objects to be added to counter.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD