Class TagProcessorHelper


  • public class TagProcessorHelper
    extends Object
    Helper class for TagProcessor classes.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • 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<BaseKeyValuePair> 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,​BaseKeyValuePair> map,
                                       List<BaseKeyValuePair> 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,​BaseKeyValuePair> map,
                                       BaseKeyValuePair[] 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<BaseKeyValuePair> 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<BaseKeyValuePair> 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