io.baltoro.client.Linked Maven / Gradle / Ivy
package io.baltoro.client;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.baltoro.client.LocalDB.Direction;
import io.baltoro.client.util.StringUtil;
import io.baltoro.obj.Base;
public class Linked
{
private String srcUuid;
private Direction direction;
private int count;
private List uuids;
private List objs;
private Map> attUuidMap;
private Map> attObjMap;
private Class c;
private LocalDB db;
Linked(Class c, String srcUuid, Direction direction, LocalDB db)
{
this.c = c;
this.db = db;
this.srcUuid = srcUuid;
this.direction = direction;
}
public List getUuids()
{
return uuids;
}
void setUuids(List uuids)
{
this.uuids = uuids;
}
public int getCount()
{
return count;
}
void setCount(int count)
{
this.count = count;
}
public List getList()
{
return objs;
}
void setList(List list)
{
this.objs = list;
}
public String getFirstUuid()
{
return uuids.get(0);
}
public T getFirst()
{
getAll();
return objs.get(0);
}
public List getAll()
{
if(StringUtil.isNullOrEmpty(uuids))
{
return new ArrayList<>();
}
if(objs == null)
{
List objs = (List) db.get(uuids);
setList(objs);
}
return objs;
}
public T[] getAllAsArray()
{
getAll();
Object[] arr = (Object[]) Array.newInstance(c, objs.size());
return (T[]) objs.toArray(arr);
}
public String[] getUuidsAsArray()
{
return uuids.toArray(new String[uuids.size()]);
}
public Class getType()
{
return c;
}
public Set getAttUuids(String objUuid)
{
if(attUuidMap == null)
{
attUuidMap = db.getLinkAtt(srcUuid, uuids, direction);
}
Set set = attUuidMap.get(objUuid);
return set;
}
/*
public Set getAttObjs(String objUuid)
{
getAttUuids(objUuid);
if(attObjMap == null)
{
Set allAttUuids = new HashSet<>(500);
for (Set attUuid : attUuidMap.values())
{
for (String val : attUuid)
{
allAttUuids.add(val);
}
}
attObjMap = db.get(allAttUuids);
}
}
*/
}