Package edu.tufts.hrilab.action.db.util
Class Utilities
java.lang.Object
edu.tufts.hrilab.action.db.util.Utilities
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
argMatches
(ActionBinding signatureArg, Object inputArg) Checks if the java class and semantic type of the input arg matches the java class and semantic type of the argument in teh DB entry signature.static List<ActionDBEntry>
filterEntries
(Predicate pred, List<org.apache.commons.lang3.tuple.Pair<Predicate, ActionDBEntry>> map, Symbol actor) Filter possible ActionDBEntries found for predicatefindMatchingEntries
(List<T> entries, List<Class<?>> inputRoleTypes) Finds the matching DBEntries for the provided role types.getEntries
(Map<String, List<T>> db, String type) Lookup by type.Lookup by type and roles.static ActionDBEntry
getEntry
(Map<String, List<ActionDBEntry>> db, String type, Symbol actor, List<Class<?>> inputRoleTypes) Lookup by type, roles and agent.static <T extends DBEntry>
TLookup by type.static <T extends DBEntry>
TLookup by type and roles.static <T extends DBEntry>
voidPut a new entry in the database.
-
Constructor Details
-
Utilities
public Utilities()
-
-
Method Details
-
getEntries
Lookup by type.- Parameters:
db
- the database in which to look uptype
- the type of the entity to look up- Returns:
- list of entries with matching type
-
getEntries
public static <T extends DBEntry> List<T> getEntries(Map<String, List<T>> db, String type, List<Class<?>> inputRoleTypes) Lookup by type and roles.- Parameters:
db
- the database in which to look uptype
- the type of the entity to look upinputRoleTypes
- the java types of the input roles of the Entry to look up- Returns:
- list of entries with matching type and roles, best match first.
-
getEntry
Lookup by type. Returns last added entry if more than one entry with type.- Parameters:
db
- the database in which to look uptype
- the type of the entity to look up- Returns:
- the (last) requested entry, if found, null otherwise
-
getEntry
public static <T extends DBEntry> T getEntry(Map<String, List<T>> db, String type, List<Class<?>> inputRoleTypes) Lookup by type and roles. Tries to find best suited entry according to provided roles.- Parameters:
db
- the database in which to look uptype
- the type of the entity to look upinputRoleTypes
- the java types of the input roles of the Entry to look up- Returns:
- the requested entry, if found, null otherwise
-
getEntry
public static ActionDBEntry getEntry(Map<String, List<ActionDBEntry>> db, String type, Symbol actor, List<Class<?>> inputRoleTypes) Lookup by type, roles and agent. Tries to find best suited entry according to provided roles.- Parameters:
db
- the database in which to look uptype
- the type of the entity to look upactor
- the actor affected by the entity to look upinputRoleTypes
- the java types of the input roles of the action to look up- Returns:
- the requested entry, if found, null otherwise
-
putEntry
Put a new entry in the database.- Parameters:
db
- the database in which to put the entryentry
- the new entry
-
findMatchingEntries
public static final <T extends DBEntry> List<T> findMatchingEntries(List<T> entries, List<Class<?>> inputRoleTypes) Finds the matching DBEntries for the provided role types.- Type Parameters:
T
- type of DBEntry- Parameters:
entries
- DBEntries.inputRoleTypes
- the java types of the input roles of the Entry to look up- Returns:
- list of matching DBEntries.
-
filterEntries
public static List<ActionDBEntry> filterEntries(Predicate pred, List<org.apache.commons.lang3.tuple.Pair<Predicate, ActionDBEntry>> map, Symbol actor) Filter possible ActionDBEntries found for predicate- Parameters:
pred
- input predicatemap
- list of possible Entries- Returns:
- list of ActionDBEntries
-
argMatches
Checks if the java class and semantic type of the input arg matches the java class and semantic type of the argument in teh DB entry signature.- Parameters:
signatureArg
- argument in the signature of the db entryinputArg
- potential input argument to the DB entry- Returns:
- true if the class and semantic type of the input arg match the signature arg
-