Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 111   Methods: 34
NCLOC: 52   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ImmutableMap.java 0% 0% 0% 0%
coverage
 1    /*BEGIN_COPYRIGHT_BLOCK*
 2   
 3    PLT Utilities BSD License
 4   
 5    Copyright (c) 2007-2010 JavaPLT group at Rice University
 6    All rights reserved.
 7   
 8    Developed by: Java Programming Languages Team
 9    Rice University
 10    http://www.cs.rice.edu/~javaplt/
 11   
 12    Redistribution and use in source and binary forms, with or without modification, are permitted
 13    provided that the following conditions are met:
 14   
 15    - Redistributions of source code must retain the above copyright notice, this list of conditions
 16    and the following disclaimer.
 17    - Redistributions in binary form must reproduce the above copyright notice, this list of
 18    conditions and the following disclaimer in the documentation and/or other materials provided
 19    with the distribution.
 20    - Neither the name of the JavaPLT group, Rice University, nor the names of the library's
 21    contributors may be used to endorse or promote products derived from this software without
 22    specific prior written permission.
 23   
 24    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 25    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 26    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND
 27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 29    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 30    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 31    OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32   
 33    *END_COPYRIGHT_BLOCK*/
 34   
 35    package edu.rice.cs.plt.collect;
 36   
 37    import java.util.*;
 38    import java.io.Serializable;
 39    import edu.rice.cs.plt.lambda.Lambda;
 40    import edu.rice.cs.plt.iter.ImmutableIterator;
 41    import edu.rice.cs.plt.iter.MappedIterator;
 42    import edu.rice.cs.plt.object.Composite;
 43    import edu.rice.cs.plt.object.ObjectUtil;
 44   
 45    /**
 46    * Wraps a map in an immutable interface. Similar to {@link java.util.Collections#unmodifiableMap},
 47    * but this class also implements {@link LambdaMap}. Note that only only <em>this</em>
 48    * interface with the data is immutable -- if the original data structure is mutable, a client with direct
 49    * access to that structure can still mutate it.
 50    */
 51    public class ImmutableMap<K, V> implements LambdaMap<K, V>, Composite, Serializable {
 52   
 53    // using wildcards here allows us to wrap more maps, but means we can't extend DelegatingMap
 54    protected Map<? extends K, ? extends V> _delegate;
 55   
 56  0 public ImmutableMap(Map<? extends K, ? extends V> map) { _delegate = map; }
 57   
 58  0 public int compositeHeight() { return ObjectUtil.compositeHeight(_delegate) + 1; }
 59  0 public int compositeSize() { return ObjectUtil.compositeSize(_delegate) + 1; }
 60   
 61  0 public int size() { return _delegate.size(); }
 62  0 public boolean isEmpty() { return _delegate.isEmpty(); }
 63   
 64  0 public V get(Object key) { return _delegate.get(key); }
 65  0 public V value(K key) { return _delegate.get(key); }
 66   
 67  0 public boolean containsKey(Object o) { return _delegate.containsKey(o); }
 68  0 public boolean containsValue(Object o) { return _delegate.containsValue(o); }
 69   
 70  0 public PredicateSet<K> keySet() { return new ImmutableSet<K>(_delegate.keySet()); }
 71  0 public Collection<V> values() { return Collections.unmodifiableCollection(_delegate.values()); }
 72  0 public Set<Entry<K, V>> entrySet() { return new EntrySet(); }
 73   
 74  0 public V put(K key, V value) { throw new UnsupportedOperationException(); }
 75  0 public void putAll(Map<? extends K, ? extends V> t) { throw new UnsupportedOperationException(); }
 76  0 public V remove(Object key) { throw new UnsupportedOperationException(); }
 77  0 public void clear() { throw new UnsupportedOperationException(); }
 78   
 79  0 public String toString() { return _delegate.toString(); }
 80  0 public boolean equals(Object o) { return _delegate.equals(o); }
 81  0 public int hashCode() { return _delegate.hashCode(); }
 82   
 83    /** Call the constructor (allows {@code K} and {@code V} to be inferred). */
 84  0 public static <K, V> ImmutableMap<K, V> make(Map<? extends K, ? extends V> map) {
 85  0 return new ImmutableMap<K, V>(map);
 86    }
 87   
 88    private final class EntrySet extends AbstractPredicateSet<Entry<K, V>> implements Serializable {
 89  0 @Override public boolean isEmpty() { return _delegate.isEmpty(); }
 90  0 @Override public int size() { return _delegate.size(); }
 91  0 @Override public int size(int bound) { int s = _delegate.size(); return s < bound ? s : bound; }
 92  0 public boolean isInfinite() { return false; }
 93  0 public boolean hasFixedSize() { return false; }
 94  0 public boolean isStatic() { return false; }
 95   
 96  0 public boolean contains(Object o) { return _delegate.entrySet().contains(o); }
 97   
 98  0 public Iterator<Entry<K, V>> iterator() {
 99  0 Lambda<Entry<? extends K, ? extends V>, Entry<K, V>> factory = ImmutableMapEntry.factory();
 100  0 return ImmutableIterator.make(MappedIterator.make(_delegate.entrySet().iterator(), factory));
 101    }
 102   
 103  0 @Override public boolean add(Entry<K, V> o) { throw new UnsupportedOperationException(); }
 104  0 @Override public boolean addAll(Collection<? extends Entry<K, V>> c) { throw new UnsupportedOperationException(); }
 105  0 @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); }
 106  0 @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
 107  0 @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
 108  0 @Override public void clear() { throw new UnsupportedOperationException(); }
 109    }
 110   
 111    }