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
- Host: GitHub
- URL: https://github.com/ventralnet/collections-extra
- Owner: ventralnet
- License: apache-2.0
- Created: 2014-02-05T21:45:12.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-27T11:35:01.000Z (over 11 years ago)
- Last Synced: 2025-01-21T21:31:16.064Z (5 months ago)
- Language: Java
- Size: 188 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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"));
```