001 /*
002 * Copyright (C) 2008 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package com.google.common.collect;
018
019 import static com.google.common.base.Preconditions.checkArgument;
020 import static com.google.common.base.Preconditions.checkNotNull;
021
022 import com.google.common.annotations.Beta;
023 import com.google.common.annotations.GwtCompatible;
024 import com.google.common.base.Function;
025 import com.google.common.base.Objects;
026 import com.google.common.base.Supplier;
027 import com.google.common.collect.Collections2.TransformedCollection;
028 import com.google.common.collect.Table.Cell;
029
030 import java.io.Serializable;
031 import java.util.Collection;
032 import java.util.Collections;
033 import java.util.Map;
034 import java.util.Set;
035 import java.util.SortedMap;
036 import java.util.SortedSet;
037
038 import javax.annotation.Nullable;
039
040 /**
041 * Provides static methods that involve a {@code Table}.
042 *
043 * <p>See the Guava User Guide article on <a href=
044 * "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Tables">
045 * {@code Tables}</a>.
046 *
047 * @author Jared Levy
048 * @author Louis Wasserman
049 * @since 7.0
050 */
051 @GwtCompatible
052 public final class Tables {
053 private Tables() {}
054
055 /**
056 * Returns an immutable cell with the specified row key, column key, and
057 * value.
058 *
059 * <p>The returned cell is serializable.
060 *
061 * @param rowKey the row key to be associated with the returned cell
062 * @param columnKey the column key to be associated with the returned cell
063 * @param value the value to be associated with the returned cell
064 */
065 public static <R, C, V> Cell<R, C, V> immutableCell(
066 @Nullable R rowKey, @Nullable C columnKey, @Nullable V value) {
067 return new ImmutableCell<R, C, V>(rowKey, columnKey, value);
068 }
069
070 static final class ImmutableCell<R, C, V>
071 extends AbstractCell<R, C, V> implements Serializable {
072 private final R rowKey;
073 private final C columnKey;
074 private final V value;
075
076 ImmutableCell(
077 @Nullable R rowKey, @Nullable C columnKey, @Nullable V value) {
078 this.rowKey = rowKey;
079 this.columnKey = columnKey;
080 this.value = value;
081 }
082
083 public R getRowKey() {
084 return rowKey;
085 }
086 public C getColumnKey() {
087 return columnKey;
088 }
089 public V getValue() {
090 return value;
091 }
092
093 private static final long serialVersionUID = 0;
094 }
095
096 abstract static class AbstractCell<R, C, V> implements Cell<R, C, V> {
097 // needed for serialization
098 AbstractCell() {}
099
100
101 @Override
102 public boolean equals(Object obj) {
103 if (obj == this) {
104 return true;
105 }
106 if (obj instanceof Cell) {
107 Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj;
108 return Objects.equal(getRowKey(), other.getRowKey())
109 && Objects.equal(getColumnKey(), other.getColumnKey())
110 && Objects.equal(getValue(), other.getValue());
111 }
112 return false;
113 }
114
115
116 @Override
117 public int hashCode() {
118 return Objects.hashCode(getRowKey(), getColumnKey(), getValue());
119 }
120
121
122 @Override
123 public String toString() {
124 return "(" + getRowKey() + "," + getColumnKey() + ")=" + getValue();
125 }
126 }
127
128 /**
129 * Creates a transposed view of a given table that flips its row and column
130 * keys. In other words, calling {@code get(columnKey, rowKey)} on the
131 * generated table always returns the same value as calling {@code
132 * get(rowKey, columnKey)} on the original table. Updating the original table
133 * changes the contents of the transposed table and vice versa.
134 *
135 * <p>The returned table supports update operations as long as the input table
136 * supports the analogous operation with swapped rows and columns. For
137 * example, in a {@link HashBasedTable} instance, {@code
138 * rowKeySet().iterator()} supports {@code remove()} but {@code
139 * columnKeySet().iterator()} doesn't. With a transposed {@link
140 * HashBasedTable}, it's the other way around.
141 */
142 public static <R, C, V> Table<C, R, V> transpose(Table<R, C, V> table) {
143 return (table instanceof TransposeTable)
144 ? ((TransposeTable<R, C, V>) table).original
145 : new TransposeTable<C, R, V>(table);
146 }
147
148 private static class TransposeTable<C, R, V> implements Table<C, R, V> {
149 final Table<R, C, V> original;
150
151 TransposeTable(Table<R, C, V> original) {
152 this.original = checkNotNull(original);
153 }
154
155 public void clear() {
156 original.clear();
157 }
158
159 public Map<C, V> column(R columnKey) {
160 return original.row(columnKey);
161 }
162
163 public Set<R> columnKeySet() {
164 return original.rowKeySet();
165 }
166
167 public Map<R, Map<C, V>> columnMap() {
168 return original.rowMap();
169 }
170
171 public boolean contains(
172 @Nullable Object rowKey, @Nullable Object columnKey) {
173 return original.contains(columnKey, rowKey);
174 }
175
176 public boolean containsColumn(@Nullable Object columnKey) {
177 return original.containsRow(columnKey);
178 }
179
180 public boolean containsRow(@Nullable Object rowKey) {
181 return original.containsColumn(rowKey);
182 }
183
184 public boolean containsValue(@Nullable Object value) {
185 return original.containsValue(value);
186 }
187
188 public V get(@Nullable Object rowKey, @Nullable Object columnKey) {
189 return original.get(columnKey, rowKey);
190 }
191
192 public boolean isEmpty() {
193 return original.isEmpty();
194 }
195
196 public V put(C rowKey, R columnKey, V value) {
197 return original.put(columnKey, rowKey, value);
198 }
199
200 public void putAll(Table<? extends C, ? extends R, ? extends V> table) {
201 original.putAll(transpose(table));
202 }
203
204 public V remove(@Nullable Object rowKey, @Nullable Object columnKey) {
205 return original.remove(columnKey, rowKey);
206 }
207
208 public Map<R, V> row(C rowKey) {
209 return original.column(rowKey);
210 }
211
212 public Set<C> rowKeySet() {
213 return original.columnKeySet();
214 }
215
216 public Map<C, Map<R, V>> rowMap() {
217 return original.columnMap();
218 }
219
220 public int size() {
221 return original.size();
222 }
223
224 public Collection<V> values() {
225 return original.values();
226 }
227
228
229 @Override
230 public boolean equals(@Nullable Object obj) {
231 if (obj == this) {
232 return true;
233 }
234 if (obj instanceof Table) {
235 Table<?, ?, ?> other = (Table<?, ?, ?>) obj;
236 return cellSet().equals(other.cellSet());
237 }
238 return false;
239 }
240
241
242 @Override
243 public int hashCode() {
244 return cellSet().hashCode();
245 }
246
247
248 @Override
249 public String toString() {
250 return rowMap().toString();
251 }
252
253 // Will cast TRANSPOSE_CELL to a type that always succeeds
254 private static final Function<Cell<?, ?, ?>, Cell<?, ?, ?>> TRANSPOSE_CELL =
255 new Function<Cell<?, ?, ?>, Cell<?, ?, ?>>() {
256 public Cell<?, ?, ?> apply(Cell<?, ?, ?> cell) {
257 return immutableCell(
258 cell.getColumnKey(), cell.getRowKey(), cell.getValue());
259 }
260 };
261
262 CellSet cellSet;
263
264 public Set<Cell<C, R, V>> cellSet() {
265 CellSet result = cellSet;
266 return (result == null) ? cellSet = new CellSet() : result;
267 }
268
269 class CellSet extends TransformedCollection<Cell<R, C, V>, Cell<C, R, V>>
270 implements Set<Cell<C, R, V>> {
271 // Casting TRANSPOSE_CELL to a type that always succeeds
272 @SuppressWarnings("unchecked")
273 CellSet() {
274 super(original.cellSet(), (Function) TRANSPOSE_CELL);
275 }
276
277
278 @Override
279 public boolean equals(Object obj) {
280 if (obj == this) {
281 return true;
282 }
283 if (!(obj instanceof Set)) {
284 return false;
285 }
286 Set<?> os = (Set<?>) obj;
287 if (os.size() != size()) {
288 return false;
289 }
290 return containsAll(os);
291 }
292
293
294 @Override
295 public int hashCode() {
296 return Sets.hashCodeImpl(this);
297 }
298
299
300 @Override
301 public boolean contains(Object obj) {
302 if (obj instanceof Cell) {
303 Cell<?, ?, ?> cell = (Cell<?, ?, ?>) obj;
304 return original.cellSet().contains(immutableCell(
305 cell.getColumnKey(), cell.getRowKey(), cell.getValue()));
306 }
307 return false;
308 }
309
310
311 @Override
312 public boolean remove(Object obj) {
313 if (obj instanceof Cell) {
314 Cell<?, ?, ?> cell = (Cell<?, ?, ?>) obj;
315 return original.cellSet().remove(immutableCell(
316 cell.getColumnKey(), cell.getRowKey(), cell.getValue()));
317 }
318 return false;
319 }
320 }
321 }
322
323 /**
324 * Creates a table that uses the specified backing map and factory. It can
325 * generate a table based on arbitrary {@link Map} classes.
326 *
327 * <p>The {@code factory}-generated and {@code backingMap} classes determine
328 * the table iteration order. However, the table's {@code row()} method
329 * returns instances of a different class than {@code factory.get()} does.
330 *
331 * <p>Call this method only when the simpler factory methods in classes like
332 * {@link HashBasedTable} and {@link TreeBasedTable} won't suffice.
333 *
334 * <p>The views returned by the {@code Table} methods {@link Table#column},
335 * {@link Table#columnKeySet}, and {@link Table#columnMap} have iterators that
336 * don't support {@code remove()}. Otherwise, all optional operations are
337 * supported. Null row keys, columns keys, and values are not supported.
338 *
339 * <p>Lookups by row key are often faster than lookups by column key, because
340 * the data is stored in a {@code Map<R, Map<C, V>>}. A method call like
341 * {@code column(columnKey).get(rowKey)} still runs quickly, since the row key
342 * is provided. However, {@code column(columnKey).size()} takes longer, since
343 * an iteration across all row keys occurs.
344 *
345 * <p>Note that this implementation is not synchronized. If multiple threads
346 * access this table concurrently and one of the threads modifies the table,
347 * it must be synchronized externally.
348 *
349 * <p>The table is serializable if {@code backingMap}, {@code factory}, the
350 * maps generated by {@code factory}, and the table contents are all
351 * serializable.
352 *
353 * <p>Note: the table assumes complete ownership over of {@code backingMap}
354 * and the maps returned by {@code factory}. Those objects should not be
355 * manually updated and they should not use soft, weak, or phantom references.
356 *
357 * @param backingMap place to store the mapping from each row key to its
358 * corresponding column key / value map
359 * @param factory supplier of new, empty maps that will each hold all column
360 * key / value mappings for a given row key
361 * @throws IllegalArgumentException if {@code backingMap} is not empty
362 * @since 10.0
363 */
364 @Beta
365 public static <R, C, V> Table<R, C, V> newCustomTable(
366 Map<R, Map<C, V>> backingMap, Supplier<? extends Map<C, V>> factory) {
367 checkArgument(backingMap.isEmpty());
368 checkNotNull(factory);
369 // TODO(jlevy): Wrap factory to validate that the supplied maps are empty?
370 return new StandardTable<R, C, V>(backingMap, factory);
371 }
372
373 /**
374 * Returns a view of a table where each value is transformed by a function.
375 * All other properties of the table, such as iteration order, are left
376 * intact.
377 *
378 * <p>Changes in the underlying table are reflected in this view. Conversely,
379 * this view supports removal operations, and these are reflected in the
380 * underlying table.
381 *
382 * <p>It's acceptable for the underlying table to contain null keys, and even
383 * null values provided that the function is capable of accepting null input.
384 * The transformed table might contain null values, if the function sometimes
385 * gives a null result.
386 *
387 * <p>The returned table is not thread-safe or serializable, even if the
388 * underlying table is.
389 *
390 * <p>The function is applied lazily, invoked when needed. This is necessary
391 * for the returned table to be a view, but it means that the function will be
392 * applied many times for bulk operations like {@link Table#containsValue} and
393 * {@code Table.toString()}. For this to perform well, {@code function} should
394 * be fast. To avoid lazy evaluation when the returned table doesn't need to
395 * be a view, copy the returned table into a new table of your choosing.
396 *
397 * @since 10.0
398 */
399 @Beta
400 public static <R, C, V1, V2> Table<R, C, V2> transformValues(
401 Table<R, C, V1> fromTable, Function<? super V1, V2> function) {
402 return new TransformedTable<R, C, V1, V2>(fromTable, function);
403 }
404
405 private static class TransformedTable<R, C, V1, V2>
406 implements Table<R, C, V2> {
407 final Table<R, C, V1> fromTable;
408 final Function<? super V1, V2> function;
409
410 TransformedTable(
411 Table<R, C, V1> fromTable, Function<? super V1, V2> function) {
412 this.fromTable = checkNotNull(fromTable);
413 this.function = checkNotNull(function);
414 }
415
416 public boolean contains(Object rowKey, Object columnKey) {
417 return fromTable.contains(rowKey, columnKey);
418 }
419
420 public boolean containsRow(Object rowKey) {
421 return fromTable.containsRow(rowKey);
422 }
423
424 public boolean containsColumn(Object columnKey) {
425 return fromTable.containsColumn(columnKey);
426 }
427
428 public boolean containsValue(Object value) {
429 return values().contains(value);
430 }
431
432 public V2 get(Object rowKey, Object columnKey) {
433 // The function is passed a null input only when the table contains a null
434 // value.
435 return contains(rowKey, columnKey)
436 ? function.apply(fromTable.get(rowKey, columnKey)) : null;
437 }
438
439 public boolean isEmpty() {
440 return fromTable.isEmpty();
441 }
442
443 public int size() {
444 return fromTable.size();
445 }
446
447 public void clear() {
448 fromTable.clear();
449 }
450
451 public V2 put(R rowKey, C columnKey, V2 value) {
452 throw new UnsupportedOperationException();
453 }
454
455 public void putAll(
456 Table<? extends R, ? extends C, ? extends V2> table) {
457 throw new UnsupportedOperationException();
458 }
459
460 public V2 remove(Object rowKey, Object columnKey) {
461 return contains(rowKey, columnKey)
462 ? function.apply(fromTable.remove(rowKey, columnKey)) : null;
463 }
464
465 public Map<C, V2> row(R rowKey) {
466 return Maps.transformValues(fromTable.row(rowKey), function);
467 }
468
469 public Map<R, V2> column(C columnKey) {
470 return Maps.transformValues(fromTable.column(columnKey), function);
471 }
472
473 Function<Cell<R, C, V1>, Cell<R, C, V2>> cellFunction() {
474 return new Function<Cell<R, C, V1>, Cell<R, C, V2>>() {
475 public Cell<R, C, V2> apply(Cell<R, C, V1> cell) {
476 return immutableCell(
477 cell.getRowKey(), cell.getColumnKey(),
478 function.apply(cell.getValue()));
479 }
480 };
481 }
482
483 class CellSet extends TransformedCollection<Cell<R, C, V1>, Cell<R, C, V2>>
484 implements Set<Cell<R, C, V2>> {
485 CellSet() {
486 super(fromTable.cellSet(), cellFunction());
487 }
488
489 @Override
490 public boolean equals(Object obj) {
491 return Sets.equalsImpl(this, obj);
492 }
493
494 @Override
495 public int hashCode() {
496 return Sets.hashCodeImpl(this);
497 }
498
499 @Override
500 public boolean contains(Object obj) {
501 if (obj instanceof Cell) {
502 Cell<?, ?, ?> cell = (Cell<?, ?, ?>) obj;
503 if (!Objects.equal(
504 cell.getValue(), get(cell.getRowKey(), cell.getColumnKey()))) {
505 return false;
506 }
507 return cell.getValue() != null
508 || fromTable.contains(cell.getRowKey(), cell.getColumnKey());
509 }
510 return false;
511 }
512
513 @Override
514 public boolean remove(Object obj) {
515 if (contains(obj)) {
516 Cell<?, ?, ?> cell = (Cell<?, ?, ?>) obj;
517 fromTable.remove(cell.getRowKey(), cell.getColumnKey());
518 return true;
519 }
520 return false;
521 }
522 }
523
524 CellSet cellSet;
525
526 public Set<Cell<R, C, V2>> cellSet() {
527 return (cellSet == null) ? cellSet = new CellSet() : cellSet;
528 }
529
530 public Set<R> rowKeySet() {
531 return fromTable.rowKeySet();
532 }
533
534 public Set<C> columnKeySet() {
535 return fromTable.columnKeySet();
536 }
537
538 Collection<V2> values;
539
540 public Collection<V2> values() {
541 return (values == null)
542 ? values = Collections2.transform(fromTable.values(), function)
543 : values;
544 }
545
546 Map<R, Map<C, V2>> createRowMap() {
547 Function<Map<C, V1>, Map<C, V2>> rowFunction =
548 new Function<Map<C, V1>, Map<C, V2>>() {
549 public Map<C, V2> apply(Map<C, V1> row) {
550 return Maps.transformValues(row, function);
551 }
552 };
553 return Maps.transformValues(fromTable.rowMap(), rowFunction);
554 }
555
556 Map<R, Map<C, V2>> rowMap;
557
558 public Map<R, Map<C, V2>> rowMap() {
559 return (rowMap == null) ? rowMap = createRowMap() : rowMap;
560 }
561
562 Map<C, Map<R, V2>> createColumnMap() {
563 Function<Map<R, V1>, Map<R, V2>> columnFunction =
564 new Function<Map<R, V1>, Map<R, V2>>() {
565 public Map<R, V2> apply(Map<R, V1> column) {
566 return Maps.transformValues(column, function);
567 }
568 };
569 return Maps.transformValues(fromTable.columnMap(), columnFunction);
570 }
571
572 Map<C, Map<R, V2>> columnMap;
573
574 public Map<C, Map<R, V2>> columnMap() {
575 return (columnMap == null) ? columnMap = createColumnMap() : columnMap;
576 }
577
578
579 @Override
580 public boolean equals(@Nullable Object obj) {
581 if (obj == this) {
582 return true;
583 }
584 if (obj instanceof Table) {
585 Table<?, ?, ?> other = (Table<?, ?, ?>) obj;
586 return cellSet().equals(other.cellSet());
587 }
588 return false;
589 }
590
591
592 @Override
593 public int hashCode() {
594 return cellSet().hashCode();
595 }
596
597
598 @Override
599 public String toString() {
600 return rowMap().toString();
601 }
602 }
603
604 /**
605 * Returns an unmodifiable view of the specified table. This method allows modules to provide
606 * users with "read-only" access to internal tables. Query operations on the returned table
607 * "read through" to the specified table, and attempts to modify the returned table, whether
608 * direct or via its collection views, result in an {@code UnsupportedOperationException}.
609 *
610 * <p>The returned table will be serializable if the specified table is serializable.
611 *
612 * <p>Consider using an {@link ImmutableTable}, which is guaranteed never to change.
613 *
614 * @param table
615 * the table for which an unmodifiable view is to be returned
616 * @return an unmodifiable view of the specified table
617 * @since 11.0
618 */
619 public static <R, C, V> Table<R, C, V> unmodifiableTable(
620 Table<? extends R, ? extends C, ? extends V> table) {
621 return new UnmodifiableTable<R, C, V>(table);
622 }
623
624 private static class UnmodifiableTable<R, C, V>
625 extends ForwardingTable<R, C, V> implements Serializable {
626 final Table<? extends R, ? extends C, ? extends V> delegate;
627
628 UnmodifiableTable(Table<? extends R, ? extends C, ? extends V> delegate) {
629 this.delegate = checkNotNull(delegate);
630 }
631
632
633 @Override
634 @SuppressWarnings("unchecked") // safe, covariant cast
635 protected Table<R, C, V> delegate() {
636 return (Table<R, C, V>) delegate;
637 }
638
639
640 @Override
641 public Set<Cell<R, C, V>> cellSet() {
642 return Collections.unmodifiableSet(super.cellSet());
643 }
644
645
646 @Override
647 public void clear() {
648 throw new UnsupportedOperationException();
649 }
650
651
652 @Override
653 public Map<R, V> column(@Nullable C columnKey) {
654 return Collections.unmodifiableMap(super.column(columnKey));
655 }
656
657
658 @Override
659 public Set<C> columnKeySet() {
660 return Collections.unmodifiableSet(super.columnKeySet());
661 }
662
663
664 @Override
665 public Map<C, Map<R, V>> columnMap() {
666 Function<Map<R, V>, Map<R, V>> wrapper = unmodifiableWrapper();
667 return Collections.unmodifiableMap(Maps.transformValues(super.columnMap(), wrapper));
668 }
669
670
671 @Override
672 public V put(@Nullable R rowKey, @Nullable C columnKey, @Nullable V value) {
673 throw new UnsupportedOperationException();
674 }
675
676
677 @Override
678 public void putAll(Table<? extends R, ? extends C, ? extends V> table) {
679 throw new UnsupportedOperationException();
680 }
681
682
683 @Override
684 public V remove(@Nullable Object rowKey, @Nullable Object columnKey) {
685 throw new UnsupportedOperationException();
686 }
687
688
689 @Override
690 public Map<C, V> row(@Nullable R rowKey) {
691 return Collections.unmodifiableMap(super.row(rowKey));
692 }
693
694
695 @Override
696 public Set<R> rowKeySet() {
697 return Collections.unmodifiableSet(super.rowKeySet());
698 }
699
700
701 @Override
702 public Map<R, Map<C, V>> rowMap() {
703 Function<Map<C, V>, Map<C, V>> wrapper = unmodifiableWrapper();
704 return Collections.unmodifiableMap(Maps.transformValues(super.rowMap(), wrapper));
705 }
706
707
708 @Override
709 public Collection<V> values() {
710 return Collections.unmodifiableCollection(super.values());
711 }
712
713 private static final long serialVersionUID = 0;
714 }
715
716 /**
717 * Returns an unmodifiable view of the specified row-sorted table. This method allows modules to
718 * provide users with "read-only" access to internal tables. Query operations on the returned
719 * table "read through" to the specified table, and attemps to modify the returned table, whether
720 * direct or via its collection views, result in an {@code UnsupportedOperationException}.
721 *
722 * <p>The returned table will be serializable if the specified table is serializable.
723 *
724 * @param table the row-sorted table for which an unmodifiable view is to be returned
725 * @return an unmodifiable view of the specified table
726 * @since 11.0
727 */
728 @Beta
729 public static <R, C, V> RowSortedTable<R, C, V> unmodifiableRowSortedTable(
730 RowSortedTable<R, ? extends C, ? extends V> table) {
731 /*
732 * It's not ? extends R, because it's technically not covariant in R. Specifically,
733 * table.rowMap().comparator() could return a comparator that only works for the ? extends R.
734 * Collections.unmodifiableSortedMap makes the same distinction.
735 */
736 return new UnmodifiableRowSortedMap<R, C, V>(table);
737 }
738
739 static final class UnmodifiableRowSortedMap<R, C, V> extends UnmodifiableTable<R, C, V>
740 implements RowSortedTable<R, C, V> {
741
742 public UnmodifiableRowSortedMap(RowSortedTable<R, ? extends C, ? extends V> delegate) {
743 super(delegate);
744 }
745
746
747 @Override
748 protected RowSortedTable<R, C, V> delegate() {
749 return (RowSortedTable<R, C, V>) super.delegate();
750 }
751
752
753 @Override
754 public SortedMap<R, Map<C, V>> rowMap() {
755 Function<Map<C, V>, Map<C, V>> wrapper = unmodifiableWrapper();
756 return Collections.unmodifiableSortedMap(Maps.transformValues(delegate().rowMap(), wrapper));
757 }
758
759
760 @Override
761 public SortedSet<R> rowKeySet() {
762 return Collections.unmodifiableSortedSet(delegate().rowKeySet());
763 }
764
765 private static final long serialVersionUID = 0;
766 }
767
768 @SuppressWarnings("unchecked")
769 private static <K, V> Function<Map<K, V>, Map<K, V>> unmodifiableWrapper() {
770 return (Function) UNMODIFIABLE_WRAPPER;
771 }
772
773 private static final Function<? extends Map<?, ?>, ? extends Map<?, ?>> UNMODIFIABLE_WRAPPER =
774 new Function<Map<Object, Object>, Map<Object, Object>>() {
775 public Map<Object, Object> apply(Map<Object, Object> input) {
776 return Collections.unmodifiableMap(input);
777 }
778 };
779 }