Coverage Report - com.sun.javafx.runtime.sequence.BoundSequenceElement
 
Classes in this File Line Coverage Branch Coverage Complexity
BoundSequenceElement
100%
8/8
N/A
0
BoundSequenceElement$1
100%
3/3
N/A
0
BoundSequenceElement$MySequenceListener
100%
8/8
88%
7/8
0
 
 1  
 package com.sun.javafx.runtime.sequence;
 2  
 
 3  
 import com.sun.javafx.runtime.location.*;
 4  
 
 5  
 /**
 6  
  * Location representing bind(x[i]), where x and i are locations.  Does not fire change triggers for modifications that
 7  
  * do not affect the value of x[i], such as inserts after i or modifications to elements other than i.  
 8  
  *
 9  
  * @author Brian Goetz
 10  
  */
 11  180
 class BoundSequenceElement<T> extends ObjectVariable<T> implements ObjectLocation<T> {
 12  
     private final SequenceLocation<T> seq;
 13  
     private final IntLocation index;
 14  
     private int lastIndex;
 15  
 
 16  
     public BoundSequenceElement(SequenceLocation<T> seq, IntLocation index) {
 17  10
         super();
 18  10
         this.seq = seq;
 19  10
         this.index = index;
 20  10
         lastIndex = index.get();
 21  10
         bind(false, new ObjectBindingExpression<T>() {
 22  
             public T computeValue() {
 23  34
                 lastIndex = BoundSequenceElement.this.index.get();
 24  34
                 return BoundSequenceElement.this.seq.getAsSequence().get(lastIndex);
 25  
             }
 26  
         }, index);
 27  10
         seq.addChangeListener(new MySequenceListener());
 28  10
     }
 29  
 
 30  20
     private class MySequenceListener implements SequenceChangeListener<T> {
 31  
         public void onChange(int startPos, int endPos, Sequence<? extends T> newElements, Sequence<T> oldValue, Sequence<T> newValue) {
 32  39
             int deltaSize = (endPos-startPos+1) - Sequences.size(newElements);
 33  39
             if (deltaSize != 0) {
 34  31
                 if (startPos <= lastIndex)
 35  17
                     invalidate();
 36  
             }
 37  
             else {
 38  8
                 if (startPos <= lastIndex && lastIndex <= endPos)
 39  5
                     invalidate();
 40  
             }
 41  39
         }
 42  
     }
 43  
 }