Class Utilities

java.lang.Object
edu.tufts.hrilab.action.db.util.Utilities

public class Utilities extends Object
  • Constructor Details

    • Utilities

      public Utilities()
  • Method Details

    • getEntries

      public static <T extends DBEntry> List<T> getEntries(Map<String,List<T>> db, String type)
      Lookup by type.
      Parameters:
      db - the database in which to look up
      type - 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 up
      type - the type of the entity to look up
      inputRoleTypes - 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

      public static <T extends DBEntry> T getEntry(Map<String,List<T>> db, String type)
      Lookup by type. Returns last added entry if more than one entry with type.
      Parameters:
      db - the database in which to look up
      type - 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 up
      type - the type of the entity to look up
      inputRoleTypes - 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 up
      type - the type of the entity to look up
      actor - the actor affected by the entity to look up
      inputRoleTypes - the java types of the input roles of the action to look up
      Returns:
      the requested entry, if found, null otherwise
    • putEntry

      public static <T extends DBEntry> void putEntry(Map<String,List<T>> db, T entry)
      Put a new entry in the database.
      Parameters:
      db - the database in which to put the entry
      entry - 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 predicate
      map - list of possible Entries
      Returns:
      list of ActionDBEntries
    • argMatches

      public static 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.
      Parameters:
      signatureArg - argument in the signature of the db entry
      inputArg - potential input argument to the DB entry
      Returns:
      true if the class and semantic type of the input arg match the signature arg