com.senseidb.search.client.req.relevance.RelevanceValues Maven / Gradle / Ivy
The newest version!
package com.senseidb.search.client.req.relevance;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The "values" part provides the input values for either the runtime model or the predefined one
* values part is used for either predefined model or a runtime model above, if these models require input values;
* "values":{
* "thisYear":2001,
* "goodYear":[
* 1996,
* 1997
* ]
* }
*/
public class RelevanceValues {
protected Map values = new HashMap();
public static RelevanceValuesBuilder builder() {
return new RelevanceValuesBuilder();
}
public Map getValues() {
return values;
}
private RelevanceValues() {
// TODO Auto-generated constructor stub
}
public static class RelevanceValuesBuilder {
private final RelevanceValues relevanceValues;
public RelevanceValuesBuilder() {
relevanceValues = new RelevanceValues();
}
public RelevanceValuesBuilder addListValue(String variableName, Object... values) {
for (Object value : values) {
checkType(value);
}
relevanceValues.values.put(variableName, Arrays.asList(values));
return this;
}
public RelevanceValuesBuilder addAtomicValue(String variableName, Object value) {
checkType(value);
relevanceValues.values.put(variableName, value);
return this;
}
private void checkType(Object value) {
if (!(value instanceof String) && !(value instanceof Number)) {
throw new IllegalStateException("The value should be either String or Number");
}
}
@SuppressWarnings("rawtypes")
public RelevanceValuesBuilder addMapValue(String variableName, List keys, List values) {
for (int i = 0; i < keys.size(); i++) {
checkType(keys.get(i));
checkType(values.get(i));
}
Map ret = new HashMap(2);
ret.put("key", keys);
ret.put("value", values);
relevanceValues.values.put(variableName, ret);
return this;
}
public RelevanceValuesBuilder addMapValue(String variableName, Map