Package kawa.lang

Class ListPat

  • All Implemented Interfaces:
    gnu.kawa.format.Printable

    public class ListPat
    extends Pattern
    Match a list whose length in in the range [min_length..max_length].
    • Constructor Summary

      Constructors 
      Constructor Description
      ListPat​(int len)  
      ListPat​(int min, int max)  
      ListPat​(int min, int max, java.lang.Object default_val)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object[] match​(int min, int max, java.lang.Object default_val, java.lang.Object obj)
      Succeeds if obj is a list of length [min..max].
      static boolean match​(int min, int max, java.lang.Object default_val, java.lang.Object obj, java.lang.Object[] vars, int start_vars)  
      boolean match​(java.lang.Object obj, java.lang.Object[] vars, int start_vars)
      Succeeds if obj is a list of length [min_length..max_length].
      void print​(Consumer out)  
      int varCount()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ListPat

        public ListPat​(int len)
      • ListPat

        public ListPat​(int min,
                       int max)
      • ListPat

        public ListPat​(int min,
                       int max,
                       java.lang.Object default_val)
    • Method Detail

      • match

        public static boolean match​(int min,
                                    int max,
                                    java.lang.Object default_val,
                                    java.lang.Object obj,
                                    java.lang.Object[] vars,
                                    int start_vars)
      • match

        public static java.lang.Object[] match​(int min,
                                               int max,
                                               java.lang.Object default_val,
                                               java.lang.Object obj)
        Succeeds if obj is a list of length [min..max].
        Parameters:
        obj - the object to match against
        Returns:
        true iff the match succeeded On success, max_length values from the elements of the list are placed in vars (starting at start_vars); if obj is shorter, missing elements are set to default_value.
      • match

        public boolean match​(java.lang.Object obj,
                             java.lang.Object[] vars,
                             int start_vars)
        Succeeds if obj is a list of length [min_length..max_length].
        Specified by:
        match in class Pattern
        Parameters:
        obj - the object to match against
        vars - the "pattern variable" values extracted from obj go here
        start_vars - where in vars to strt putting the varCount() values
        Returns:
        null on failure, or an array of bound pattern variables: max_length values from the elements of the list are placed in the result; if obj is shorter, missing elements are set to default_value.
      • varCount

        public int varCount()
        Specified by:
        varCount in class Pattern
      • print

        public void print​(Consumer out)
        Specified by:
        print in interface gnu.kawa.format.Printable
        Overrides:
        print in class Pattern