E
- リストに含まれる要素の型public abstract class ObservableListBase<E> extends AbstractList<E> implements ObservableList<E>
ObservableList
実装のベース・クラスとして役立つ抽象クラス。ベース・クラスは、クラスを実装する2つの機能を提供します。
addListener
メソッドおよびremoveListener
メソッドの実装によるリスナー処理。Change
オブジェクトを使用してリスナーに通知するためのfireChange(javafx.collections.ListChangeListener.Change)
メソッドが提供されます。
ListChangeListener.Change
オブジェクトを作成するメソッド。next*
と呼ばれる様々なメソッドがあります。たとえば、リストに新しいアイテムを追加するnextAdd(int, int)
、またはリストからアイテムを削除するnextRemove(int, java.lang.Object)
などです。
これらのメソッドは、常にbeginChange()
とendChange()
ブロックで囲む必要があります。
次の例を参照してください。
public void removeOddIndexes() { beginChange(); try { for (int i = 1; i < size(); ++i) { remove(i); } } finally { endChange(); } } public void remove(int i) { beginChange(); try { E removed = ... //do some stuff that will actually remove the element at index i nextRemove(i, removed); } finally { endChange(); } }例の
try
/finally
ブロックは、beginChange()
/endChange()
ブロック内で例外が発生する可能性がある場合のみ必要となります。
注意: 変更可能なObservableList
実装を作成する場合は、ModifiableObservableListBase
をスーパークラスとして使用することを検討してください。
注意: 順次アクセスしてリストを作成するには、AbstractList.listIterator()
メソッド、AbstractList.iterator()
メソッドをオーバーライドし、これらをAbstractList.get(int)
メソッド、AbstractCollection.size()
メソッドおよび他のメソッドで適宜使用する必要があります。
ObservableList
, ListChangeListener.Change
, ModifiableObservableListBase
modCount
コンストラクタと説明 |
---|
ObservableListBase() |
修飾子と型 | メソッドと説明 |
---|---|
boolean |
addAll(E... elements)
要素の可変引数を追加する便利なメソッド。
|
void |
addListener(InvalidationListener listener)
Observable が無効になるたびに通知されるInvalidationListener を追加します。 |
void |
addListener(ListChangeListener<? super E> listener)
リスナーをこの監視可能リストに追加します。
|
protected void |
beginChange()
変更ブロックを開始します。
|
protected void |
endChange()
変更ブロックを終了します。
|
protected void |
fireChange(ListChangeListener.Change<? extends E> change)
すべてのリスナーに変更を通知します。
|
protected boolean |
hasListeners()
このリストに登録されているリスナーがある場合はtrueを返します。
|
protected void |
nextAdd(int from, int to)
新しい追加操作を変更に追加します。
|
protected void |
nextPermutation(int from, int to, int[] perm)
新しい順列操作を変更に追加します。
|
protected void |
nextRemove(int idx, E removed)
新しい削除操作を単一のアイテムを削除する変更に追加します。
|
protected void |
nextRemove(int idx, List<? extends E> removed)
新しい削除操作を複数のアイテムを削除する変更に追加します。
|
protected void |
nextReplace(int from, int to, List<? extends E> removed)
新しい置換操作を変更に追加します。
|
protected void |
nextSet(int idx, E old)
新しい設定操作を変更に追加します。
|
protected void |
nextUpdate(int pos)
新しい更新操作を変更に追加します。
|
void |
remove(int from, int to)
基本的にsublist(from, to).clear()へのショートカット。これは共通操作であるため、ObservableListは便利に使用するためにこのメソッドを持ちます。
|
boolean |
removeAll(E... elements)
removaAllメソッドの可変引数を使用する便利なメソッド。
|
void |
removeListener(InvalidationListener listener)
Observable の値が無効になるたびに通知されるリスナーのリストから指定されたリスナーを削除します。 |
void |
removeListener(ListChangeListener<? super E> listener)
この監視可能リストからリスナーの削除を試行します。
|
boolean |
retainAll(E... elements)
retainメソッドの可変引数を使用する便利なメソッド。
|
boolean |
setAll(Collection<? extends E> col)
ObservableListをクリアし、コレクションからすべての要素を追加します。
|
boolean |
setAll(E... elements)
ObservableListをクリアし、可変引数として渡されるすべての要素を追加します。
|
add, add, addAll, clear, equals, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
filtered, sorted, sorted
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
parallelStream, removeIf, stream
protected final void nextUpdate(int pos)
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
pos
- 更新された要素が存在するリスト内の位置。protected final void nextSet(int idx, E old)
nextRemove(idx); nextAdd(idx, idx + 1);
と同等です。
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
idx
- 設定されたアイテムの索引。old
- idx
位置にある古い値。protected final void nextReplace(int from, int to, List<? extends E> removed)
nextRemove(from, removed); nextAdd(from, to);
と同等です。
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
from
- アイテムが置換された索引to
- 新しいアイテムが存在する範囲の最後の索引(これを含まない)removed
- 削除されたアイテムのリストprotected final void nextRemove(int idx, List<? extends E> removed)
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
idx
- アイテムが削除された索引removed
- 削除されたアイテムのリストprotected final void nextRemove(int idx, E removed)
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
idx
- アイテムが削除された索引removed
- 削除されたアイテムprotected final void nextPermutation(int from, int to, int[] perm)
"i"
の順列には、索引"i"
のアイテムが移動された索引が含まれます。
最小順列を指定する必要はありません。常にnextPermutation(0, size(), permutation);
を使用してこのメソッドを呼び出すことが適切です。
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
from
- 順序が変更された範囲の最初(これを含む)をマークします。to
- 順序が変更された範囲の最後(これを含まない)をマークします。perm
- 該当する範囲の順列。from != 0
の場合でも、配列にはリストの索引を含める必要があります。このため、そのような順列には範囲(0, from)
の索引は含めません。protected final void nextAdd(int from, int to)
注意: beginChange()
/endChange()
ブロック内で呼び出す必要があります。
注意: リストの現在の状態を反映する必要があります。
from
- 追加された範囲の最初(これを含む)をマークしますto
- 追加された範囲の最後(これを含まない)をマークしますprotected final void beginChange()
next*
メソッドを呼び出す前に呼び出す必要があります。各beginChange()
には、対応するendChange()
呼出しが必要です。
beginChange()
呼出しは、beginChange()
/endChange()
ブロックにネストできます。
endChange()
protected final void endChange()
ObservableList
の最も外側のブロックの場合、Change
が作成され、すべてのリスナーに通知されます。
ネストされたブロックを終了すると、通知は起動されません。
beginChange()
public final void addListener(InvalidationListener listener)
Observable
Observable
が無効になるたびに通知されるInvalidationListener
を追加します。同じリスナーが複数回追加される場合、複数回通知されます。つまり、一意性を確認するためにチェックが実行されません。
実際の同じInvalidationListener
インスタンスが異なるObservables
に対して安全に登録される場合があるので注意してください。
Observable
は、リスナーの強参照を格納するため、リスナーはガベージ・コレクションされず、メモリー・リークが発生する可能性があります。使用後にremoveListener
を呼び出してリスナーを登録解除するか、WeakInvalidationListener
のインスタンスを使用してこの状況を回避することをお薦めします。
Observable
のaddListener
listener
- 登録するリスナーObservable.removeListener(InvalidationListener)
public final void removeListener(InvalidationListener listener)
Observable
Observable
の値が無効になるたびに通知されるリスナーのリストから指定されたリスナーを削除します。
指定されたリスナーが以前に登録されていない場合(つまり、一度も追加されていなかった場合)、このメソッドの呼出しはno-opです。以前に追加されたことがある場合は削除されます。複数回追加された場合、最初の発生のみ削除されます。
Observable
のremoveListener
listener
- 削除するリスナーObservable.addListener(InvalidationListener)
public final void addListener(ListChangeListener<? super E> listener)
ObservableList
ObservableList<E>
のaddListener
listener
- リストの変更をリスニングするリスナーpublic final void removeListener(ListChangeListener<? super E> listener)
ObservableList
ObservableList<E>
のremoveListener
listener
- 削除するリスナーprotected final void fireChange(ListChangeListener.Change<? extends E> change)
change
- protected final boolean hasListeners()
public boolean addAll(E... elements)
ObservableList
ObservableList<E>
のaddAll
elements
- 追加する要素public boolean setAll(E... elements)
ObservableList
ObservableList<E>
のsetAll
elements
- 設定する要素public boolean setAll(Collection<? extends E> col)
ObservableList
ObservableList<E>
のsetAll
col
- このobservableArrayListに追加される要素を含むコレクションpublic boolean removeAll(E... elements)
ObservableList
ObservableList<E>
のremoveAll
elements
- 削除する要素public boolean retainAll(E... elements)
ObservableList
ObservableList<E>
のretainAll
elements
- 保持する要素public void remove(int from, int to)
ObservableList
remove
、インタフェース: ObservableList<E>
from
- 削除する範囲の開始(含む)to
- 削除する範囲の最後(含まない)Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.