Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.collections;
027
028import java.util.Collection;
029import java.util.Comparator;
030import java.util.List;
031import java.util.function.Predicate;
032
033import javafx.beans.Observable;
034import javafx.collections.transformation.FilteredList;
035import javafx.collections.transformation.SortedList;
036
037/**
038 * A list that allows listeners to track changes when they occur.
039 *
040 * @see ListChangeListener
041 * @see ListChangeListener.Change
042 * @param <E> the list element type
043 */
044public interface ObservableList<E> extends List<E>, Observable {
045    /**
046     * Add a listener to this observable list.
047     * @param listener the listener for listening to the list changes
048     */
049    public void addListener(ListChangeListener<? super E> listener);
050
051    /**
052     * Tries to removed a listener from this observable list. If the listener is not
053     * attached to this list, nothing happens.
054     * @param listener a listener to remove
055     */
056    public void removeListener(ListChangeListener<? super E> listener);
057
058    /**
059     * A convenient method for var-arg adding of elements.
060     * @param elements the elements to add
061     * @return true (as specified by Collection.add(E))
062     */
063    public boolean addAll(E... elements);
064
065    /**
066     * Clears the ObservableList and add all the elements passed as var-args.
067     * @param elements the elements to set
068     * @return true (as specified by Collection.add(E))
069     * @throws NullPointerException if the specified arguments contain one or more null elements
070     */
071    public boolean setAll(E... elements);
072
073    /**
074     * Clears the ObservableList and add all elements from the collection.
075     * @param col the collection with elements that will be added to this observableArrayList
076     * @return true (as specified by Collection.add(E))
077     * @throws NullPointerException if the specified collection contains one or more null elements
078     */
079    public boolean setAll(Collection<? extends E> col);
080
081    /**
082     * A convenient method for var-arg usage of removaAll method.
083     * @param elements the elements to be removed
084     * @return true if list changed as a result of this call
085     */
086    public boolean removeAll(E... elements);
087
088    /**
089     * A convenient method for var-arg usage of retain method.
090     * @param elements the elements to be retained
091     * @return true if list changed as a result of this call
092     */
093    public boolean retainAll(E... elements);
094
095    /**
096     * Basically a shortcut to sublist(from, to).clear()
097     * As this is a common operation, ObservableList has this method for convenient usage.
098     * @param from the start of the range to remove (inclusive)
099     * @param to the end of the range to remove (exclusive)
100     * @throws IndexOutOfBoundsException if an illegal range is provided
101     */
102    public void remove(int from, int to);
103
104    /**
105     * Creates a {@link FilteredList} wrapper of this list using
106     * the specified predicate.
107     * @param predicate the predicate to use
108     * @return new {@code FilteredList}
109     */
110    public default FilteredList<E> filtered(Predicate<E> predicate) {
111        return new FilteredList<>(this, predicate);
112    }
113
114    /**
115     * Creates a {@link SortedList} wrapper of this list using
116     * the specified comparator.
117     * @param comparator the comparator to use or null for the natural order
118     * @return new {@code SortedList}
119     */
120    public default SortedList<E> sorted(Comparator<E> comparator) {
121        return new SortedList<>(this, comparator);
122    }
123
124    /**
125     * Creates a {@link SortedList} wrapper of this list with the natural
126     * ordering.
127     * @return new {@code SortedList}
128     */
129    public default SortedList<E> sorted() {
130        return sorted(null);
131    }
132}