Skip to content

Commit

Permalink
Made KVStoreCollectionPartitionings public.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwever committed May 17, 2019
1 parent 4d3375b commit 731d5e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static void best(final KVStoreCollection collection, final String setting
KVStoreCollection grouped = new KVStoreCollection(collection);
grouped.group(setting, sampleID);

KVStoreCollectionPartition partition = new KVStoreCollectionPartition(setting, collection);
SingleLayerKVStoreCollectionPartition partition = new SingleLayerKVStoreCollectionPartition(setting, collection);

for (Entry<String, KVStoreCollection> entry : partition) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import ai.libs.jaicore.logging.ToJSONStringUtil;

import java.util.Set;

/**
* Automatically partitions a KVStoreCollection according to the values of the partitioning key when KVStores or KVStoreCollections are added.
*
* @author mwever
*/
public class KVStoreCollectionPartition implements Iterable<Entry<String, KVStoreCollection>> {
public class SingleLayerKVStoreCollectionPartition implements Iterable<Entry<String, KVStoreCollection>> {

/* Key for partitioning. */
private final String partitionKey;
Expand All @@ -28,7 +27,7 @@ public class KVStoreCollectionPartition implements Iterable<Entry<String, KVStor
* @param partitionKey The field name for the partitioning key.
* @param collection The {@link KVStoreCollection} to initialize this partition.
*/
KVStoreCollectionPartition(final String partitionKey, final KVStoreCollection collection) {
public SingleLayerKVStoreCollectionPartition(final String partitionKey, final KVStoreCollection collection) {
this(partitionKey);
this.addAll(collection);
}
Expand All @@ -38,16 +37,16 @@ public class KVStoreCollectionPartition implements Iterable<Entry<String, KVStor
*
* @param partitionKey The field name for the first level partition.
*/
KVStoreCollectionPartition(final String firstLevelKey) {
public SingleLayerKVStoreCollectionPartition(final String firstLevelKey) {
this.partitionKey = firstLevelKey;
this.data = new HashMap<>();
}

/**
* Adds a signle {@link KVStore} to this {@link KVStoreCollectionPartition}.
* Adds a signle {@link KVStore} to this {@link SingleLayerKVStoreCollectionPartition}.
* @param store
*/
void add(final KVStore store) {
public void add(final KVStore store) {
/* First ensure that nested maps contain the required keys and KVStoreCollection respectively. */
String keyForPartition = store.getAsString(this.partitionKey);
if (!this.data.containsKey(keyForPartition)) {
Expand All @@ -57,17 +56,17 @@ void add(final KVStore store) {
}

/**
* Adds an entire {@link KVStoreCollection to this {@link KVStoreCollectionPartition}.
* Adds an entire {@link KVStoreCollection to this {@link SingleLayerKVStoreCollectionPartition}.
* @param collection The collection to be added to this partition.
*/
void addAll(final KVStoreCollection collection) {
public void addAll(final KVStoreCollection collection) {
collection.forEach(this::add);
}

/**
* @return The set of entries of this partition.
*/
Set<Entry<String, KVStoreCollection>> entrySet() {
public Set<Entry<String, KVStoreCollection>> entrySet() {
return this.data.entrySet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author mwever
*/
class TwoLayerKVStoreCollectionPartition implements Iterable<Entry<String, Map<String, KVStoreCollection>>> {
public class TwoLayerKVStoreCollectionPartition implements Iterable<Entry<String, Map<String, KVStoreCollection>>> {

/* Keys for partitioning. */
private final String firstLayerKey;
Expand All @@ -27,7 +27,7 @@ class TwoLayerKVStoreCollectionPartition implements Iterable<Entry<String, Map<S
* @param secondLayerKey The field name for the second level partition.
* @param collection The {@link KVStoreCollection} to initialize this two-layer partition.
*/
TwoLayerKVStoreCollectionPartition(final String firstLayerKey, final String secondLayerKey, final KVStoreCollection collection) {
public TwoLayerKVStoreCollectionPartition(final String firstLayerKey, final String secondLayerKey, final KVStoreCollection collection) {
this(firstLayerKey, secondLayerKey);
this.addAll(collection);
}
Expand All @@ -38,7 +38,7 @@ class TwoLayerKVStoreCollectionPartition implements Iterable<Entry<String, Map<S
* @param firstLevelKey The field name for the first level partition.
* @param secondLevelKey The field name for the second level partition.
*/
TwoLayerKVStoreCollectionPartition(final String firstLevelKey, final String secondLevelKey) {
public TwoLayerKVStoreCollectionPartition(final String firstLevelKey, final String secondLevelKey) {
this.firstLayerKey = firstLevelKey;
this.secondLayerKey = secondLevelKey;
this.data = new HashMap<>();
Expand All @@ -48,7 +48,7 @@ class TwoLayerKVStoreCollectionPartition implements Iterable<Entry<String, Map<S
* Adds a signle {@link KVStore} to this {@link TwoLayerKVStoreCollectionPartition}.
* @param store
*/
void add(final KVStore store) {
public void add(final KVStore store) {
/* First ensure that nested maps contain the required keys and KVStoreCollection respectively. */
String firstLevelValue = store.getAsString(this.firstLayerKey);
String secondLevelValue = store.getAsString(this.secondLayerKey);
Expand All @@ -66,14 +66,14 @@ void add(final KVStore store) {
* Adds an entire {@link KVStoreCollection to this {@link TwoLayerKVStoreCollectionPartition}.
* @param collection The collection to be added to this partition.
*/
void addAll(final KVStoreCollection collection) {
public void addAll(final KVStoreCollection collection) {
collection.forEach(this::add);
}

/**
* @return The set of entries of this partition.
*/
Set<Entry<String, Map<String, KVStoreCollection>>> entrySet() {
public Set<Entry<String, Map<String, KVStoreCollection>>> entrySet() {
return this.data.entrySet();
}

Expand Down

0 comments on commit 731d5e9

Please sign in to comment.