< prev index next >

modules/javafx.base/src/main/java/javafx/beans/binding/ListExpression.java

Print this page




  53  * @param <E> the type of the {@code List} elements.
  54  * @since JavaFX 2.1
  55  */
  56 public abstract class ListExpression<E> implements ObservableListValue<E> {
  57 
  58     private static final ObservableList EMPTY_LIST = FXCollections.emptyObservableList();
  59 
  60     @Override
  61     public ObservableList<E> getValue() {
  62         return get();
  63     }
  64 
  65     /**
  66      * Returns a {@code ListExpression} that wraps a
  67      * {@link javafx.beans.value.ObservableListValue}. If the
  68      * {@code ObservableListValue} is already a {@code ListExpression}, it
  69      * will be returned. Otherwise a new
  70      * {@link javafx.beans.binding.ListBinding} is created that is bound to
  71      * the {@code ObservableListValue}.
  72      *

  73      * @param value
  74      *            The source {@code ObservableListValue}
  75      * @return A {@code ListExpression} that wraps the
  76      *         {@code ObservableListValue} if necessary
  77      * @throws NullPointerException
  78      *             if {@code value} is {@code null}
  79      */
  80     public static <E> ListExpression<E> listExpression(final ObservableListValue<E> value) {
  81         if (value == null) {
  82             throw new NullPointerException("List must be specified.");
  83         }
  84         return value instanceof ListExpression ? (ListExpression<E>) value
  85                 : new ListBinding<E>() {
  86             {
  87                 super.bind(value);
  88             }
  89 
  90             @Override
  91             public void dispose() {
  92                 super.unbind(value);
  93             }
  94 
  95             @Override
  96             protected ObservableList<E> computeValue() {
  97                 return value.get();
  98             }
  99 
 100             @Override
 101             public ObservableList<ObservableListValue<E>> getDependencies() {
 102                 return FXCollections.singletonObservableList(value);
 103             }
 104         };
 105     }
 106 
 107     /**
 108      * The size of the list

 109      */
 110     public int getSize() {
 111         return size();
 112     }
 113 
 114     /**
 115      * An integer property that represents the size of the list.
 116      * @return the property
 117      */
 118     public abstract ReadOnlyIntegerProperty sizeProperty();
 119 
 120     /**
 121      * A boolean property that is {@code true}, if the list is empty.


 122      */
 123     public abstract ReadOnlyBooleanProperty emptyProperty();
 124 
 125     /**
 126      * Creates a new {@link ObjectBinding} that contains the element at the specified position.
 127      * If {@code index} points behind the list, the {@code ObjectBinding} contains {@code null}.
 128      *
 129      * @param index the index of the element
 130      * @return the {@code ObjectBinding}
 131      * @throws IllegalArgumentException if {@code index < 0}
 132      */
 133     public ObjectBinding<E> valueAt(int index) {
 134         return Bindings.valueAt(this, index);
 135     }
 136 
 137     /**
 138      * Creates a new {@link ObjectBinding} that contains the element at the specified position.
 139      * If {@code index} points outside of the list, the {@code ObjectBinding} contains {@code null}.
 140      *
 141      * @param index the index of the element




  53  * @param <E> the type of the {@code List} elements.
  54  * @since JavaFX 2.1
  55  */
  56 public abstract class ListExpression<E> implements ObservableListValue<E> {
  57 
  58     private static final ObservableList EMPTY_LIST = FXCollections.emptyObservableList();
  59 
  60     @Override
  61     public ObservableList<E> getValue() {
  62         return get();
  63     }
  64 
  65     /**
  66      * Returns a {@code ListExpression} that wraps a
  67      * {@link javafx.beans.value.ObservableListValue}. If the
  68      * {@code ObservableListValue} is already a {@code ListExpression}, it
  69      * will be returned. Otherwise a new
  70      * {@link javafx.beans.binding.ListBinding} is created that is bound to
  71      * the {@code ObservableListValue}.
  72      *
  73      * @param <E> the type of the wrapped {@code List}
  74      * @param value
  75      *            The source {@code ObservableListValue}
  76      * @return A {@code ListExpression} that wraps the
  77      *         {@code ObservableListValue} if necessary
  78      * @throws NullPointerException
  79      *             if {@code value} is {@code null}
  80      */
  81     public static <E> ListExpression<E> listExpression(final ObservableListValue<E> value) {
  82         if (value == null) {
  83             throw new NullPointerException("List must be specified.");
  84         }
  85         return value instanceof ListExpression ? (ListExpression<E>) value
  86                 : new ListBinding<E>() {
  87             {
  88                 super.bind(value);
  89             }
  90 
  91             @Override
  92             public void dispose() {
  93                 super.unbind(value);
  94             }
  95 
  96             @Override
  97             protected ObservableList<E> computeValue() {
  98                 return value.get();
  99             }
 100 
 101             @Override
 102             public ObservableList<ObservableListValue<E>> getDependencies() {
 103                 return FXCollections.singletonObservableList(value);
 104             }
 105         };
 106     }
 107 
 108     /**
 109      * The size of the list
 110      * @return the size
 111      */
 112     public int getSize() {
 113         return size();
 114     }
 115 
 116     /**
 117      * An integer property that represents the size of the list.
 118      * @return the property
 119      */
 120     public abstract ReadOnlyIntegerProperty sizeProperty();
 121 
 122     /**
 123      * A boolean property that is {@code true}, if the list is empty.
 124      * @return the {@code ReadOnlyBooleanProperty}
 125      *
 126      */
 127     public abstract ReadOnlyBooleanProperty emptyProperty();
 128 
 129     /**
 130      * Creates a new {@link ObjectBinding} that contains the element at the specified position.
 131      * If {@code index} points behind the list, the {@code ObjectBinding} contains {@code null}.
 132      *
 133      * @param index the index of the element
 134      * @return the {@code ObjectBinding}
 135      * @throws IllegalArgumentException if {@code index < 0}
 136      */
 137     public ObjectBinding<E> valueAt(int index) {
 138         return Bindings.valueAt(this, index);
 139     }
 140 
 141     /**
 142      * Creates a new {@link ObjectBinding} that contains the element at the specified position.
 143      * If {@code index} points outside of the list, the {@code ObjectBinding} contains {@code null}.
 144      *
 145      * @param index the index of the element


< prev index next >