Class TagProcessorHelper


  • public class TagProcessorHelper
    extends Object
    Helper class for TagProcessor classes.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • m_SupportedTagInfoCache

        protected static Map<Class,​Set<TagInfo>> m_SupportedTagInfoCache
        for caching the tag info per tag processor.
      • m_ApplicableTagInfoCache

        protected static Map<Class,​Set<TagInfo>> m_ApplicableTagInfoCache
        for caching the tag info per applicable.
      • m_TagInfos

        protected static Map<String,​TagInfo> m_TagInfos
        the lookup by name.
    • Constructor Detail

      • TagProcessorHelper

        public TagProcessorHelper()
    • Method Detail

      • hasTag

        public static boolean hasTag​(Object obj,
                                     String tag)
        Checks whether the specified tag is present.
        Parameters:
        obj - the object to check
        tag - the tag to look for
        Returns:
        true if the object supports tags and the tag is present
      • getTagValue

        protected static String getTagValue​(Object obj,
                                            String tag,
                                            Variables vars)
        Returns the value of the tag if present.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise null (eg if the object is not a tag handler or the tag is not present)
      • getTagString

        public static String getTagString​(Object obj,
                                          String tag,
                                          String defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagString

        public static String getTagString​(Object obj,
                                          String tag,
                                          String defValue,
                                          Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagBoolean

        public static boolean getTagBoolean​(Object obj,
                                            String tag,
                                            boolean defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagBoolean

        public static boolean getTagBoolean​(Object obj,
                                            String tag,
                                            boolean defValue,
                                            Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagByte

        public static byte getTagByte​(Object obj,
                                      String tag,
                                      byte defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagByte

        public static byte getTagByte​(Object obj,
                                      String tag,
                                      byte defValue,
                                      Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagInt

        public static int getTagInt​(Object obj,
                                    String tag,
                                    int defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagInt

        public static int getTagInt​(Object obj,
                                    String tag,
                                    int defValue,
                                    Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagLong

        public static long getTagLong​(Object obj,
                                      String tag,
                                      long defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagLong

        public static long getTagLong​(Object obj,
                                      String tag,
                                      long defValue,
                                      Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagFloat

        public static float getTagFloat​(Object obj,
                                        String tag,
                                        float defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagFloat

        public static float getTagFloat​(Object obj,
                                        String tag,
                                        float defValue,
                                        Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagDouble

        public static double getTagDouble​(Object obj,
                                          String tag,
                                          double defValue)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getTagDouble

        public static double getTagDouble​(Object obj,
                                          String tag,
                                          double defValue,
                                          Variables vars)
        Returns the value of the tag if present, otherwise the default value.
        Parameters:
        obj - the object to obtain the tag value from
        tag - the tag to look for
        defValue - the default value
        vars - the variables to use, ignored if null
        Returns:
        the associated value, otherwise the default value (eg if the object is not a tag handler or the tag is not present)
      • getAllTags

        public static List<Tag> getAllTags​(TagHandler handler)
        Retrieves all tags from the tag handler,.
        Parameters:
        handler - the tag handler
        Returns:
        all tags
      • addToMap

        protected static void addToMap​(Map<String,​Tag> map,
                                       List<Tag> tags,
                                       boolean override)
        Adds the tags to the map.
        Parameters:
        map - the map for storing the tags (using their key as the map's key)
        tags - the tags to add
        override - if true, then existing tags can be replaced; otherwise only non-existing tags get added
      • addToMap

        protected static void addToMap​(Map<String,​Tag> map,
                                       Tag[] tags,
                                       boolean override)
        Adds the tags to the map.
        Parameters:
        map - the map for storing the tags (using their key as the map's key)
        tags - the tags to add
        override - if true, then existing tags can be replaced; otherwise only non-existing tags get added
      • getAllTags

        public static List<Tag> getAllTags​(Actor actor,
                                           boolean traverse)
        Retrieves all tags from the actor, going up in the actor tree, with lower ones overriding ones defined higher up.
        Parameters:
        actor - the actor to start
        traverse - whether to traverse upwards or not traverse at all
        Returns:
        all tags
      • getAllTags

        public static List<Tag> getAllTags​(Node node,
                                           boolean traverse)
        Retrieves all tags from the actor, going up in the actor tree, with lower ones overriding ones defined higher up.
        Parameters:
        node - the actor to start
        traverse - whether to traverse upwards or not traverse at all
        Returns:
        all tags
      • getTagProcessors

        public static Class[] getTagProcessors()
        Returns the list of all classes that implement the TagProcessor interface.
        Returns:
        the classes
      • initTagInfoCache

        protected static void initTagInfoCache()
        Initializes the caches for the TagInfo items.
      • getApplicableTags

        public static List<TagInfo> getApplicableTags​(Class cls)
        Returns all the tags that can be applied to the specified class.
        Parameters:
        cls - the class to look up the tags for
        Returns:
        the applicable tags
      • getSupportedTags

        public static List<TagInfo> getSupportedTags​(Class cls)
        Returns all the tags that can are supported by the specified class.
        Parameters:
        cls - the class to look up the tags for
        Returns:
        the supported tags
      • getAllTags

        public static List<TagInfo> getAllTags()
        Returns a list of all possible tags.
        Returns:
        the tags
      • getTagInfo

        public static TagInfo getTagInfo​(String name)
        Returns the tag info for the tag's name.
        Parameters:
        name - the name of the tag to get the info for
        Returns:
        the info or null if unknown name