Class Subscriptions

  • All Implemented Interfaces:
    java.util.Map

    public class Subscriptions
    extends SampMap
    Represents the set of subscribed messages for a SAMP client. This has the form of a Map in which each key is an MType (perhaps wildcarded) and the corresponding values are maps with keys which are so far undefined (thus typically empty).
    Since:
    14 Jul 2008
    Author:
    Mark Taylor
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String ATOM_REGEX  
      private static java.util.regex.Pattern MSUB_PATTERN  
      private static java.lang.String MSUB_REGEX  
      private static java.lang.String MTYPE_REGEX  
    • Constructor Summary

      Constructors 
      Constructor Description
      Subscriptions()
      Constructs an empty subscriptions object.
      Subscriptions​(java.util.Map map)
      Constructs a subscriptions object based on an existing map.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMType​(java.lang.String mtype)
      Adds a subscription to a given MType.
      static Subscriptions asSubscriptions​(java.util.Map map)
      Returns a given map in the form of a Subscriptions object.
      void check()
      Checks that this object is ready for use with the SAMP toolkit.
      private static int countAtoms​(java.lang.String text)
      Counts the number of dot-separated "atoms" in a string.
      java.util.Map getSubscription​(java.lang.String mtype)
      Returns the map which forms the value for a given MType key.
      boolean isSubscribed​(java.lang.String mtype)
      Determines whether a given (non-wildcarded) MType is subscribed to by this object.
      static int matchLevel​(java.lang.String pattern, java.lang.String mtype)
      Performs wildcard matching of MTypes.
      • Methods inherited from class java.util.AbstractMap

        clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • MTYPE_REGEX

        private static java.lang.String MTYPE_REGEX
      • MSUB_REGEX

        private static java.lang.String MSUB_REGEX
      • MSUB_PATTERN

        private static final java.util.regex.Pattern MSUB_PATTERN
    • Constructor Detail

      • Subscriptions

        public Subscriptions()
        Constructs an empty subscriptions object.
      • Subscriptions

        public Subscriptions​(java.util.Map map)
        Constructs a subscriptions object based on an existing map.
        Parameters:
        map - map containing initial data for this object
    • Method Detail

      • addMType

        public void addMType​(java.lang.String mtype)
        Adds a subscription to a given MType. mtype may include a wildcard according to the SAMP rules.
        Parameters:
        mtype - subscribed MType, possibly wildcarded
      • isSubscribed

        public boolean isSubscribed​(java.lang.String mtype)
        Determines whether a given (non-wildcarded) MType is subscribed to by this object.
        Parameters:
        mtype - MType to test
      • getSubscription

        public java.util.Map getSubscription​(java.lang.String mtype)
        Returns the map which forms the value for a given MType key. If a wildcarded subscription is recorded which matches mtype, the corresponding value is returned. If mtype is not subscribed to, null is returned.
        Parameters:
        mtype - MType to query
        Returns:
        map value corresponding to mtype, or null
      • check

        public void check()
        Description copied from class: SampMap
        Checks that this object is ready for use with the SAMP toolkit. As well as calling SampUtils.checkMap(java.util.Map) (ensuring that all keys are Strings, and all values Strings, Lists or Maps), subclass-specific invariants may be checked. In the case that there's something wrong, an informative DataException will be thrown.
        Overrides:
        check in class SampMap
      • asSubscriptions

        public static Subscriptions asSubscriptions​(java.util.Map map)
        Returns a given map in the form of a Subscriptions object.
        Parameters:
        map - map
        Returns:
        subscriptions
      • matchLevel

        public static int matchLevel​(java.lang.String pattern,
                                     java.lang.String mtype)
        Performs wildcard matching of MTypes. The result is the number of dot-separated "atoms" which match between the two.
        Parameters:
        pattern - MType pattern; may contain a wildcard
        mtype - unwildcarded MType for comparison with pattern
        Returns:
        the number of atoms of pattern which match mtype; if pattern="*" the result is 0, and if there is no match the result is -1
      • countAtoms

        private static int countAtoms​(java.lang.String text)
        Counts the number of dot-separated "atoms" in a string.
        Parameters:
        text - string to test