public C.List<T> unique(Comparator<T> comp) { Set<T> set = new TreeSet<T>(comp); C.List<T> retList = null; int i = 0; for (T t: this) { i++; if (set.contains(t)) { if (null == retList) { retList = C.newSizedList(size()); retList.addAll(subList(0, i - 1)); } } else if (null != retList) { retList.add(t); } set.add(t); } return null == retList ? this : retList; }
public C.List<T> unique(Comparator<T> comp) { Set<T> set = new TreeSet<T>(comp); C.List<T> retList = null; int i = 0; for (T t: this) { i++; if (set.contains(t)) { if (null == retList) { retList = C.newSizedList(size()); retList.addAll(subList(0, i - 1)); } } else if (null != retList) { retList.add(t); } set.add(t); } return null == retList ? this : retList; }
@Override public C.List<T> unique() { Set<T> set = C.newSet(); C.List<T> retList = null; int i = 0; for (T t: this) { i++; if (set.contains(t)) { if (null == retList) { retList = C.newSizedList(size()); retList.addAll(subList(0, i - 1)); } } else if (null != retList) { retList.add(t); } set.add(t); } return null == retList ? this : retList; }
@Override public C.List<T> unique() { Set<T> set = C.newSet(); C.List<T> retList = null; int i = 0; for (T t: this) { i++; if (set.contains(t)) { if (null == retList) { retList = C.newSizedList(size()); retList.addAll(subList(0, i - 1)); } } else if (null != retList) { retList.add(t); } set.add(t); } return null == retList ? this : retList; }
@Override public C.List<T> take(int n) { boolean immutable = isImmutable(); if (n == 0) { if (immutable) { return Nil.list(); } else { return C.newList(); } } else if (n < 0) { return drop(size() + n); } else if (n >= size()) { return this; } if (immutable) { return subList(0, n); } C.List<T> l = C.newSizedList(n); l.addAll(subList(0, n)); return l; }
@Override public C.List<T> take(int n) { boolean immutable = isImmutable(); if (n == 0) { if (immutable) { return Nil.list(); } else { return C.newList(); } } else if (n < 0) { return drop(size() + n); } else if (n >= size()) { return this; } if (immutable) { return subList(0, n); } C.List<T> l = C.newSizedList(n); l.addAll(subList(0, n)); return l; }
@Override public C.List<T> drop(int n) throws IndexOutOfBoundsException { int sz = size(); boolean immutable = isImmutable(); if (n < 0) { n = -n; if (n >= sz) { if (immutable) return C.newList(); else return C.list(); } else { return take(sz - n); } } if (0 == n) { return this; } // TODO handle lazy drop if (immutable) { return subList(n, size()); } if (n >= sz) { return C.newList(); } C.List<T> l = C.newSizedList(sz - n); l.addAll(subList(n, sz)); return l; }
@Override public C.List<T> drop(int n) throws IndexOutOfBoundsException { int sz = size(); boolean immutable = isImmutable(); if (n < 0) { n = -n; if (n >= sz) { if (immutable) return C.newList(); else return C.list(); } else { return take(sz - n); } } if (0 == n) { return this; } // TODO handle lazy drop if (immutable) { return subList(n, size()); } if (n >= sz) { return C.newList(); } C.List<T> l = C.newSizedList(sz - n); l.addAll(subList(n, sz)); return l; }
@Override public C.List<T> tail(int n) { boolean immutable = isImmutable(); int sz = size(); if (n < 0) { return head(-n); } else if (n == 0) { if (immutable) { return Nil.list(); } else { return C.newList(); } } else if (n >= sz) { return this; } C.List<T> sl = subList(sz - n, sz); if (immutable) { return sl; } C.List<T> l = C.newSizedList(n); l.addAll(sl); return l; }
@Override public C.List<T> tail(int n) { boolean immutable = isImmutable(); int sz = size(); if (n < 0) { return head(-n); } else if (n == 0) { if (immutable) { return Nil.list(); } else { return C.newList(); } } else if (n >= sz) { return this; } C.List<T> sl = subList(sz - n, sz); if (immutable) { return sl; } C.List<T> l = C.newSizedList(n); l.addAll(sl); return l; }