Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 117   Methods: 20
NCLOC: 65   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IterableCollection.java 11.1% 20.5% 15% 16.9%
coverage 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.AbstractCollection;
 38    import java.util.Iterator;
 39    import java.util.Collection;
 40    import java.io.Serializable;
 41    import edu.rice.cs.plt.iter.SizedIterable;
 42    import edu.rice.cs.plt.iter.IterUtil;
 43    import edu.rice.cs.plt.iter.ImmutableIterator;
 44    import edu.rice.cs.plt.object.Composite;
 45    import edu.rice.cs.plt.object.ObjectUtil;
 46   
 47    /**
 48    * A Collection wrapping an Iterable. Allows iterables to be viewed as collections without creating a
 49    * copy (which would require linear time). Does not support mutation, but does reflect
 50    * changes made to the underlying iterable.
 51    */
 52    public class IterableCollection<E> extends AbstractCollection<E>
 53    implements SizedIterable<E>, Composite, Serializable {
 54   
 55    private final Iterable<? extends E> _iter;
 56    private final boolean _fixedSize;
 57    private int _size; // -1 when uninitialized
 58   
 59  74 public IterableCollection(Iterable<? extends E> iter) {
 60  74 _iter = iter;
 61  74 _fixedSize = IterUtil.hasFixedSize(iter);
 62  74 _size = -1;
 63    }
 64   
 65  0 public int compositeHeight() { return ObjectUtil.compositeHeight(_iter) + 1; }
 66  0 public int compositeSize() { return ObjectUtil.compositeSize(_iter) + 1; }
 67   
 68  0 @Override public boolean isEmpty() {
 69  0 if (_size == -1) { return IterUtil.isEmpty(_iter); }
 70  0 else { return _size == 0; }
 71    }
 72   
 73  74 public int size() {
 74  74 if (_fixedSize) {
 75  74 if (_size == -1) { _size = IterUtil.sizeOf(_iter); }
 76  74 return _size;
 77    }
 78  0 else { return IterUtil.sizeOf(_iter); }
 79    }
 80   
 81  0 public int size(int bound) {
 82  0 if (_fixedSize) {
 83  0 if (_size == -1) {
 84  0 int result = IterUtil.sizeOf(_iter, bound);
 85  0 if (result < bound) { _size = result; }
 86  0 return result;
 87    }
 88  0 else { return (_size < bound) ? _size : bound; }
 89    }
 90  0 else { return IterUtil.sizeOf(_iter, bound); }
 91    }
 92   
 93  0 public boolean isInfinite() { return IterUtil.isInfinite(_iter); }
 94  0 public boolean hasFixedSize() { return _fixedSize; }
 95  0 public boolean isStatic() { return _fixedSize && IterUtil.isStatic(_iter); }
 96   
 97  0 @Override public boolean contains(Object o) {
 98  0 return IterUtil.contains(_iter, o);
 99    }
 100   
 101  74 public Iterator<E> iterator() { return new ImmutableIterator<E>(_iter.iterator()); }
 102   
 103  0 @Override public boolean add(E o) { throw new UnsupportedOperationException(); }
 104  0 @Override public boolean addAll(Collection<? extends E> c) { throw new UnsupportedOperationException(); }
 105  0 @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); }
 106  0 @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
 107  0 @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
 108  0 @Override public void clear() { throw new UnsupportedOperationException(); }
 109   
 110  0 public String toString() { return _iter.toString(); }
 111  0 public boolean equals(Object o) {
 112  0 if (this == o) { return true; }
 113  0 else if (!(o instanceof IterableCollection<?>)) { return false; }
 114  0 else { return _iter.equals(((IterableCollection<?>) o)._iter); }
 115    }
 116  0 public int hashCode() { return IterableCollection.class.hashCode() ^ _iter.hashCode(); }
 117    }