Coverage Report - com.sun.javafx.runtime.sequence.BoundSequences
 
Classes in this File Line Coverage Branch Coverage Complexity
BoundSequences
47%
18/38
0%
0/4
0
BoundSequences$1
100%
2/2
N/A
0
BoundSequences$10
0%
0/3
N/A
0
BoundSequences$11
0%
0/3
N/A
0
BoundSequences$2
100%
2/2
N/A
0
BoundSequences$3
0%
0/2
0%
0/2
0
BoundSequences$4
0%
0/2
N/A
0
BoundSequences$5
100%
2/2
N/A
0
BoundSequences$6
0%
0/2
N/A
0
BoundSequences$7
0%
0/2
N/A
0
BoundSequences$8
0%
0/3
N/A
0
BoundSequences$9
100%
3/3
N/A
0
BoundSequences$BooleanBoundComprehensionCallback
N/A
N/A
0
BoundSequences$BooleanSimpleBoundComprehensionCallback
N/A
N/A
0
BoundSequences$DoubleBoundComprehensionCallback
N/A
N/A
0
BoundSequences$DoubleSimpleBoundComprehensionCallback
N/A
N/A
0
BoundSequences$IntBoundComprehensionCallback
N/A
N/A
0
BoundSequences$IntSimpleBoundComprehensionCallback
N/A
N/A
0
BoundSequences$ObjectBoundComprehensionCallback
N/A
N/A
0
BoundSequences$ObjectSimpleBoundComprehensionCallback
N/A
N/A
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 com.sun.javafx.runtime.location.*;
 29  
 
 30  
 /**
 31  
  * BoundSequences
 32  
  *
 33  
  * @author Brian Goetz
 34  
  */
 35  0
 public class BoundSequences {
 36  
     /**
 37  
      * Construct a bound sequence of the form
 38  
      *   bind [ a, b, ... ]
 39  
      * where a, b, ..., are sequence locations.
 40  
      *  
 41  
      */
 42  
     public static <T> SequenceLocation<T> concatenate(Class<T> clazz, SequenceLocation<? extends T>... locations) {
 43  0
         return new BoundCompositeSequence<T>(clazz, locations);
 44  
     }
 45  
 
 46  
     /**
 47  
      * Construct a bound sequence of the form
 48  
      *   bind [ a, b, ... ]
 49  
      * where a, b, ..., are sequence locations.
 50  
      *
 51  
      */
 52  
     public static <T> SequenceLocation<T> concatenate(Class<T> clazz, SequenceLocation<? extends T>[] locations, int size) {
 53  38
         return new BoundCompositeSequence<T>(clazz, locations, size);
 54  
     }
 55  
 
 56  
     /**
 57  
      * Construct a bound sequence of the form
 58  
      *   bind a
 59  
      * where a is a sequence location of a subtype of the desired element type
 60  
      *
 61  
      */
 62  
     @SuppressWarnings("unchecked")
 63  
     public static <T, V extends T> SequenceLocation<T> upcast(Class<T> clazz, SequenceLocation<V> location) {
 64  0
         Class<V> vClass = location.getAsSequence().getElementType();
 65  0
         if (clazz == vClass)
 66  0
             return (SequenceLocation<T>) location;
 67  0
         else if (!clazz.isAssignableFrom(vClass))
 68  0
             throw new ClassCastException("Cannot upcast Sequence<" + vClass.getName()
 69  
                     + "> to Sequence<" + clazz.getName() + ">");
 70  
         else
 71  0
             return new BoundUpcastSequence<T, V>(clazz, location);
 72  
     }
 73  
 
 74  
     /** Construct a bound sequence of the form
 75  
      *   bind reverse x
 76  
      * where x is a sequence.
 77  
      */
 78  
     public static<T> SequenceLocation<T> reverse(SequenceLocation<T> sequence) {
 79  1
         return new BoundReverseSequence<T>(sequence);
 80  
     }
 81  
 
 82  
     /** Construct a bound sequence of the form
 83  
      *   bind [ x ]
 84  
      * where x is an instance.
 85  
      */
 86  
     public static<T, V extends T> SequenceLocation<T> singleton(Class<T> clazz, ObjectLocation<V> location) {
 87  665
         return new BoundSingletonSequence<T, V>(clazz, location);
 88  
     }
 89  
 
 90  
     /** Construct a bound sequence of the form
 91  
      *   bind [ x ]
 92  
      * where x is an Integer instance.
 93  
      */
 94  
     public static<T> SequenceLocation<Integer> singleton(IntLocation location) {
 95  0
         return new BoundSingletonSequence<Integer, Integer>(Integer.class, location);
 96  
     }
 97  
 
 98  
     public static<T> SequenceLocation<T> empty(final Class<T> clazz) {
 99  486
         return new AbstractBoundSequence<T>(clazz) {
 100  486
             { setInitialValue(Sequences.emptySequence(clazz)); }
 101  
         };
 102  
     }
 103  
 
 104  
     public static<T> ObjectLocation<T> element(SequenceLocation<T> sequence, IntLocation index) {
 105  1
         return new BoundSequenceElement<T>(sequence, index);
 106  
     }
 107  
 
 108  
     public static IntLocation element(SequenceLocation<Integer> sequence, IntLocation index) {
 109  9
         return Locations.asIntLocation(new BoundSequenceElement<Integer>(sequence, index));
 110  
     }
 111  
 
 112  
     public static DoubleLocation element(SequenceLocation<Double> sequence, IntLocation index) {
 113  0
         return Locations.asDoubleLocation(new BoundSequenceElement<Double>(sequence, index));
 114  
     }
 115  
 
 116  
     public static BooleanLocation element(SequenceLocation<Boolean> sequence, IntLocation index) {
 117  0
         return Locations.asBooleanLocation(new BoundSequenceElement<Boolean>(sequence, index));
 118  
     }
 119  
 
 120  
     public static<T> IntLocation sizeof(final SequenceLocation<T> sequence) {
 121  1
         return IntVariable.make(new IntBindingExpression() {
 122  
             public int computeValue() {
 123  3
                 return Sequences.size(sequence.get());
 124  
             }
 125  
         }, sequence);
 126  
     }
 127  
 
 128  
     public static<T> IntLocation sizeof(final ObjectLocation<T> item) {
 129  0
         return IntVariable.make(new IntBindingExpression() {
 130  
             public int computeValue() {
 131  0
                 return item.get() == null ? 0 : 1;
 132  
             }
 133  
         }, item);
 134  
     }
 135  
 
 136  
     public static SequenceLocation<Integer> range(IntLocation a, IntLocation b) {
 137  34
         return new BoundIntRangeSequence(a, b);
 138  
     }
 139  
     
 140  
     public static SequenceLocation<Integer> range(IntLocation a, IntLocation b, IntLocation step) {
 141  6
         return new BoundIntRangeSequence(a, b, step);
 142  
     }
 143  
 
 144  
     public static SequenceLocation<Integer> range(IntLocation a, IntLocation b, boolean exclusive) {
 145  4
         return new BoundIntRangeSequence(a, b, exclusive);
 146  
     }
 147  
 
 148  
     public static SequenceLocation<Integer> range(IntLocation a, IntLocation b, IntLocation step, boolean exclusive) {
 149  5
         return new BoundIntRangeSequence(a, b, step, exclusive);
 150  
     }
 151  
 
 152  
     
 153  
     public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b) {
 154  1
         return new BoundNumberRangeSequence(a, b);
 155  
     }
 156  
     
 157  
     public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b, DoubleLocation step) {
 158  0
         return new BoundNumberRangeSequence(a, b, step);
 159  
     }
 160  
 
 161  
     public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b, boolean exclusive) {
 162  1
         return new BoundNumberRangeSequence(a, b, exclusive);
 163  
     }
 164  
 
 165  
     public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b, DoubleLocation step, boolean exclusive) {
 166  1
         return new BoundNumberRangeSequence(a, b, step, exclusive);
 167  
     }
 168  
     
 169  
     public static<T> SequenceLocation<T> slice(Class<T> clazz, SequenceLocation<T> sequence, IntLocation a, IntLocation b) {
 170  5
         return new BoundSequenceSlice<T>(clazz, sequence, a, b, false);
 171  
     }
 172  
     
 173  
     public static<T> SequenceLocation<T> sliceExclusive(Class<T> clazz, SequenceLocation<T> sequence, IntLocation a, IntLocation b) {
 174  3
         return new BoundSequenceSlice<T>(clazz, sequence, a, b, true);
 175  
     }
 176  
     
 177  
     public interface ObjectSimpleBoundComprehensionCallback<T, V> {
 178  
          V computeElement$(T element, int index);
 179  
     }
 180  
 
 181  
     public interface IntSimpleBoundComprehensionCallback<V> {
 182  
          V computeElement$(int element, int index);
 183  
     }
 184  
 
 185  
     public interface DoubleSimpleBoundComprehensionCallback<V> {
 186  
          V computeElement$(double element, int index);
 187  
     }
 188  
 
 189  
     public interface BooleanSimpleBoundComprehensionCallback<V> {
 190  
         V computeElement$(boolean element, int index);
 191  
     }
 192  
 
 193  
     public static<T, V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz,
 194  
                                                                          SequenceLocation<T> seq,
 195  
                                                                          boolean useIndex,
 196  
                                                                          final ObjectSimpleBoundComprehensionCallback<T, V> callback) {
 197  0
         return new SimpleBoundComprehension<T, V>(clazz, seq, useIndex) {
 198  
             protected V computeElement$(T element, int index) {
 199  0
                 return callback.computeElement$(element, index);
 200  
             }
 201  
         };
 202  
     }
 203  
 
 204  
     public static<V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz,
 205  
                                                                       SequenceLocation<Integer> seq,
 206  
                                                                       boolean useIndex,
 207  
                                                                       final IntSimpleBoundComprehensionCallback<V> callback) {
 208  5
         return new SimpleBoundComprehension<Integer, V>(clazz, seq, useIndex) {
 209  
             protected V computeElement$(Integer element, int index) {
 210  37
                 return callback.computeElement$(element, index);
 211  
             }
 212  
         };
 213  
     }
 214  
 
 215  
     public static<V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz,
 216  
                                                                       SequenceLocation<Double> seq,
 217  
                                                                       boolean useIndex,
 218  
                                                                       final DoubleSimpleBoundComprehensionCallback<V> callback) {
 219  0
         return new SimpleBoundComprehension<Double, V>(clazz, seq, useIndex) {
 220  
             protected V computeElement$(Double element, int index) {
 221  0
                 return callback.computeElement$(element, index);
 222  
             }
 223  
         };
 224  
     }
 225  
 
 226  
     public static<V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz,
 227  
                                                                       SequenceLocation<Boolean> seq,
 228  
                                                                       boolean useIndex,
 229  
                                                                       final BooleanSimpleBoundComprehensionCallback<V> callback) {
 230  0
         return new SimpleBoundComprehension<Boolean, V>(clazz, seq, useIndex) {
 231  
             protected V computeElement$(Boolean element, int index) {
 232  0
                 return callback.computeElement$(element, index);
 233  
             }
 234  
         };
 235  
     }
 236  
 
 237  
     public interface ObjectBoundComprehensionCallback<T, V> {
 238  
          SequenceLocation<V> computeElements$(ObjectLocation<T> elementLocation, IntLocation indexLocation);
 239  
     }
 240  
 
 241  
     public interface IntBoundComprehensionCallback<T> {
 242  
          SequenceLocation<T> computeElements$(IntLocation elementLocation, IntLocation indexLocation);
 243  
     }
 244  
 
 245  
     public interface DoubleBoundComprehensionCallback<T> {
 246  
          SequenceLocation<T> computeElements$(DoubleLocation elementLocation, IntLocation indexLocation);
 247  
     }
 248  
 
 249  0
     public interface BooleanBoundComprehensionCallback<T> {
 250  
          SequenceLocation<T> computeElements$(BooleanLocation elementLocation, IntLocation indexLocation);
 251  
     }
 252  
 
 253  
     public static<T, V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz,
 254  
                                                                    SequenceLocation<T> sequenceLocation,
 255  
                                                                    boolean useIndex,
 256  
                                                                    final ObjectBoundComprehensionCallback<T, V> callback) {
 257  0
         return new AbstractBoundComprehension<T, ObjectLocation<T>, V>(clazz, sequenceLocation, useIndex) {
 258  
             protected ObjectLocation<T> makeInductionLocation(T value) {
 259  0
                 return ObjectVariable.<T>make(value);
 260  
             }
 261  
 
 262  
             protected SequenceLocation<V> computeElements$(ObjectLocation<T> elementLocation, IntLocation indexLocation) {
 263  0
                 return callback.computeElements$(elementLocation, indexLocation);
 264  
             }
 265  
         };
 266  
     }
 267  
 
 268  
     public static<V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz,
 269  
                                                                    SequenceLocation<Integer> sequenceLocation,
 270  
                                                                    boolean useIndex,
 271  
                                                                    final IntBoundComprehensionCallback<V> callback) {
 272  105
         return new AbstractBoundComprehension<Integer, IntLocation, V>(clazz, sequenceLocation, useIndex) {
 273  
             protected IntLocation makeInductionLocation(Integer value) {
 274  48
                 return IntVariable.make(value);
 275  
             }
 276  
 
 277  
             protected SequenceLocation<V> computeElements$(IntLocation elementLocation, IntLocation indexLocation) {
 278  48
                 return callback.computeElements$(elementLocation, indexLocation);
 279  
             }
 280  
         };
 281  
     }
 282  
 
 283  
     public static<V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz,
 284  
                                                                 SequenceLocation<Double> sequenceLocation,
 285  
                                                                 boolean useIndex,
 286  
                                                                 final DoubleBoundComprehensionCallback<V> callback) {
 287  0
         return new AbstractBoundComprehension<Double, DoubleLocation, V>(clazz, sequenceLocation, useIndex) {
 288  
             protected DoubleLocation makeInductionLocation(Double value) {
 289  0
                 return DoubleVariable.make(value);
 290  
             }
 291  
 
 292  
             protected SequenceLocation<V> computeElements$(DoubleLocation elementLocation, IntLocation indexLocation) {
 293  0
                 return callback.computeElements$(elementLocation, indexLocation);
 294  
             }
 295  
         };
 296  
     }
 297  
 
 298  
     public static<V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz,
 299  
                                                                 SequenceLocation<Boolean> sequenceLocation,
 300  
                                                                 boolean useIndex,
 301  
                                                                 final BooleanBoundComprehensionCallback<V> callback) {
 302  0
         return new AbstractBoundComprehension<Boolean, BooleanLocation, V>(clazz, sequenceLocation, useIndex) {
 303  
             protected BooleanLocation makeInductionLocation(Boolean value) {
 304  0
                 return BooleanVariable.make(value);
 305  
             }
 306  
 
 307  
             protected SequenceLocation<V> computeElements$(BooleanLocation elementLocation, IntLocation indexLocation) {
 308  0
                 return callback.computeElements$(elementLocation, indexLocation);
 309  
             }
 310  
         };
 311  
     }
 312  
     
 313  
 }