Coverage Report - com.sun.javafx.runtime.sequence.AbstractBoundSequence
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractBoundSequence
56%
42/75
60%
12/20
0
AbstractBoundSequence$1
0%
0/3
N/A
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.sequence;
 27  
 
 28  
 import java.util.Iterator;
 29  
 import java.util.List;
 30  
 import java.util.ArrayList;
 31  
 
 32  
 import com.sun.javafx.runtime.location.*;
 33  
 
 34  
 /**
 35  
  * Abstract base class for bound sequences.  Subclass constructors are expected to compute the initial value, set up
 36  
  * any required triggers on dependent objects, and call the setInitialValue() method to provide a value.  (This places
 37  
  * limits on designing subclasses for further inheritance.)  The setInitialValue() method must be called exactly once.
 38  
  *
 39  
  * @author Brian Goetz
 40  
  */
 41  88
 public abstract class AbstractBoundSequence<T> extends AbstractLocation implements SequenceLocation<T> {
 42  
     private final Class<T> clazz;
 43  
     private List<SequenceChangeListener<T>> changeListeners;
 44  
     private Sequence<T> value;
 45  
 
 46  
     // Currently, no support for lazy binding.
 47  
 
 48  1346
     protected AbstractBoundSequence(Class<T> clazz) {
 49  1346
         this.clazz = clazz;
 50  1346
         this.value = Sequences.emptySequence(clazz);
 51  1346
     }
 52  
 
 53  
     protected void setInitialValue(Sequence<T> initialValue) {
 54  1346
         if (isValid())
 55  0
             throw new IllegalStateException("Cannot call setInitialValue more than once");
 56  1346
         Sequence<T> oldValue = value;
 57  1346
         Sequence<T> newValue = initialValue;
 58  1346
         if (newValue == null)
 59  0
             newValue = Sequences.emptySequence(clazz);
 60  1346
         value = newValue;
 61  1346
         setValid();
 62  1346
         if (!Sequences.isEqual(oldValue, newValue)) {
 63  859
             invalidateDependencies();
 64  859
             notifyListeners(0, Sequences.size(oldValue)-1, newValue, oldValue, newValue);
 65  
         }
 66  1346
     }
 67  
 
 68  
     protected void updateSlice(int startPos, int endPos, Sequence<? extends T> newValues) {
 69  985
         Sequence<T> oldValue = value;
 70  985
         value = oldValue.replaceSlice(startPos, endPos, newValues);
 71  985
         invalidateDependencies();
 72  985
         notifyListeners(startPos, endPos, newValues, oldValue, value);
 73  985
     }
 74  
 
 75  
     protected void updateSlice(int startPos, int endPos, Sequence<? extends T> newValues, Sequence<T> newSequence) {
 76  48
         Sequence<T> oldValue = value;
 77  48
         value = newSequence;
 78  48
         invalidateDependencies();
 79  48
         notifyListeners(startPos, endPos, newValues, oldValue, newSequence);
 80  48
     }
 81  
 
 82  
     protected Sequence<T> getRawValue() {
 83  51
         return value;
 84  
     }
 85  
 
 86  
     protected Class<T> getClazz() {
 87  907
         return clazz;
 88  
     }
 89  
 
 90  
     public Sequence<T> get() {
 91  61
         return getAsSequence();
 92  
     }
 93  
 
 94  
     public T get(int position) {
 95  0
         return getAsSequence().get(position);
 96  
     }
 97  
 
 98  
     public Sequence<T> getAsSequence() {
 99  1824
         assert(isValid());
 100  1824
         return value;
 101  
     }
 102  
 
 103  
     public Sequence<T> getSlice(int startPos, int endPos) {
 104  5
         return getAsSequence().getSlice(startPos, endPos);
 105  
     }
 106  
 
 107  
     public boolean isNull() {
 108  0
         return Sequences.size(getAsSequence()) == 0;
 109  
     }
 110  
 
 111  
     public void addChangeListener(final ObjectChangeListener<Sequence<T>> listener) {
 112  0
         addChangeListener(new SequenceChangeListener<T>() {
 113  
             public void onChange(int startPos, int endPos, Sequence<? extends T> newElements, Sequence<T> oldValue, Sequence<T> newValue) {
 114  0
                 listener.onChange(oldValue, newValue);
 115  0
             }
 116  
         });
 117  0
     }
 118  
 
 119  
     public void addChangeListener(SequenceChangeListener<T> listener) {
 120  418
         if (changeListeners == null)
 121  417
             changeListeners = new ArrayList<SequenceChangeListener<T>>();
 122  418
         changeListeners.add(listener);
 123  418
     }
 124  
 
 125  
     public void removeChangeListener(SequenceChangeListener<T> listener) {
 126  70
         if (changeListeners != null)
 127  70
             changeListeners.remove(listener);
 128  70
     }
 129  
 
 130  
     private void notifyListeners(final int startPos, final int endPos,
 131  
                                  final Sequence<? extends T> newElements,
 132  
                                  final Sequence<T> oldValue, final Sequence<T> newValue) {
 133  1892
         if (changeListeners != null) {
 134  1032
             for (SequenceChangeListener<T> listener : changeListeners)
 135  1023
                 listener.onChange(startPos, endPos, newElements, oldValue, newValue);
 136  
         }
 137  1892
     }
 138  
 
 139  
     public Iterator<T> iterator() {
 140  0
         return getAsSequence().iterator();
 141  
     }
 142  
 
 143  
     @Override
 144  
     public String toString() {
 145  0
         return getAsSequence().toString();
 146  
     }
 147  
 
 148  
     @Override
 149  
     public void invalidate() {
 150  0
         throw new UnsupportedOperationException();
 151  
     }
 152  
 
 153  
     public void setDefault() {
 154  0
         throw new UnsupportedOperationException();
 155  
     }
 156  
 
 157  
     public T set(int position, T value) {
 158  0
         throw new UnsupportedOperationException();
 159  
     }
 160  
 
 161  
     public Sequence<T> set(Sequence<T> value) {
 162  0
         throw new UnsupportedOperationException();
 163  
     }
 164  
 
 165  
     public Sequence<T> setFromLiteral(Sequence<T> value) {
 166  0
         throw new UnsupportedOperationException();
 167  
     }
 168  
 
 169  
     public Sequence<T> setAsSequence(Sequence<? extends T> value) {
 170  0
         throw new UnsupportedOperationException();
 171  
     }
 172  
 
 173  
     public Sequence<T> setAsSequenceFromLiteral(Sequence<? extends T> value) {
 174  0
         throw new UnsupportedOperationException();
 175  
     }
 176  
 
 177  
     public Sequence<? extends T> replaceSlice(int startPos, int endPos, Sequence<? extends T> newValues) {
 178  0
         throw new UnsupportedOperationException();
 179  
     }
 180  
 
 181  
     public void delete(int position) {
 182  0
         throw new UnsupportedOperationException();
 183  
     }
 184  
 
 185  
     public void deleteSlice(int startPos, int endPos) {
 186  0
         throw new UnsupportedOperationException();
 187  
     }
 188  
 
 189  
     public void deleteAll() {
 190  0
         throw new UnsupportedOperationException();
 191  
     }
 192  
 
 193  
     public void deleteValue(T value) {
 194  0
         throw new UnsupportedOperationException();
 195  
     }
 196  
 
 197  
     public void delete(SequencePredicate<T> sequencePredicate) {
 198  0
         throw new UnsupportedOperationException();
 199  
     }
 200  
 
 201  
     public void insert(T value) {
 202  0
         throw new UnsupportedOperationException();
 203  
     }
 204  
 
 205  
     public void insert(Sequence<? extends T> values) {
 206  0
         throw new UnsupportedOperationException();
 207  
     }
 208  
 
 209  
     public void insertFirst(T value) {
 210  0
         throw new UnsupportedOperationException();
 211  
     }
 212  
 
 213  
     public void insertFirst(Sequence<? extends T> values) {
 214  0
         throw new UnsupportedOperationException();
 215  
     }
 216  
 
 217  
     public void insertBefore(T value, int position) {
 218  0
         throw new UnsupportedOperationException();
 219  
     }
 220  
 
 221  
     public void insertBefore(T value, SequencePredicate<T> sequencePredicate) {
 222  0
         throw new UnsupportedOperationException();
 223  
     }
 224  
 
 225  
     public void insertBefore(Sequence<? extends T> values, int position) {
 226  0
         throw new UnsupportedOperationException();
 227  
     }
 228  
 
 229  
     public void insertBefore(Sequence<? extends T> values, SequencePredicate<T> sequencePredicate) {
 230  0
         throw new UnsupportedOperationException();
 231  
     }
 232  
 
 233  
     public void insertAfter(T value, int position) {
 234  0
         throw new UnsupportedOperationException();
 235  
     }
 236  
 
 237  
     public void insertAfter(T value, SequencePredicate<T> sequencePredicate) {
 238  0
         throw new UnsupportedOperationException();
 239  
     }
 240  
 
 241  
     public void insertAfter(Sequence<? extends T> values, int position) {
 242  0
         throw new UnsupportedOperationException();
 243  
     }
 244  
 
 245  
     public void insertAfter(Sequence<? extends T> values, SequencePredicate<T> sequencePredicate) {
 246  0
         throw new UnsupportedOperationException();
 247  
     }
 248  
 }