equal
deleted
inserted
replaced
69 |
69 |
70 /** Construct an empty list. |
70 /** Construct an empty list. |
71 */ |
71 */ |
72 @SuppressWarnings("unchecked") |
72 @SuppressWarnings("unchecked") |
73 public static <A> List<A> nil() { |
73 public static <A> List<A> nil() { |
74 return EMPTY_LIST; |
74 return (List<A>)EMPTY_LIST; |
75 } |
75 } |
76 private static List EMPTY_LIST = new List<Object>(null,null) { |
76 |
|
77 private static List<?> EMPTY_LIST = new List<Object>(null,null) { |
77 public List<Object> setTail(List<Object> tail) { |
78 public List<Object> setTail(List<Object> tail) { |
78 throw new UnsupportedOperationException(); |
79 throw new UnsupportedOperationException(); |
79 } |
80 } |
80 public boolean isEmpty() { |
81 public boolean isEmpty() { |
81 return true; |
82 return true; |
316 return false; |
317 return false; |
317 } |
318 } |
318 |
319 |
319 /** Are the two lists the same? |
320 /** Are the two lists the same? |
320 */ |
321 */ |
321 public static boolean equals(List xs, List ys) { |
322 public static boolean equals(List<?> xs, List<?> ys) { |
322 while (xs.tail != null && ys.tail != null) { |
323 while (xs.tail != null && ys.tail != null) { |
323 if (xs.head == null) { |
324 if (xs.head == null) { |
324 if (ys.head != null) return false; |
325 if (ys.head != null) return false; |
325 } else { |
326 } else { |
326 if (!xs.head.equals(ys.head)) return false; |
327 if (!xs.head.equals(ys.head)) return false; |
366 for (Object o : list) |
367 for (Object o : list) |
367 klass.cast(o); |
368 klass.cast(o); |
368 return (List<T>)list; |
369 return (List<T>)list; |
369 } |
370 } |
370 |
371 |
371 private static Iterator EMPTYITERATOR = new Iterator() { |
372 private static Iterator<?> EMPTYITERATOR = new Iterator<Object>() { |
372 public boolean hasNext() { |
373 public boolean hasNext() { |
373 return false; |
374 return false; |
374 } |
375 } |
375 public Object next() { |
376 public Object next() { |
376 throw new java.util.NoSuchElementException(); |
377 throw new java.util.NoSuchElementException(); |
380 } |
381 } |
381 }; |
382 }; |
382 |
383 |
383 @SuppressWarnings("unchecked") |
384 @SuppressWarnings("unchecked") |
384 private static <A> Iterator<A> emptyIterator() { |
385 private static <A> Iterator<A> emptyIterator() { |
385 return EMPTYITERATOR; |
386 return (Iterator<A>)EMPTYITERATOR; |
386 } |
387 } |
387 |
388 |
388 @Override |
389 @Override |
389 public Iterator<A> iterator() { |
390 public Iterator<A> iterator() { |
390 if (tail == null) |
391 if (tail == null) |