public final class Bind extends Object
java.util.* collections (if they are thread safe) to get additional speed.
There are many [code examples](https://github.com/jankotek/MapDB/tree/master/src/test/java/examples)
how Collection Binding can be used.
NOTE: Binding just installs Modification Listener on primary collection. Binding itself is not persistent
and has to be restored after primary collection is loaded. Data contained in secondary collection are persistent.| Modifier and Type | Class and Description |
|---|---|
static interface |
Bind.MapListener<K,V>
Listener called when
Map is modified. |
static interface |
Bind.MapWithModificationListener<K,V>
Primary Maps must provide notifications when it is modified.
|
| Modifier and Type | Method and Description |
|---|---|
static <K,V,C> void |
histogram(Bind.MapWithModificationListener<K,V> primary,
ConcurrentMap<C,Long> histogram,
Fun.Function2<C,K,V> entryToCategory)
Binds Secondary Map so it it creates [histogram](http://en.wikipedia.org/wiki/Histogram) from
data in Primary Map.
|
static <K,V> void |
mapInverse(Bind.MapWithModificationListener<K,V> primary,
Map<V,K> inverse)
Binds Secondary Set so it contains inverse mapping to Primary Map: Primary Value will become Secondary Key.
|
static <K,V> void |
mapInverse(Bind.MapWithModificationListener<K,V> primary,
Set<Object[]> inverse)
Binds Secondary Set so it contains inverse mapping to Primary Map: Primary Value will become Secondary Key.
|
static <K,V> void |
mapPutAfterDelete(Bind.MapWithModificationListener<K,V> primary,
Bind.MapWithModificationListener<K,V> secondary,
boolean overwriteSecondary)
After key is removed from primary for some reason (map.remove, or expiration in
HTreeMap),
it gets moved into secondary collection. |
static <K,V,K2> void |
secondaryKey(Bind.MapWithModificationListener<K,V> map,
Map<K2,K> secondary,
Fun.Function2<K2,K,V> fun)
Binds Secondary Set so it contains Secondary Key (Index).
|
static <K,V,K2> void |
secondaryKey(Bind.MapWithModificationListener<K,V> map,
Set<Object[]> secondary,
Fun.Function2<K2,K,V> fun)
Binds Secondary Set so it contains Secondary Key (Index).
|
static <K,V,K2> void |
secondaryKeys(Bind.MapWithModificationListener<K,V> map,
Set<Object[]> secondary,
Fun.Function2<K2[],K,V> fun)
Binds Secondary Set so it contains Secondary Key (Index).
|
static <K,V,V2> void |
secondaryValue(Bind.MapWithModificationListener<K,V> map,
Map<K,V2> secondary,
Fun.Function2<V2,K,V> fun)
Binds Secondary Map so that it contains Key from Primary Map and custom Value.
|
static <K,V,V2> void |
secondaryValues(Bind.MapWithModificationListener<K,V> map,
Set<Object[]> secondary,
Fun.Function2<V2[],K,V> fun)
Binds Secondary Map so that it contains Key from Primary Map and custom Value.
|
static <K,V> void |
size(Bind.MapWithModificationListener<K,V> map,
Atomic.Long sizeCounter)
Binds
Atomic.Long to Primary Map so the Atomic.Long contains size of Map. |
public static <K,V> void size(Bind.MapWithModificationListener<K,V> map, Atomic.Long sizeCounter)
Atomic.Long to Primary Map so the Atomic.Long contains size of Map.
Atomic.Long is incremented on each insert and decremented on each entry removal.
MapDB collections usually do not keep their size, but require complete traversal to count items.
If Atomic.Long has zero value, it will be updated with value from map.size() and than
bind to map.
NOTE: Binding just installs Modification Listener on primary collection. Binding itself is not persistent
and has to be restored after primary collection is loaded. Data contained in secondary collection are persistent.
NOTE: BTreeMap and HTreeMap already supports this directly as optional parameter named counter.
In that case all calls to Map.size() are forwarded to underlying counter. Check parameters at
DB.hashMapCreate(String) and
DB.treeMapCreate(String)K - type of key in mapV - type of value in mapmap - primary map whose size needs to be trackedsizeCounter - number updated when Map Entry is added or removed.public static <K,V,V2> void secondaryValue(Bind.MapWithModificationListener<K,V> map, Map<K,V2> secondary, Fun.Function2<V2,K,V> fun)
K - - key type in primary and Secondary MapV - - value type in Primary MapV2 - - value type in Secondary Mapmap - Primary Mapsecondary - Secondary Map with customfun - function which calculates secondary value from primary key and valuepublic static <K,V,V2> void secondaryValues(Bind.MapWithModificationListener<K,V> map, Set<Object[]> secondary, Fun.Function2<V2[],K,V> fun)
K - - key type in primary and Secondary MapV - - value type in Primary MapV2 - - value type in Secondary Map
.map - Primary Mapsecondary - Secondary Map with customfun - function which calculates secondary values from primary key and valuepublic static <K,V,K2> void secondaryKey(Bind.MapWithModificationListener<K,V> map, Set<Object[]> secondary, Fun.Function2<K2,K,V> fun)
Fun.filter(java.util.NavigableSet, Object[])
If Secondary Set is empty its content will be recreated from Primary Map.
This binding is not persistent. You need to restore it every time store is reopened.
NOTE: Binding just installs Modification Listener on primary collection. Binding itself is not persistent
and has to be restored after primary collection is loaded. Data contained in secondary collection are persistent.
Type params:K - - Key in Primary MapV - - Value in Primary MapK2 - - Secondarymap - primary mapsecondary - secondary setfun - function which calculates Secondary Key from Primary Key and Valuepublic static <K,V,K2> void secondaryKey(Bind.MapWithModificationListener<K,V> map, Map<K2,K> secondary, Fun.Function2<K2,K,V> fun)
K - - Key in Primary MapV - - Value in Primary MapK2 - - Secondarymap - primary mapsecondary - secondary setfun - function which calculates Secondary Key from Primary Key and Valuepublic static <K,V,K2> void secondaryKeys(Bind.MapWithModificationListener<K,V> map, Set<Object[]> secondary, Fun.Function2<K2[],K,V> fun)
Fun.filter(java.util.NavigableSet, Object[])}
If Secondary Set is empty its content will be recreated from Primary Map.
NOTE: Binding just installs Modification Listener on primary collection. Binding itself is not persistent
and has to be restored after primary collection is loaded. Data contained in secondary collection are persistent.
Type params:K - - Key in Primary MapV - - Value in Primary MapK2 - - Secondarymap - primary mapsecondary - secondary setfun - function which calculates Secondary Keys from Primary Key and Valuepublic static <K,V> void mapInverse(Bind.MapWithModificationListener<K,V> primary, Set<Object[]> inverse)
Fun.filter(java.util.NavigableSet, Object[])
If Secondary Set is empty its content will be recreated from Primary Map.
NOTE: Binding just installs Modification Listener on primary collection. Binding itself is not persistent
and has to be restored after primary collection is loaded. Data contained in secondary collection are persistent.
Type params:K - - Key in Primary Map and Second Value in Secondary SetV - - Value in Primary Map and Primary Value in Secondary Setprimary - Primary Map for which inverse mapping will be createdinverse - Secondary Set which will contain inverse mappingpublic static <K,V> void mapInverse(Bind.MapWithModificationListener<K,V> primary, Map<V,K> inverse)
NavigableSet<Fun.Tuple2<V,K>> which
handles value duplicities. Use mapInverse(org.mapdb.Bind.MapWithModificationListener, java.util.Map)
If Secondary Set is empty its content will be recreated from Primary Map.
NOTE: Binding just installs Modification Listener on primary collection. Binding itself is not persistent
and has to be restored after primary collection is loaded. Data contained in secondary collection are persistent.
Type params:K - - Key in Primary Map and Second Value in Secondary SetV - - Value in Primary Map and Primary Value in Secondary Setprimary - Primary Map for which inverse mapping will be createdinverse - Secondary Set which will contain inverse mappingpublic static <K,V,C> void histogram(Bind.MapWithModificationListener<K,V> primary, ConcurrentMap<C,Long> histogram, Fun.Function2<C,K,V> entryToCategory)
K - - Key type in primary mapV - - Value type in primary mapC - - Category typeprimary - Primary Map to create histogram forhistogram - Secondary Map to create histogram for, key is Category, value is number of items in categoryentryToCategory - returns Category in which entry from Primary Map belongs to.public static <K,V> void mapPutAfterDelete(Bind.MapWithModificationListener<K,V> primary, Bind.MapWithModificationListener<K,V> secondary, boolean overwriteSecondary)
HTreeMap),
it gets moved into secondary collection. This does not apply to updated values where key remains
unchanged (put(), replace()..)K - keyV - valueprimary - map from which data are removed by usersecondary - map which gets automatically updated with data removed from primaryoverwriteSecondary - if true any data in secondary will be overwritten.
If false only non-existing keys will be inserted
(put() versus putIfAbsent();Copyright © 2015. All Rights Reserved.