An open API service indexing awesome lists of open source software.

https://github.com/ventralnet/collections-extra

Collections and collections utilities I have written
https://github.com/ventralnet/collections-extra

Last synced: 3 months ago
JSON representation

Collections and collections utilities I have written

Awesome Lists containing this project

README

        

collections-extra
===================

Collections and collections utilities I have written

DefaultValueMap
---------------

DefaultValueMap is a class that extends java.util.HashMap that, when a key does not exist
will return a default value that is provided during construction through a DefaultValueCreator.

For example
```java
DefaultValueCreator zeroLongCreator = new DefaultValueCreator() {
public Long create() {
return 0L;
}
};
DefaultValueMap defaultToZeroMap = new DefaultValueMap(zeroLongCreator);

assertEquals((Long)0L,defaultToZeroMap.get("key_that_does_not_exist"));
```

CountMap
--------

CountMap is a subclass of DefaultValueMap which uses the default value of 0L. CountMap provides a
method .add(K key, Long addend) that will add the addend to the value specified at key.

For example
```java
CountMap countMap = new CountMap();

assertEquals((Long)0L, countMap.get("key_does_not_exist"));
countMap.add("key_does_not_exist",100L);
assertEquals((Long)100L,countMap.get("key_does_not_exist"));
```