View Javadoc

    1   package sharin.unlinq;
    2
    3   import java.util.ArrayList;
    4   import java.util.Collection;
    5   import java.util.Comparator;
    6   import java.util.Iterator;
    7   import java.util.List;
    8   import java.util.ListIterator;
    9   import java.util.Map;
    10
    11  public class BasicEnumerableList<T> implements EnumerableList<T> {
    12
    13      private final List<T> list;
    14
    15      public BasicEnumerableList() {
    16          this(null);
    17      }
    18
    19      public BasicEnumerableList(List<T> list) {
    20
    21          if (list == null) {
    22              list = new ArrayList<T>();
    23          }
    24
    25          this.list = list;
    26      }
    27
    28      private Enumerable<T> getEnumerable() {
    29          return new BasicEnumerable<T>(list);
    30      }
    31
    32      @Override
    33      public String toString() {
    34          return list.toString();
    35      }
    36
    37      public void add(int index, T element) {
    38          list.add(index, element);
    39      }
    40
    41      public boolean add(T o) {
    42          return list.add(o);
    43      }
    44
    45      public boolean addAll(Collection<? extends T> c) {
    46          return list.addAll(c);
    47      }
    48
    49      public boolean addAll(int index, Collection<? extends T> c) {
    50          return list.addAll(index, c);
    51      }
    52
    53      public void clear() {
    54          list.clear();
    55      }
    56
    57      public boolean contains(Object o) {
    58          return list.contains(o);
    59      }
    60
    61      public boolean containsAll(Collection<?> c) {
    62          return list.containsAll(c);
    63      }
    64
    65      @Override
    66      public boolean equals(Object o) {
    67          return list.equals(o);
    68      }
    69
    70      public T get(int index) {
    71          return list.get(index);
    72      }
    73
    74      @Override
    75      public int hashCode() {
    76          return list.hashCode();
    77      }
    78
    79      public int indexOf(Object o) {
    80          return list.indexOf(o);
    81      }
    82
    83      public boolean isEmpty() {
    84          return list.isEmpty();
    85      }
    86
    87      public Iterator<T> iterator() {
    88          return list.iterator();
    89      }
    90
    91      public int lastIndexOf(Object o) {
    92          return list.lastIndexOf(o);
    93      }
    94
    95      public ListIterator<T> listIterator() {
    96          return list.listIterator();
    97      }
    98
    99      public ListIterator<T> listIterator(int index) {
    100         return list.listIterator(index);
    101     }
    102
    103     public T remove(int index) {
    104         return list.remove(index);
    105     }
    106
    107     public boolean remove(Object o) {
    108         return list.remove(o);
    109     }
    110
    111     public boolean removeAll(Collection<?> c) {
    112         return list.removeAll(c);
    113     }
    114
    115     public boolean retainAll(Collection<?> c) {
    116         return list.retainAll(c);
    117     }
    118
    119     public T set(int index, T element) {
    120         return list.set(index, element);
    121     }
    122
    123     public int size() {
    124         return list.size();
    125     }
    126
    127     public List<T> subList(int fromIndex, int toIndex) {
    128         return list.subList(fromIndex, toIndex);
    129     }
    130
    131     public Object[] toArray() {
    132         return list.toArray();
    133     }
    134
    135     public <R> R[] toArray(R[] a) {
    136         return list.toArray(a);
    137     }
    138
    139     public <A, R> R aggregate(A seed, Func2<A, T, A> func,
    140             Func<A, R> resultSelector) {
    141         return getEnumerable().aggregate(seed, func, resultSelector);
    142     }
    143
    144     public <A> A aggregate(A seed, Func2<A, T, A> func) {
    145         return getEnumerable().aggregate(seed, func);
    146     }
    147
    148     public T aggregate(Func2<T, T, T> func) {
    149         return getEnumerable().aggregate(func);
    150     }
    151
    152     public Boolean all(Func<T, Boolean> predicate) {
    153         return getEnumerable().all(predicate);
    154     }
    155
    156     public Boolean any() {
    157         return getEnumerable().any();
    158     }
    159
    160     public Boolean any(Func<T, Boolean> predicate) {
    161         return getEnumerable().any(predicate);
    162     }
    163
    164     public double average() {
    165         return getEnumerable().average();
    166     }
    167
    168     public double average(Func<T, Integer> selector) {
    169         return getEnumerable().average(selector);
    170     }
    171
    172     public double averageDouble() {
    173         return getEnumerable().averageDouble();
    174     }
    175
    176     public double averageDouble(Func<T, Double> selector) {
    177         return getEnumerable().averageDouble(selector);
    178     }
    179
    180     public float averageFloat() {
    181         return getEnumerable().averageFloat();
    182     }
    183
    184     public float averageFloat(Func<T, Float> selector) {
    185         return getEnumerable().averageFloat(selector);
    186     }
    187
    188     public double averageLong() {
    189         return getEnumerable().averageLong();
    190     }
    191
    192     public double averageLong(Func<T, Long> selector) {
    193         return getEnumerable().averageLong(selector);
    194     }
    195
    196     public <R> Enumerable<R> cast(Class<R> resultClass) {
    197         return getEnumerable().cast(resultClass);
    198     }
    199
    200     public Enumerable<T> concat(Enumerable<T> second) {
    201         return getEnumerable().concat(second);
    202     }
    203
    204     public int count() {
    205         return getEnumerable().count();
    206     }
    207
    208     public int count(Func<T, Boolean> predicate) {
    209         return getEnumerable().count(predicate);
    210     }
    211
    212     public Enumerable<T> defaultIfEmpty() {
    213         return getEnumerable().defaultIfEmpty();
    214     }
    215
    216     public Enumerable<T> defaultIfEmpty(T defaultValue) {
    217         return getEnumerable().defaultIfEmpty(defaultValue);
    218     }
    219
    220     public Enumerable<T> distinct() {
    221         return getEnumerable().distinct();
    222     }
    223
    224     public T elementAt(int index) {
    225         return getEnumerable().elementAt(index);
    226     }
    227
    228     public T elementAtOrDefault(int index, T defaultValue) {
    229         return getEnumerable().elementAtOrDefault(index, defaultValue);
    230     }
    231
    232     public T elementAtOrDefault(int index) {
    233         return getEnumerable().elementAtOrDefault(index);
    234     }
    235
    236     public Enumerable<T> except(Enumerable<T> second) {
    237         return getEnumerable().except(second);
    238     }
    239
    240     public T first() {
    241         return getEnumerable().first();
    242     }
    243
    244     public T first(Func<T, Boolean> predicate) {
    245         return getEnumerable().first(predicate);
    246     }
    247
    248     public T firstOrDefault() {
    249         return getEnumerable().firstOrDefault();
    250     }
    251
    252     public T firstOrDefault(Func<T, Boolean> predicate, T defaultValue) {
    253         return getEnumerable().firstOrDefault(predicate, defaultValue);
    254     }
    255
    256     public T firstOrDefault(Func<T, Boolean> predicate) {
    257         return getEnumerable().firstOrDefault(predicate);
    258     }
    259
    260     public T firstOrDefault(T defaultValue) {
    261         return getEnumerable().firstOrDefault(defaultValue);
    262     }
    263
    264     public <K, E, R> Enumerable<R> groupBy(Func<T, K> keySelector,
    265             Func<T, E> elementSelector,
    266             Func2<K, Enumerable<E>, R> resultSelector) {
    267         return getEnumerable().groupBy(keySelector, elementSelector,
    268                 resultSelector);
    269     }
    270
    271     public <K, E> Enumerable<Grouping<K, E>> groupBy(Func<T, K> keySelector,
    272             Func<T, E> elementSelector) {
    273         return getEnumerable().groupBy(keySelector, elementSelector);
    274     }
    275
    276     public <K, R> Enumerable<R> groupBy(Func<T, K> keySelector,
    277             Func2<K, Enumerable<T>, R> resultSelector) {
    278         return getEnumerable().groupBy(keySelector, resultSelector);
    279     }
    280
    281     public <K> Enumerable<Grouping<K, T>> groupBy(Func<T, K> keySelector) {
    282         return getEnumerable().groupBy(keySelector);
    283     }
    284
    285     public <I, K, R> Enumerable<R> groupJoin(Enumerable<I> inner,
    286             Func<T, K> outerKeySelector, Func<I, K> innerKeySelector,
    287             Func2<T, Enumerable<I>, R> resultSelector) {
    288         return getEnumerable().groupJoin(inner, outerKeySelector,
    289                 innerKeySelector, resultSelector);
    290     }
    291
    292     public Enumerable<T> intersect(Enumerable<T> second) {
    293         return getEnumerable().intersect(second);
    294     }
    295
    296     public <I, K, R> Enumerable<R> join(Enumerable<I> inner,
    297             Func<T, K> outerKeySelector, Func<I, K> innerKeySelector,
    298             Func2<T, I, R> resultSelector) {
    299         return getEnumerable().join(inner, outerKeySelector, innerKeySelector,
    300                 resultSelector);
    301     }
    302
    303     public T last() {
    304         return getEnumerable().last();
    305     }
    306
    307     public T last(Func<T, Boolean> predicate) {
    308         return getEnumerable().last(predicate);
    309     }
    310
    311     public T lastOrDefault() {
    312         return getEnumerable().lastOrDefault();
    313     }
    314
    315     public T lastOrDefault(Func<T, Boolean> predicate, T defaultValue) {
    316         return getEnumerable().lastOrDefault(predicate, defaultValue);
    317     }
    318
    319     public T lastOrDefault(Func<T, Boolean> predicate) {
    320         return getEnumerable().lastOrDefault(predicate);
    321     }
    322
    323     public T lastOrDefault(T defaultValue) {
    324         return getEnumerable().lastOrDefault(defaultValue);
    325     }
    326
    327     public long longCount() {
    328         return getEnumerable().longCount();
    329     }
    330
    331     public long longCount(Func<T, Boolean> predicate) {
    332         return getEnumerable().longCount(predicate);
    333     }
    334
    335     public T max() {
    336         return getEnumerable().max();
    337     }
    338
    339     public <R extends Comparable<R>> R max(Func<T, R> selector) {
    340         return getEnumerable().max(selector);
    341     }
    342
    343     public T min() {
    344         return getEnumerable().min();
    345     }
    346
    347     public <R extends Comparable<R>> R min(Func<T, R> selector) {
    348         return getEnumerable().min(selector);
    349     }
    350
    351     public <R> Enumerable<R> ofType(Class<R> resultClass) {
    352         return getEnumerable().ofType(resultClass);
    353     }
    354
    355     public <K> OrderedEnumerable<T> orderBy(Func<T, K> keySelector,
    356             Comparator<K> comparator) {
    357         return getEnumerable().orderBy(keySelector, comparator);
    358     }
    359
    360     public <K> OrderedEnumerable<T> orderBy(Func<T, K> keySelector) {
    361         return getEnumerable().orderBy(keySelector);
    362     }
    363
    364     public <K> OrderedEnumerable<T> orderByDescending(Func<T, K> keySelector,
    365             Comparator<K> comparator) {
    366         return getEnumerable().orderByDescending(keySelector, comparator);
    367     }
    368
    369     public <K> OrderedEnumerable<T> orderByDescending(Func<T, K> keySelector) {
    370         return getEnumerable().orderByDescending(keySelector);
    371     }
    372
    373     public Enumerable<T> reverse() {
    374         return getEnumerable().reverse();
    375     }
    376
    377     public <R> Enumerable<R> select(Func<T, R> selector) {
    378         return getEnumerable().select(selector);
    379     }
    380
    381     public <R> Enumerable<R> select(Func2<T, Integer, R> selector) {
    382         return getEnumerable().select(selector);
    383     }
    384
    385     public <C, R> Enumerable<R> selectMany(
    386             Func<T, Enumerable<C>> collectionSelector,
    387             Func2<T, C, R> resultSelector) {
    388         return getEnumerable().selectMany(collectionSelector, resultSelector);
    389     }
    390
    391     public <R> Enumerable<R> selectMany(Func<T, Enumerable<R>> selector) {
    392         return getEnumerable().selectMany(selector);
    393     }
    394
    395     public <C, R> Enumerable<R> selectMany(
    396             Func2<T, Integer, Enumerable<C>> collectionSelector,
    397             Func2<T, C, R> resultSelector) {
    398         return getEnumerable().selectMany(collectionSelector, resultSelector);
    399     }
    400
    401     public <R> Enumerable<R> selectMany(
    402             Func2<T, Integer, Enumerable<R>> selector) {
    403         return getEnumerable().selectMany(selector);
    404     }
    405
    406     public Boolean sequenceEqual(Enumerable<T> second) {
    407         return getEnumerable().sequenceEqual(second);
    408     }
    409
    410     public T single() {
    411         return getEnumerable().single();
    412     }
    413
    414     public T single(Func<T, Boolean> predicate) {
    415         return getEnumerable().single(predicate);
    416     }
    417
    418     public T singleOrDefault() {
    419         return getEnumerable().singleOrDefault();
    420     }
    421
    422     public T singleOrDefault(Func<T, Boolean> predicate, T defaultValue) {
    423         return getEnumerable().singleOrDefault(predicate, defaultValue);
    424     }
    425
    426     public T singleOrDefault(Func<T, Boolean> predicate) {
    427         return getEnumerable().singleOrDefault(predicate);
    428     }
    429
    430     public T singleOrDefault(T defaultValue) {
    431         return getEnumerable().singleOrDefault(defaultValue);
    432     }
    433
    434     public Enumerable<T> skip(int count) {
    435         return getEnumerable().skip(count);
    436     }
    437
    438     public Enumerable<T> skipWhile(Func<T, Boolean> predicate) {
    439         return getEnumerable().skipWhile(predicate);
    440     }
    441
    442     public Enumerable<T> skipWhile(Func2<T, Integer, Boolean> predicate) {
    443         return getEnumerable().skipWhile(predicate);
    444     }
    445
    446     public int sum() {
    447         return getEnumerable().sum();
    448     }
    449
    450     public int sum(Func<T, Integer> selector) {
    451         return getEnumerable().sum(selector);
    452     }
    453
    454     public double sumDouble() {
    455         return getEnumerable().sumDouble();
    456     }
    457
    458     public double sumDouble(Func<T, Double> selector) {
    459         return getEnumerable().sumDouble(selector);
    460     }
    461
    462     public float sumFloat() {
    463         return getEnumerable().sumFloat();
    464     }
    465
    466     public float sumFloat(Func<T, Float> selector) {
    467         return getEnumerable().sumFloat(selector);
    468     }
    469
    470     public long sumLong() {
    471         return getEnumerable().sumLong();
    472     }
    473
    474     public long sumLong(Func<T, Long> selector) {
    475         return getEnumerable().sumLong(selector);
    476     }
    477
    478     public Enumerable<T> take(int count) {
    479         return getEnumerable().take(count);
    480     }
    481
    482     public Enumerable<T> takeWhile(Func<T, Boolean> predicate) {
    483         return getEnumerable().takeWhile(predicate);
    484     }
    485
    486     public Enumerable<T> takeWhile(Func2<T, Integer, Boolean> predicate) {
    487         return getEnumerable().takeWhile(predicate);
    488     }
    489
    490     public <R> R[] toArray(Class<R> resultClass) {
    491         return getEnumerable().toArray(resultClass);
    492     }
    493
    494     public <K, E> Dictionary<K, E> toDictionary(Func<T, K> keySelector,
    495             Func<T, E> elementSelector) {
    496         return getEnumerable().toDictionary(keySelector, elementSelector);
    497     }
    498
    499     public <K> Dictionary<K, T> toDictionary(Func<T, K> keySelector) {
    500         return getEnumerable().toDictionary(keySelector);
    501     }
    502
    503     public List<T> toList() {
    504         return getEnumerable().toList();
    505     }
    506
    507     public EnumerableList<T> toEnumerableList() {
    508         return getEnumerable().toEnumerableList();
    509     }
    510
    511     public <K> Map<K, List<T>> toListMap(Func<T, K> keySelector) {
    512         return getEnumerable().toListMap(keySelector);
    513     }
    514
    515     public <K, E> Map<K, List<E>> toListMap(Func<T, K> keySelector,
    516             Func<T, E> elementSelector) {
    517         return getEnumerable().toListMap(keySelector, elementSelector);
    518     }
    519
    520     public <K, E> Lookup<K, E> toLookup(Func<T, K> keySelector,
    521             Func<T, E> elementSelector) {
    522         return getEnumerable().toLookup(keySelector, elementSelector);
    523     }
    524
    525     public <K> Lookup<K, T> toLookup(Func<T, K> keySelector) {
    526         return getEnumerable().toLookup(keySelector);
    527     }
    528
    529     public Enumerable<T> union(Enumerable<T> second) {
    530         return getEnumerable().union(second);
    531     }
    532
    533     public Enumerable<T> where(Func<T, Boolean> predicate) {
    534         return getEnumerable().where(predicate);
    535     }
    536
    537     public Enumerable<T> where(Func2<T, Integer, Boolean> predicate) {
    538         return getEnumerable().where(predicate);
    539     }
    540
    541     public <K> Map<K, T> toMap(Func<T, K> keySelector) {
    542         return getEnumerable().toMap(keySelector);
    543     }
    544
    545     public <K, E> Map<K, E> toMap(Func<T, K> keySelector,
    546             Func<T, E> elementSelector) {
    547         return getEnumerable().toMap(keySelector, elementSelector);
    548     }
    549 }