Coverage Report - com.sun.javafx.runtime.sequence.FilterSequence
 
Classes in this File Line Coverage Branch Coverage Complexity
FilterSequence
100%
11/11
100%
6/6
0
 
 1  
 /*
 2  
  * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 5  
  * This code is free software; you can redistribute it and/or modify it
 6  
  * under the terms of the GNU General Public License version 2 only, as
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file that accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  
  * version 2 for more details (a copy is included in the LICENSE file that
 15  
  * accompanied this code).
 16  
  *
 17  
  * You should have received a copy of the GNU General Public License version
 18  
  * 2 along with this work; if not, write to the Free Software Foundation,
 19  
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  
  *
 21  
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package com.sun.javafx.runtime.sequence;
 27  
 
 28  
 import java.util.BitSet;
 29  
 
 30  
 /**
 31  
  * Represents a view of another sequence that has some elements removed, suitable for "delete from" or foo[predicate]
 32  
  * sequence operations.  Instances of FilterSequence should be constructed with the Sequences.filter() factory, rather
 33  
  * than with the FilterSequence constructor.  O(newElementCount) space and time construction costs.
 34  
  *
 35  
  * @author Brian Goetz
 36  
  */
 37  
 class FilterSequence<T> extends AbstractSequence<T> implements Sequence<T> {
 38  
 
 39  
     private final Sequence<? extends T> sequence;
 40  
     private final int[] indices;
 41  
 
 42  
     public FilterSequence(Sequence<T> sequence, BitSet bits) {
 43  1024
         super(sequence.getElementType());
 44  1024
         this.sequence = sequence;
 45  1024
         indices = new int[bits.cardinality()];
 46  20272
         for (int i = bits.nextSetBit(0), next = 0; i >= 0; i = bits.nextSetBit(i + 1))
 47  19248
             indices[next++] = i;
 48  1024
     }
 49  
 
 50  
     @Override
 51  
     public int size() {
 52  18893
         return indices.length;
 53  
     }
 54  
 
 55  
 
 56  
     @Override
 57  
     public int getDepth() {
 58  1162
         return sequence.getDepth() + 1;
 59  
     }
 60  
 
 61  
     @Override
 62  
     public T get(int position) {
 63  37950
         if (position < 0 || position >= indices.length)
 64  512
             throw new IndexOutOfBoundsException(Integer.toString(position));
 65  
         else
 66  37438
             return sequence.get(indices[position]);
 67  
     }
 68  
 }