edu.neu.ccs.demeterf.demfgen.lib
Class Cons<X>

java.lang.Object
  extended by edu.neu.ccs.demeterf.demfgen.lib.List<X>
      extended by edu.neu.ccs.demeterf.demfgen.lib.Cons<X>
All Implemented Interfaces:
java.lang.Iterable<X>

public class Cons<X>
extends List<X>

Represents a Lisp style cons list. You should not use the constructor, use List.push(...) to add an element to the front of the list. It is left public so that the parser generator can parse different lists if needed.


Nested Class Summary
static class Cons.first
           
static class Cons.rest
           
 
Nested classes/interfaces inherited from class edu.neu.ccs.demeterf.demfgen.lib.List
List.Build<X>, List.Comp<X>, List.Fold<X,Y>, List.Map<X,Y>, List.Pred<X>, List.Stringer<X>, List.Zip<X,Y,Z>
 
Field Summary
 X first
           
 List<X> rest
           
 
Constructor Summary
Cons(X f, List<X> r)
           
 
Method Summary
 List<X> add(X a, int i)
          Add an Element to this list at the given index
 List<X> append(List<X> l)
          Append another List to the end of this List
 List<X> append(X t)
          Append an element to the end of this List
 boolean contains(List.Pred<X> p)
          Does this Predicate match anything in this List?
 boolean contains(X t)
          Does the given X occur in this List?
 boolean containsAll(List<X> l)
          Does this List contain all of the given List's Elements?
 boolean containsAll(List<X> l, List.Comp<X> c)
          Does this List contain all of the given List's Elements using the given comparer?
 boolean containsAny(List<X> l)
          Does this List contain any of the given List's Elements?
 boolean equals(java.lang.Object o)
           
 List<X> filter(List.Pred<X> p)
          Filter out all the non-matching Elements
 X find(List.Pred<X> p)
          Return the first matching X, throws a RuntimeException if not there
 X find(X t)
          Return the given X, throws a RuntimeException if not there
<Y> Y
foldl(List.Fold<X,Y> f, Y b)
          Fold this List to a single Value (Left to Right)
<Y> Y
foldr(List.Fold<X,Y> f, Y b)
          Fold this List to a single Value (Right to Left)
 int hashCode()
           
 List<X> insert(X a, List.Comp<X> c)
          Insert an Element into this SORTED list using the given Comparison
 boolean isEmpty()
          Is this List Empty?
 int length()
          The Length of This List
 X lookup(int i)
          Lookup the i^th item in this List
<Y> List<Y>
map(List.Map<X,Y> m)
          Apply a function to each Element of this List
 List<X> pop()
          Return this List without the first Element
 List<X> remove(int i)
          Remove an Element from this list at the given index
 List<X> remove(List.Pred<X> p)
          Remove the first matching X
 List<X> remove(X t)
          Remove the given X
 List<X> replace(int i, X s)
          Replace the element at index 'i' with 's'
 List<X> replace(List.Pred<X> p, X t)
          Replace the first matching X with 't'
 List<X> replace(X t, X s)
          Replace the first occurence of 't' with 's'
 List<X> replaceAll(List.Pred<X> p, X t)
          Replace all matching Xs with 't'
 List<X> replaceAll(X t, X s)
          Replace all occurences of 't' with 's'
 List<X> reverse(List<X> acc)
          Reverse this List with the given Accumulator
 List<X> reverse(List<X> acc, int i)
          Reverse this List with the given Accumulator
 List<X> sort(List.Comp<X> c)
          Sort this List using the given Comparison
 X top()
          Return the first Element of this List
 java.lang.String toString(List.Stringer<X> s)
          To String using a Stringer (Visitor)
 java.lang.String toString(java.lang.String sep, java.lang.String pre)
          To String, with a seperator and prefix
<Y,Z> List<Z>
zip(List.Zip<X,Y,Z> z, List<Y> l)
          Zip two lists (this, and 'l') into a single list, one element at a time
 
Methods inherited from class edu.neu.ccs.demeterf.demfgen.lib.List
buildlist, create, create, filterout, fold, index, index, iterator, pop, push, push, reverse, reverse, same, same, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

first

public final X first

rest

public final List<X> rest
Constructor Detail

Cons

public Cons(X f,
            List<X> r)
Method Detail

append

public List<X> append(List<X> l)
Description copied from class: List
Append another List to the end of this List

Specified by:
append in class List<X>

append

public List<X> append(X t)
Description copied from class: List
Append an element to the end of this List

Specified by:
append in class List<X>

top

public X top()
Description copied from class: List
Return the first Element of this List

Specified by:
top in class List<X>

pop

public List<X> pop()
Description copied from class: List
Return this List without the first Element

Specified by:
pop in class List<X>

isEmpty

public boolean isEmpty()
Description copied from class: List
Is this List Empty?

Specified by:
isEmpty in class List<X>

contains

public boolean contains(X t)
Description copied from class: List
Does the given X occur in this List?

Specified by:
contains in class List<X>

contains

public boolean contains(List.Pred<X> p)
Description copied from class: List
Does this Predicate match anything in this List?

Specified by:
contains in class List<X>

containsAny

public boolean containsAny(List<X> l)
Description copied from class: List
Does this List contain any of the given List's Elements?

Specified by:
containsAny in class List<X>

containsAll

public boolean containsAll(List<X> l)
Description copied from class: List
Does this List contain all of the given List's Elements?

Specified by:
containsAll in class List<X>

containsAll

public boolean containsAll(List<X> l,
                           List.Comp<X> c)
Description copied from class: List
Does this List contain all of the given List's Elements using the given comparer?

Specified by:
containsAll in class List<X>

find

public X find(X t)
Description copied from class: List
Return the given X, throws a RuntimeException if not there

Specified by:
find in class List<X>

find

public X find(List.Pred<X> p)
Description copied from class: List
Return the first matching X, throws a RuntimeException if not there

Specified by:
find in class List<X>

remove

public List<X> remove(X t)
Description copied from class: List
Remove the given X

Specified by:
remove in class List<X>

remove

public List<X> remove(List.Pred<X> p)
Description copied from class: List
Remove the first matching X

Specified by:
remove in class List<X>

lookup

public X lookup(int i)
Description copied from class: List
Lookup the i^th item in this List

Specified by:
lookup in class List<X>

length

public int length()
Description copied from class: List
The Length of This List

Specified by:
length in class List<X>

toString

public java.lang.String toString(java.lang.String sep,
                                 java.lang.String pre)
Description copied from class: List
To String, with a seperator and prefix

Specified by:
toString in class List<X>

toString

public java.lang.String toString(List.Stringer<X> s)
Description copied from class: List
To String using a Stringer (Visitor)

Specified by:
toString in class List<X>

filter

public List<X> filter(List.Pred<X> p)
Description copied from class: List
Filter out all the non-matching Elements

Specified by:
filter in class List<X>

foldr

public <Y> Y foldr(List.Fold<X,Y> f,
                   Y b)
Description copied from class: List
Fold this List to a single Value (Right to Left)

Specified by:
foldr in class List<X>

foldl

public <Y> Y foldl(List.Fold<X,Y> f,
                   Y b)
Description copied from class: List
Fold this List to a single Value (Left to Right)

Specified by:
foldl in class List<X>

map

public <Y> List<Y> map(List.Map<X,Y> m)
Description copied from class: List
Apply a function to each Element of this List

Specified by:
map in class List<X>

add

public List<X> add(X a,
                   int i)
Description copied from class: List
Add an Element to this list at the given index

Specified by:
add in class List<X>

remove

public List<X> remove(int i)
Description copied from class: List
Remove an Element from this list at the given index

Specified by:
remove in class List<X>

insert

public List<X> insert(X a,
                      List.Comp<X> c)
Description copied from class: List
Insert an Element into this SORTED list using the given Comparison

Specified by:
insert in class List<X>

sort

public List<X> sort(List.Comp<X> c)
Description copied from class: List
Sort this List using the given Comparison

Specified by:
sort in class List<X>

reverse

public List<X> reverse(List<X> acc)
Description copied from class: List
Reverse this List with the given Accumulator

Specified by:
reverse in class List<X>

reverse

public List<X> reverse(List<X> acc,
                       int i)
Description copied from class: List
Reverse this List with the given Accumulator

Specified by:
reverse in class List<X>

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

zip

public <Y,Z> List<Z> zip(List.Zip<X,Y,Z> z,
                         List<Y> l)
Description copied from class: List
Zip two lists (this, and 'l') into a single list, one element at a time

Specified by:
zip in class List<X>

replace

public List<X> replace(X t,
                       X s)
Description copied from class: List
Replace the first occurence of 't' with 's'

Specified by:
replace in class List<X>

replace

public List<X> replace(List.Pred<X> p,
                       X t)
Description copied from class: List
Replace the first matching X with 't'

Specified by:
replace in class List<X>

replace

public List<X> replace(int i,
                       X s)
Description copied from class: List
Replace the element at index 'i' with 's'

Specified by:
replace in class List<X>

replaceAll

public List<X> replaceAll(X t,
                          X s)
Description copied from class: List
Replace all occurences of 't' with 's'

Specified by:
replaceAll in class List<X>

replaceAll

public List<X> replaceAll(List.Pred<X> p,
                          X t)
Description copied from class: List
Replace all matching Xs with 't'

Specified by:
replaceAll in class List<X>