コード例 #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);
 }