selva.oss.ds.document.DocumentImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lib Show documentation
Show all versions of lib Show documentation
Collection of libraries that make backend DX an oasis.
The newest version!
package selva.oss.ds.document;
import static selva.oss.lang.Commons.*;
import selva.oss.ds.document.datatype.DataTypeConfig;
import selva.oss.ds.document.datatype.TypedValue;
import java.util.*;
/* The Values and Configs are never expected to be null and they are always expected to be valid
*/
class DocumentImpl implements DocumentBaseImpl {
private Map dataTypeConfigs = new HashMap<>();
private Map data = new HashMap<>();
public boolean containsField(String field) {
return dataTypeConfigs.containsKey(field);
}
public boolean containsValue(String field) {
return data.containsKey(field);
}
public Optional fetchTypedValue(String field) {
if (!containsValue(field)) {
return Optional.empty();
}
return Optional.of(data.get(field));
}
public TypedValue fetchTypedValueSure(String field) {
if (!containsValue(field)) {
throw new DocumentBase.ValueDoesNotExistException();
}
return data.get(field);
}
public Optional fetchConfig(String field) {
if (!containsField(field)) {
return Optional.empty();
}
return Optional.of(dataTypeConfigs.get(field));
}
public DataTypeConfig fetchConfigSure(String field) {
if (!containsField(field)) {
throw new DocumentBase.ConfigDoesNotExistException();
}
return dataTypeConfigs.get(field);
}
public void putTypedValue(String field, TypedValue typedValue) {
data.put(field, typedValue);
}
public void putConfig(String field, DataTypeConfig dataTypeConfig) {
dataTypeConfigs.put(field, dataTypeConfig);
}
}