info.unterrainer.commons.jreutils.collections.DataTable Maven / Gradle / Ivy
package info.unterrainer.commons.jreutils.collections;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import java.util.function.Function;
import lombok.Getter;
import lombok.experimental.Accessors;
/**
* A synchronized data-structure acting as a table. You may create indexes for
* various columns of this table.
*/
@Accessors(fluent = true)
public class DataTable {
private Class clazz;
private int maxEntries;
@Getter
private DataQueue queue;
private HashMap> keySuppliers = new HashMap<>();
private HashMap> maps = new HashMap<>();
public DataTable(final Class clazz, final int maxEntries) {
this.clazz = clazz;
this.maxEntries = maxEntries;
queue = new DataQueue<>(maxEntries);
}
@SuppressWarnings("unchecked")
public DataTable addIndex(final String name, final Function keySupplier) {
keySuppliers.put(name, (Function) keySupplier);
maps.put(name, new DataMap