Coverage Report - com.sun.javafx.runtime.location.BoundOperators
 
Classes in this File Line Coverage Branch Coverage Complexity
BoundOperators
75%
12/16
N/A
0
BoundOperators$1
83%
5/6
50%
2/4
0
BoundOperators$10
57%
4/7
100%
2/2
0
BoundOperators$11
43%
3/7
100%
2/2
0
BoundOperators$12
43%
3/7
100%
2/2
0
BoundOperators$13
50%
3/6
100%
2/2
0
BoundOperators$14
7%
3/43
100%
2/2
0
BoundOperators$2
100%
6/6
67%
4/6
0
BoundOperators$3
0%
0/6
0%
0/4
0
BoundOperators$4
0%
0/6
0%
0/6
0
BoundOperators$5
100%
2/2
100%
2/2
0
BoundOperators$6
0%
0/2
0%
0/2
0
BoundOperators$7
100%
2/2
50%
1/2
0
BoundOperators$8
100%
2/2
100%
2/2
0
BoundOperators$9
100%
2/2
100%
2/2
0
 
 1  
 /*
 2  
  * Copyright 2008 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.location;
 27  
 
 28  
 import com.sun.javafx.functions.Function0;
 29  
 import com.sun.javafx.functions.Function1;
 30  
 import com.sun.javafx.runtime.Util;
 31  
 import com.sun.javafx.runtime.sequence.*;
 32  
 
 33  
 /**
 34  
  * Factories for bound operator expressions.  Factories for most operators (plus, ==, !) are generated and live in
 35  
  * GeneratedBoundOperators; these are the hand-written ones.
 36  
  *
 37  
  * @author Brian Goetz
 38  
  */
 39  
 public class BoundOperators extends GeneratedBoundOperators {
 40  
     // non-instantiable
 41  0
     private BoundOperators() { }
 42  
 
 43  
     public static <T, V> BooleanLocation eq_oo(final ObjectLocation<T> a, final ObjectLocation<V> b) {
 44  18
         return BooleanVariable.make(new BooleanBindingExpression() {
 45  
             public boolean computeValue() {
 46  20
                 T aVal = a.get();
 47  20
                 V bVal = b.get();
 48  20
                 if (aVal == null)
 49  20
                     return bVal == null;
 50  
                 else
 51  0
                     return aVal.equals(bVal);
 52  
             }
 53  
         }, a, b);
 54  
     }
 55  
 
 56  
     public static <T, V> BooleanLocation ne_oo(final ObjectLocation<T> a, final ObjectLocation<V> b) {
 57  16
         return BooleanVariable.make(new BooleanBindingExpression() {
 58  
             public boolean computeValue() {
 59  16
                 T aVal = a.get();
 60  16
                 V bVal = b.get();
 61  16
                 if (aVal == null)
 62  2
                     return bVal != null;
 63  
                 else
 64  14
                     return !aVal.equals(bVal);
 65  
             }
 66  
         }, a, b);
 67  
     }
 68  
 
 69  
     public static <T, V> BooleanLocation eq_ss(final SequenceLocation<T> a, final SequenceLocation<V> b) {
 70  0
         return BooleanVariable.make(new BooleanBindingExpression() {
 71  
             public boolean computeValue() {
 72  0
                 Sequence<T> aVal = a.getAsSequence();
 73  0
                 Sequence<V> bVal = b.getAsSequence();
 74  0
                 if (aVal == null)
 75  0
                     return bVal == null;
 76  
                 else
 77  0
                     return aVal.equals(bVal);
 78  
             }
 79  
         }, a, b);
 80  
     }
 81  
 
 82  
     public static <T, V> BooleanLocation ne_ss(final SequenceLocation<T> a, final SequenceLocation<V> b) {
 83  0
         return BooleanVariable.make(new BooleanBindingExpression() {
 84  
             public boolean computeValue() {
 85  0
                 Sequence<T> aVal = a.getAsSequence();
 86  0
                 Sequence<V> bVal = b.getAsSequence();
 87  0
                 if (aVal == null)
 88  0
                     return bVal != null;
 89  
                 else
 90  0
                     return !aVal.equals(bVal);
 91  
             }
 92  
         }, a, b);
 93  
     }
 94  
 
 95  
 
 96  
     public static IntLocation makeBoundIf(boolean lazy,
 97  
                                           final BooleanLocation conditional,
 98  
                                           final Function0<IntLocation> thenBranch,
 99  
                                           final Function0<IntLocation> elseBranch) {
 100  14
         return new IndirectIntExpression(lazy, conditional) {
 101  
             protected IntLocation computeLocation() {
 102  17
                 return (conditional.get()) ? thenBranch.invoke() : elseBranch.invoke();
 103  
             }
 104  
         };
 105  
     }
 106  
 
 107  
     public static DoubleLocation makeBoundIf(boolean lazy,
 108  
                                              final BooleanLocation conditional,
 109  
                                              final Function0<DoubleLocation> thenBranch,
 110  
                                              final Function0<DoubleLocation> elseBranch) {
 111  0
         return new IndirectDoubleExpression(lazy, conditional) {
 112  
             protected DoubleLocation computeLocation() {
 113  0
                 return (conditional.get()) ? thenBranch.invoke() : elseBranch.invoke();
 114  
             }
 115  
         };
 116  
     }
 117  
 
 118  
     public static BooleanLocation makeBoundIf(boolean lazy,
 119  
                                               final BooleanLocation conditional,
 120  
                                               final Function0<BooleanLocation> thenBranch,
 121  
                                               final Function0<BooleanLocation> elseBranch) {
 122  4
         return new IndirectBooleanExpression(lazy, conditional) {
 123  
             protected BooleanLocation computeLocation() {
 124  4
                 return (conditional.get()) ? thenBranch.invoke() : elseBranch.invoke();
 125  
             }
 126  
         };
 127  
     }
 128  
 
 129  
     public static<T> ObjectLocation<T> makeBoundIf(boolean lazy,
 130  
                                                    final BooleanLocation conditional,
 131  
                                                    final Function0<ObjectLocation<T>> thenBranch,
 132  
                                                    final Function0<ObjectLocation<T>> elseBranch) {
 133  42
         return new IndirectObjectExpression<T>(lazy, conditional) {
 134  
             protected ObjectLocation<T> computeLocation() {
 135  54
                 return (conditional.get()) ? thenBranch.invoke() : elseBranch.invoke();
 136  
             }
 137  
         };
 138  
     }
 139  
 
 140  
     public static<T> SequenceLocation<T> makeBoundIf(Class<T> clazz,
 141  
                                                      boolean lazy,
 142  
                                                      final BooleanLocation conditional,
 143  
                                                      final Function0<SequenceLocation<T>> thenBranch,
 144  
                                                      final Function0<SequenceLocation<T>> elseBranch) {
 145  403
         return new IndirectSequenceExpression<T>(clazz, lazy, conditional) {
 146  
             protected SequenceLocation<T> computeLocation() {
 147  914
                 return (conditional.get()) ? thenBranch.invoke() : elseBranch.invoke();
 148  
             }
 149  
         };
 150  
     }
 151  
 
 152  
 
 153  
     public static<T> IntLocation makeBoundSelect(boolean lazy, 
 154  
                                                  final ObjectLocation<T> receiver,
 155  
                                                  final Function1<IntLocation, T> selector) {
 156  11
         return new IndirectIntExpression(lazy, receiver) {
 157  
             protected IntLocation computeLocation() {
 158  24
                 T selectorValue = receiver.get();
 159  24
                 return selectorValue == null ? IntConstant.make(DEFAULT) : selector.invoke(selectorValue);
 160  
             }
 161  
 
 162  
             public int setAsInt(int value) {
 163  
                 // @@@ Shouldn't mutate unconditionally -- only if bound bidirectionally
 164  1
                 return helper.get().setAsInt(value);
 165  
             }
 166  
 
 167  
             public void setDefault() {
 168  0
                 helper.get().setDefault();
 169  0
             }
 170  
 
 171  
             public Integer set(Integer value) {
 172  0
                 return helper.get().set(value);
 173  
             }
 174  
         };
 175  
     }
 176  
 
 177  
     public static<T> DoubleLocation makeBoundSelect(boolean lazy,
 178  
                                                     final ObjectLocation<T> receiver,
 179  
                                                     final Function1<DoubleLocation, T> selector) {
 180  6
         return new IndirectDoubleExpression(lazy, receiver) {
 181  
             protected DoubleLocation computeLocation() {
 182  26
                 T selectorValue = receiver.get();
 183  26
                 return selectorValue == null ? DoubleConstant.make(DEFAULT) : selector.invoke(selectorValue);
 184  
             }
 185  
 
 186  
             public double setAsDouble(double value) {
 187  
                 // @@@ Shouldn't mutate unconditionally -- only if bound bidirectionally
 188  0
                 return helper.get().setAsDouble(value);
 189  
             }
 190  
 
 191  
             public void setDefault() {
 192  0
                 helper.get().setDefault();
 193  0
             }
 194  
 
 195  
             public Double set(Double value) {
 196  0
                 return helper.get().set(value);
 197  
             }
 198  
         };
 199  
     }
 200  
 
 201  
     public static<T> BooleanLocation makeBoundSelect(boolean lazy,
 202  
                                                      final ObjectLocation<T> receiver,
 203  
                                                      final Function1<BooleanLocation, T> selector) {
 204  3
         return new IndirectBooleanExpression(lazy, receiver) {
 205  
             protected BooleanLocation computeLocation() {
 206  9
                 T selectorValue = receiver.get();
 207  9
                 return selectorValue == null ? BooleanConstant.make(DEFAULT) : selector.invoke(selectorValue);
 208  
             }
 209  
 
 210  
             public boolean setAsBoolean(boolean value) {
 211  
                 // @@@ Shouldn't mutate unconditionally -- only if bound bidirectionally
 212  0
                 return helper.get().setAsBoolean(value);
 213  
             }
 214  
 
 215  
             public void setDefault() {
 216  0
                 helper.get().setDefault();
 217  0
             }
 218  
 
 219  
             public Boolean set(Boolean value) {
 220  0
                 return helper.get().set(value);
 221  
             }
 222  
         };
 223  
     }
 224  
 
 225  
     public static<T, U> ObjectLocation<U> makeBoundSelect(final Class clazz,
 226  
                                                           boolean lazy,
 227  
                                                           final ObjectLocation<T> receiver,
 228  
                                                           final Function1<ObjectLocation<U>, T> selector) {
 229  22
         return new IndirectObjectExpression<U>(lazy, receiver) {
 230  
 
 231  
             protected ObjectLocation<U> computeLocation() {
 232  40
                 T selectorValue = receiver.get();
 233  40
                 return selectorValue == null ? ObjectConstant.make(Util.<U>defaultValue(clazz)) : selector.invoke(selectorValue);
 234  
             }
 235  
 
 236  
             public void setDefault() {
 237  0
                 helper.get().setDefault();
 238  0
             }
 239  
 
 240  
             public U set(U value) {
 241  
                 // @@@ Shouldn't mutate unconditionally -- only if bound bidirectionally
 242  0
                 return helper.get().set(value);
 243  
             }
 244  
         };
 245  
     }
 246  
 
 247  
     public static<T, U> SequenceLocation<U> makeBoundSelect(final Class<U> clazz,
 248  
                                                             boolean lazy,
 249  
                                                             final ObjectLocation<T> receiver,
 250  
                                                             final Function1<SequenceLocation<U>, T> selector) {
 251  
 
 252  1
         final SequenceLocation<U> defaultValue = SequenceConstant.<U>make(Sequences.emptySequence(clazz));
 253  
 
 254  1
         return new IndirectSequenceExpression<U>(clazz, lazy, receiver) {
 255  
             // @@@ Sequence triggers are not going to be right.  Need to add a trigger to each "generation" of underlying
 256  
             // sequence location, and propagate sequence triggers to outer Location wrapper
 257  
 
 258  
             protected SequenceLocation<U> computeLocation() {
 259  5
                 T selectorValue = receiver.get();
 260  5
                 return selectorValue == null ? defaultValue : selector.invoke(selectorValue);
 261  
             }
 262  
 
 263  
             public void setDefault() {
 264  0
                 helper.get().setDefault();
 265  0
             }
 266  
 
 267  
             public Sequence<U> setAsSequence(Sequence<? extends U> value) {
 268  
                 // @@@ Shouldn't mutate unconditionally -- only if bound bidirectionally
 269  0
                 return helper.get().setAsSequence(value);
 270  
             }
 271  
 
 272  
             public Sequence<U> set(Sequence<U> value) {
 273  0
                 return helper.get().set(value);
 274  
             }
 275  
 
 276  
             public U set(int position, U newValue) {
 277  0
                 return helper.get().set(position, newValue);
 278  
             }
 279  
 
 280  
             public Sequence<? extends U> replaceSlice(int startPos, int endPos, Sequence<? extends U> newValues) {
 281  0
                 return helper.get().replaceSlice(startPos, endPos, newValues);
 282  
             }
 283  
 
 284  
             public void delete(int position) {
 285  0
                 helper.get().delete(position);
 286  0
             }
 287  
 
 288  
             public void deleteSlice(int startPos, int endPos) {
 289  0
                 helper.get().deleteSlice(startPos, endPos);
 290  0
             }
 291  
 
 292  
             public void delete(SequencePredicate<U> tSequencePredicate) {
 293  0
                 helper.get().delete(tSequencePredicate);
 294  0
             }
 295  
 
 296  
             public void deleteAll() {
 297  0
                 helper.get().deleteAll();
 298  0
             }
 299  
 
 300  
             public void deleteValue(U targetValue) {
 301  0
                 helper.get().deleteValue(targetValue);
 302  0
             }
 303  
 
 304  
             public void insert(U value) {
 305  0
                 helper.get().insert(value);
 306  0
             }
 307  
 
 308  
             public void insert(Sequence<? extends U> values) {
 309  0
                 helper.get().insert(values);
 310  0
             }
 311  
 
 312  
             public void insertFirst(U value) {
 313  0
                 helper.get().insertFirst(value);
 314  0
             }
 315  
 
 316  
             public void insertFirst(Sequence<? extends U> values) {
 317  0
                 helper.get().insertFirst(values);
 318  0
             }
 319  
 
 320  
             public void insertBefore(U value, int position) {
 321  0
                 helper.get().insertBefore(value, position);
 322  0
             }
 323  
 
 324  
             public void insertBefore(U value, SequencePredicate<U> tSequencePredicate) {
 325  0
                 helper.get().insertBefore(value, tSequencePredicate);
 326  0
             }
 327  
 
 328  
             public void insertBefore(Sequence<? extends U> values, int position) {
 329  0
                 helper.get().insertBefore(values, position);
 330  0
             }
 331  
 
 332  
             public void insertBefore(Sequence<? extends U> values, SequencePredicate<U> tSequencePredicate) {
 333  0
                 helper.get().insertBefore(values, tSequencePredicate);
 334  0
             }
 335  
 
 336  
             public void insertAfter(U value, int position) {
 337  0
                 helper.get().insertAfter(value, position);
 338  0
             }
 339  
 
 340  
             public void insertAfter(U value, SequencePredicate<U> tSequencePredicate) {
 341  0
                 helper.get().insertAfter(value, tSequencePredicate);
 342  0
             }
 343  
 
 344  
             public void insertAfter(Sequence<? extends U> values, int position) {
 345  0
                 helper.get().insertAfter(values, position);
 346  0
             }
 347  
 
 348  
             public void insertAfter(Sequence<? extends U> values, SequencePredicate<U> tSequencePredicate) {
 349  0
                 helper.get().insertAfter(values, tSequencePredicate);
 350  0
             }
 351  
         };
 352  
     }
 353  
 
 354  
 }