package foundation.data.entity;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import foundation.data.meta.field.FieldsRuntime;
|
|
|
public class Index implements IIndex {
|
|
private String fieldName;
|
private Map<Object, Entity> maps;
|
|
|
public Index(String fieldName) {
|
maps = new HashMap<Object, Entity>();
|
|
this.fieldName = fieldName;
|
}
|
|
public void load(EntitySet entitySet) {
|
FieldsRuntime meta = entitySet.getEntityMeta();
|
int index = meta.getIndex(fieldName);
|
|
for (Entity entity: entitySet) {
|
Object value = entity.getValue(index);
|
|
if (value == null) {
|
continue;
|
}
|
|
maps.put(value, entity);
|
}
|
}
|
|
public void add(Object value, Entity entity) {
|
if (value == null) {
|
return;
|
}
|
|
maps.put(value, entity);
|
}
|
|
public Entity get(Object value) {
|
if (value == null) {
|
return null;
|
}
|
|
return maps.get(value);
|
}
|
|
public String getName() {
|
return fieldName;
|
}
|
}
|