View Javadoc

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