net.yadaframework.raw.YadaLookupTableFour Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yadaweb Show documentation
Show all versions of yadaweb Show documentation
Some useful tasks for the Yada Framework
package net.yadaframework.raw;
import java.util.HashMap;
import java.util.Map;
/**
* Implements a table with four columns: three keys and one value. The purpose is to return the fourth value given the first three ones.
* Can't have rows with the same keys.
* @param the type of column 1
* @param the type of column 2
* @param the type of column 3
* @param the type of the value
*/
public class YadaLookupTableFour {
Map> col1 = new HashMap<>();
/**
* Add a new row to the table. Any value can be null.
*/
public void put(K1 key1, K2 key2, K3 key3, V value) {
YadaLookupTableThree col2 = col1.get(key1);
if (col2==null) {
col2 = new YadaLookupTableThree<>();
col1.put(key1, col2);
}
col2.put(key2, key3, value);
}
/**
* Get the value of the last column given the first ones
* @param key1 can be null
* @param key2 can be null
* @param key3 can be null
* @return the value of column 4, or null
*/
public V get(K1 key1, K2 key2, K3 key3) {
YadaLookupTableThree col2 = col1.get(key1);
if (col2!=null) {
return col2.get(key2, key3);
}
return null;
}
}