Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jchrest.lib
Class ListPattern

    java.lang.Object
      jchrest.lib.Pattern
          jchrest.lib.ListPattern

All Implemented Interfaces:
  java.lang.Iterable<PrimitivePattern>

    public class ListPattern

extends Pattern
implements java.lang.Iterable<PrimitivePattern>

The ListPattern is the primary datatype used to represent compound patterns within Chrest. A ListPattern holds an ordered list of instances of other pattern types. The ListPattern may optionally indicate that it cannot be extended by setting the _finished flag. Note that once a pattern is 'finished', it cannot be added to. TODO: Think about if ListPatterns can be embedded within ListPatterns - would have to look inside ListPattern to make the match.

Constructor Summary
`ListPattern()`
`ListPattern(Modality modality)`

Method Summary
`void` | `add(PrimitivePattern pattern)` Used in constructing instances by `Pattern` class.
`ListPattern` | `append(ListPattern pattern)` Return a new ListPattern formed from the contents of this list pattern and the contents of the given pattern appended to it.
`ListPattern` | `append(PrimitivePattern pattern)` Return a new ListPattern formed from the contents of this list pattern and the given PrimitivePattern appended to it.
`ListPattern` | `clone()` Construct a copy of this pattern, so that it can be modified without affecting the original.
`boolean` | `contains(PrimitivePattern given)`
`boolean` | `equals(ListPattern pattern)` Two patterns are equal if they contain the same items.
`ListPattern` | `getFirstItem()` Construct a new pattern containing just the first item in this one.
`PrimitivePattern` | `getItem(int index)` Retrieve the indexed item from the list pattern.
`Modality` | `getModality()` Accessor to retrieve the modality of the pattern.
`java.lang.String` | `getModalityString()` Convert the modality into a string.
`boolean` | `isAction()` Accessor method to check action modality.
`boolean` | `isEmpty()` Check if the list pattern is empty, holding no patterns.
`boolean` | `isFinished()` Accessor method to _finished property.
`static boolean` | `isSameModality(ListPattern pattern1, ListPattern pattern2)` Class level method to check if two patterns have the same modality.
`boolean` | `isSimilarTo(ListPattern pattern, int k)` Compare this list pattern with a given list pattern, returning true if the two share k or more items.
`boolean` | `isVerbal()` Accessor method to check verbal modality.
`boolean` | `isVisual()` Accessor method to check visual modality.
`java.util.Iterator<PrimitivePattern>` | `iterator()` Support iteration over the items of a list pattern.
`boolean` | `matches(Pattern givenPattern)` Two patterns match if they are both ListPatterns and this ListPattern contains a subset of the given pattern.
`ListPattern` | `remove(ListPattern pattern)` Return a new ListPattern forming the parts of this pattern without the matching elements of the given pattern.
`void` | `setFinished()` Set the _finished property to true.
`void` | `setModality(Modality modality)` Mutator to change modality of pattern.
`void` | `setNotFinished()` Set the _finished property to false.
`int` | `size()` Return the number of patterns held inside the list pattern.
`ListPattern` | `sort(java.util.Comparator<PrimitivePattern> comparator)` Return a new list pattern with the items sorted using the given comparator.
`java.lang.String` | `toString()` Render the list pattern as a string.

Methods inherited from class jchrest.lib.Pattern
`makeActionList, makeNumber, makeString, makeVerbalList, makeVerbalList, makeVisualList, makeVisualList`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ListPattern

    public ListPattern()

### ListPattern

    public ListPattern(Modality modality)

Method Detail

### add

    public void add(PrimitivePattern pattern)

  Used in constructing instances by `Pattern` class. Add pattern to list, unless the pattern is 'finished'.

### clone

    public ListPattern clone()

  Construct a copy of this pattern, so that it can be modified without affecting the original.

  Overrides:
    `clone` in class `java.lang.Object`

### size

    public int size()

  Return the number of patterns held inside the list pattern.

### isEmpty

    public boolean isEmpty()

  Check if the list pattern is empty, holding no patterns.

### getItem

    public PrimitivePattern getItem(int index)

  Retrieve the indexed item from the list pattern. There is no check on the validity of the index.

### isFinished

    public boolean isFinished()

  Accessor method to _finished property.

### isSameModality

    public static boolean isSameModality(ListPattern pattern1,
                                         ListPattern pattern2)

  Class level method to check if two patterns have the same modality.

### getModality

    public Modality getModality()

  Accessor to retrieve the modality of the pattern.

### setModality

    public void setModality(Modality modality)

  Mutator to change modality of pattern.

### isVisual

    public boolean isVisual()

  Accessor method to check visual modality.

### isVerbal

    public boolean isVerbal()

  Accessor method to check verbal modality.

### isAction

    public boolean isAction()

  Accessor method to check action modality.

### getModalityString

    public java.lang.String getModalityString()

  Convert the modality into a string.

### setFinished

    public void setFinished()

  Set the _finished property to true.

### setNotFinished

    public void setNotFinished()

  Set the _finished property to false.

### equals

    public boolean equals(ListPattern pattern)

  Two patterns are equal if they contain the same items.

### matches

    public boolean matches(Pattern givenPattern)

  Two patterns match if they are both ListPatterns and this ListPattern contains a subset of the given pattern.

  Specified by:
    `matches` in class `Pattern`

### remove

    public ListPattern remove(ListPattern pattern)

  Return a new ListPattern forming the parts of this pattern without the matching elements of the given pattern.

### append

    public ListPattern append(ListPattern pattern)

  Return a new ListPattern formed from the contents of this list pattern and the contents of the given pattern appended to it.

### append

    public ListPattern append(PrimitivePattern pattern)

  Return a new ListPattern formed from the contents of this list pattern and the given PrimitivePattern appended to it.

### getFirstItem

    public ListPattern getFirstItem()

  Construct a new pattern containing just the first item in this one.

### toString

    public java.lang.String toString()

  Render the list pattern as a string.

  Specified by:
    `toString` in class `Pattern`

### contains

    public boolean contains(PrimitivePattern given)

### isSimilarTo

    public boolean isSimilarTo(ListPattern pattern,
                               int k)

  Compare this list pattern with a given list pattern, returning true if the two share k or more items.

### sort

    public ListPattern sort(java.util.Comparator<PrimitivePattern> comparator)

  Return a new list pattern with the items sorted using the given comparator.

### iterator

    public java.util.Iterator<PrimitivePattern> iterator()

  Support iteration over the items of a list pattern.

  Specified by:
    `iterator` in interface `java.lang.Iterable<PrimitivePattern>`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD