예제 #1
0
파일: List.java 프로젝트: hugobenichi/jpfds
 public void cons(X elem) {
   assertUnpublished();
   if (head.isEmpty()) {
     this.end = new BoundedList<>(elem);
     this.head = this.end;
   } else {
     this.head = new BoundedList<>(elem, this.head);
   }
 }
예제 #2
0
파일: List.java 프로젝트: hugobenichi/jpfds
 public int size() {
   int size = 0;
   Seq<X> seq = this;
   while (seq.nonEmpty()) {
     assert seq.isEmpty() || seq instanceof BoundedList;
     seq = seq.tail();
     size++;
   }
   return size;
 }
예제 #3
0
파일: List.java 프로젝트: hugobenichi/jpfds
 public void add(X elem) {
   assertUnpublished();
   List<X> newEnd = new BoundedList<>(elem);
   if (head.isEmpty()) {
     this.head = newEnd;
     this.end = newEnd;
   } else {
     this.end.tail = newEnd;
     this.end = newEnd;
   }
 }
예제 #4
0
파일: List.java 프로젝트: hugobenichi/jpfds
 /**
  * A covariant constructor for adding an element at the front of a Seq.
  *
  * @param elem an element reference. Can be null.
  * @param tail any type of Seq. Cannot be null.
  * @param <Y> type of the element added at the front of the given Seq.
  * @return a new Seq made of the given arguments using the List class.
  */
 public static <Y> Seq<Y> cons(Y elem, Seq<? extends Y> tail) {
   if (tail.isEmpty() || tail instanceof BoundedList) return new BoundedList<>(elem, tail);
   else return new List<>(elem, tail);
 }