Class CollectionPatterns

java.lang.Object
eu.bandm.tools.paisley.CollectionPatterns

@Generated(generator="eu.bandm.tools.expander", version="", timestamp="2026-01-24T11:39:12") public abstract class CollectionPatterns extends Object
Static factory methods for creating patterns for collections.

Patterns produced by factory methods of this class do not tolerate null targets. They throw NullPointerException during matching rather than failing silently. Use PrimitivePatterns.neqNull() to guard against this behavior.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A> Pattern<A[]>
    anyArrayElement(Pattern<? super A> elem)
    Returns a pattern that matches a given pattern against any element of an array successively.
    static <A> Pattern<Iterable<A>>
    anyElement(Pattern<? super A> elem)
    Returns a pattern that matches a given pattern against any element successively.
    static <E> Pattern<List<E>>
    cons(Pattern<? super E> first, Pattern<? super List<E>> rest)
    Returns a pattern that matches the first element and the rest of a list with separate patterns conjunctively.
    static <A> Pattern<A[]>
    elementwise(Pattern<? super A>... elems)
    Returns a pattern that matches a given array of patterns element-by-element against an array.
    static <E> Pattern<List<E>>
    elementwise(List<Pattern<? super E>> elems)
    Returns a pattern that matches a given list of patterns element-by-element against a list.
    static <A> Pattern<A[]>
    firstArrayElement(Pattern<? super A> elem)
    Returns a pattern that matches a given pattern against any element of an array successively until a match is found.
    static <A> Pattern<Iterable<A>>
    firstElement(Pattern<? super A> elem)
    Returns a pattern that matches a given pattern against any element successively until a match is found.
    static <E> Pattern<List<E>>
    get(int index, Pattern<? super E> elem)
    Returns a pattern that matches a given pattern against the element at a given index in a list.
    static <K, V> Pattern<Map<K,V>>
    get(K key, Pattern<? super V> value)
    Returns a pattern that matches a given pattern against the element for a given key in a map.
    static <A> Pattern<A[]>
    getArray(int index, Pattern<? super A> elem)
    Returns a pattern that matches a given pattern against the element at a given index in an array.
    static <K, V> Pattern<Map<K,V>>
    keySet(Pattern<? super Set<K>> keySet)
    Returns a pattern that matches a given pattern against the key set of a map.
    static <A> Pattern<A[]>
    length(Pattern<? super Integer> length)
    Returns a pattern that matches a given pattern against the length of an array.
    static <E, F> Motif<List<E>,List<F>>
    map(Motif<E,F> elem)
    Lifts the given motif to lists.
    static <E> Pattern<List<E>>
    nil()
    Returns a pattern that matches an empty list.
    static <E> Pattern<Collection<E>>
    singleton(Pattern<? super E> elem)
    Returns a pattern that matches a given pattern against the single element of a collection.
    static <E> Pattern<Collection<E>>
    size(Pattern<? super Integer> size)
    Returns a pattern that matches a given pattern against the size of a collection.
    static <E> Pattern<List<E>>
    snoc(Pattern<? super List<E>> front, Pattern<? super E> last)
    Returns a pattern that matches the front and the last element of a list with separate patterns conjunctively.
    static <K, V> Pattern<Map<K,V>>
    values(Pattern<? super Collection<V>> values)
    Returns a pattern that matches a given pattern against the values of a map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • anyElement

      public static <A> Pattern<Iterable<A>> anyElement(Pattern<? super A> elem)
      Returns a pattern that matches a given pattern against any element successively.

      Matches are effected exhaustively for each element returned by the iterator of the target before proceeding to the next element. For a deterministic pattern, this is equivalent to finding the matching elements.

      Elements are retrieved from the iterator lazily on demand. A pattern created with this method is suitable for processing an infinite enumeration of elements.

      Type Parameters:
      A - the type of elements to match against
      Parameters:
      elem - the pattern to match against the elements of a given target
      Returns:
      a pattern that matches elem against each element of its target successively
      Throws:
      NullPointerException - if elem is null
      See Also:
    • firstElement

      public static <A> Pattern<Iterable<A>> firstElement(Pattern<? super A> elem)
      Returns a pattern that matches a given pattern against any element successively until a match is found.

      Matches are effected exhaustively for the first element returned by the iterator for which there are any; subsequent elements are ignored. For a deterministic pattern, this is equivalent to finding the first matching element.

      Elements are retrieved from the iterator lazily on demand. A pattern created with this method is suitable for processing an infinite enumeration of elements.

      Type Parameters:
      A - the type of elements to match against
      Parameters:
      elem - the pattern to match against the elements of a given target
      Returns:
      a pattern that matches elem against each element of its target successively until a match is found
      See Also:
    • anyArrayElement

      public static <A> Pattern<A[]> anyArrayElement(Pattern<? super A> elem)
      Returns a pattern that matches a given pattern against any element of an array successively.

      Matches are effected exhaustively for each element of the target in ascending order before proceeding to the next element. For a deterministic pattern, this is equivalent to finding the matching elements.

      Type Parameters:
      A - the type of elements to match against
      Parameters:
      elem - the pattern to match against the elements of a given target
      Returns:
      a pattern that matches elem against each element of its target successively
      See Also:
    • firstArrayElement

      public static <A> Pattern<A[]> firstArrayElement(Pattern<? super A> elem)
      Returns a pattern that matches a given pattern against any element of an array successively until a match is found.

      Matches are effected exhaustively for the first element in ascending order for which there are any; subsequent elements are ignored. For a deterministic pattern, this is equivalent to finding the first matching element.

      Type Parameters:
      A - the type of elements to match against
      Parameters:
      elem - the pattern to match against the elements of a given target
      Returns:
      a pattern that matches elem against each element of its target successively until a match is found
      See Also:
    • keySet

      public static <K, V> Pattern<Map<K,V>> keySet(Pattern<? super Set<K>> keySet)
      Returns a pattern that matches a given pattern against the key set of a map.
      Type Parameters:
      K - the type of map keys
      V - the type of map values
      Parameters:
      keySet - the pattern to match against the key set
      Returns:
      a pattern that matches a map by matching keySet against its key set
      Throws:
      NullPointerException - if keySet is null
      See Also:
    • values

      public static <K, V> Pattern<Map<K,V>> values(Pattern<? super Collection<V>> values)
      Returns a pattern that matches a given pattern against the values of a map.
      Type Parameters:
      K - the type of map keys
      V - the type of map values
      Parameters:
      values - the pattern to match against the key set
      Returns:
      a pattern that matches a map by matching values against its value collection
      Throws:
      NullPointerException - if values is null
      See Also:
    • size

      public static <E> Pattern<Collection<E>> size(Pattern<? super Integer> size)
      Returns a pattern that matches a given pattern against the size of a collection.
      Type Parameters:
      E - the type of collection elements
      Parameters:
      size - the pattern to match against the size
      Returns:
      a pattern that matches a collection by matching size against its size
      Throws:
      NullPointerException - if size is null
      See Also:
    • get

      public static <E> Pattern<List<E>> get(int index, Pattern<? super E> elem)
      Returns a pattern that matches a given pattern against the element at a given index in a list.

      The failure behaviour of the resulting pattern reflects that of List.get(int): If the given index is invalid for a target list, an IndexOutOfBoundsException is thrown during matching.

      Type Parameters:
      E - the type of list elements
      Parameters:
      index - the index of the element to select
      elem - the pattern to match against the selected element
      Returns:
      a pattern that matches a list by matching elem against the element at index
      Throws:
      NullPointerException - if elem is null
      See Also:
    • get

      public static <K, V> Pattern<Map<K,V>> get(K key, Pattern<? super V> value)
      Returns a pattern that matches a given pattern against the element for a given key in a map.

      The failure behaviour of the resulting pattern reflects that of Map.get(java.lang.Object): If the given key is not contained in a target list, the body pattern is matched against null. If the key is null, and the map does not support null keys, NullPointerException exception may be thrown during matching.

      Type Parameters:
      K - the type of map keys
      V - the type of map values
      Parameters:
      key - the key of the element to select
      value - the pattern to match against the selected element
      Returns:
      a pattern that matches a map by matching value against the map element for key
      See Also:
    • length

      public static <A> Pattern<A[]> length(Pattern<? super Integer> length)
      Returns a pattern that matches a given pattern against the length of an array.
      Type Parameters:
      A - the type of array elements
      Parameters:
      length - the pattern to match against the length
      Returns:
      a pattern that matches an array by matching length against its length
    • getArray

      public static <A> Pattern<A[]> getArray(int index, Pattern<? super A> elem)
      Returns a pattern that matches a given pattern against the element at a given index in an array.

      The failure behaviour of the resulting pattern reflects that of array selection: if the given index is invalid for a target array, an ArrayIndexOutOfBoundsException is thrown during matching.

      Type Parameters:
      A - the type of array elements
      Parameters:
      index - the index of the element to select
      elem - the pattern to match against the selected element
      Returns:
      a pattern that matches an array by matching elem against the element at index
    • elementwise

      public static <E> Pattern<List<E>> elementwise(List<Pattern<? super E>> elems)
      Returns a pattern that matches a given list of patterns element-by-element against a list.

      The first pattern is matched against the first list element and so forth. A successful match requires the size of the target list to match the number of given patterns exactly. Multiple matches for individual patterns are combined as with Pattern.all(Pattern...).

      Type Parameters:
      E - the type of list elements
      Parameters:
      elems - a list of patterns to match against list elements
      Returns:
      a pattern that matches a list by matching elems one-to-one against its elements
    • elementwise

      public static <A> Pattern<A[]> elementwise(Pattern<? super A>... elems)
      Returns a pattern that matches a given array of patterns element-by-element against an array.

      The first pattern is matched against the first array element and so forth. A successful match requires the length of the target array to match the number of given patterns exactly. Multiple matches for individual patterns are combined as with Pattern.all(Pattern...).

      Type Parameters:
      A - the type of array elements
      Parameters:
      elems - an array of patterns to match against array elements
      Returns:
      a pattern that matches an array by matching elems one-to-one against its elements
    • singleton

      public static <E> Pattern<Collection<E>> singleton(Pattern<? super E> elem)
      Returns a pattern that matches a given pattern against the single element of a collection. A successful match requires the target collection to have size one exactly.
      Type Parameters:
      E - the type of collection elements
      Parameters:
      elem - a pattern to match against the collection element
      Returns:
      a pattern that matches a collection by matching elem against its single element
      Throws:
      NullPointerException - if elem is null
    • nil

      public static <E> Pattern<List<E>> nil()
      Returns a pattern that matches an empty list.

      The returned pattern is deterministic and binds no variables.

      Type Parameters:
      E - the type of list elements
      Returns:
      a pattern that matches a list if and only if it is empty
    • cons

      public static <E> Pattern<List<E>> cons(Pattern<? super E> first, Pattern<? super List<E>> rest)
      Returns a pattern that matches the first element and the rest of a list with separate patterns conjunctively.

      The returned pattern does not match an empty list.

      Type Parameters:
      E - the type of list elements
      Parameters:
      first - the pattern to match against the first element of a list
      rest - the pattern to match against the rest (all except the first element) of a list
      Returns:
      a pattern that matches a nonempty list by matching first against its first element and second against the rest
      Throws:
      NullPointerException - if first or rest is null
    • snoc

      public static <E> Pattern<List<E>> snoc(Pattern<? super List<E>> front, Pattern<? super E> last)
      Returns a pattern that matches the front and the last element of a list with separate patterns conjunctively.

      The returned pattern does not match an empty list.

      Type Parameters:
      E - the type of list elements
      Parameters:
      front - the pattern to match against the front (all except the last element) of a list
      last - the pattern to match against the last element of a list
      Returns:
      a pattern that matches a nonempty list by matching front against its front and last against the last element
      Throws:
      NullPointerException - if front or last is null
    • map

      public static <E, F> Motif<List<E>,List<F>> map(Motif<E,F> elem)
      Lifts the given motif to lists.
      Type Parameters:
      E - the type of subpattern list elements
      F - the type of target list elements
      Parameters:
      elem - the motif to apply to elements
      Returns:
      a motif that applies to a whole list by applying elem to each element successively