+ public void setList(List<T> aList) {
+ try (LockHolder lh = lockForWriting()) {
+ list = aList;
+ lh.downgrade();
+ forceNotify();
+ }
+ }
+ public void triggerItemChangedNotification(T item) {
+ try (LockHolder lh = lockForReading()) {
+ int index = list.indexOf(item);
+ if (index == -1) {
+ debug("ObList", "??? not sending notifications for item not found in the list");
+ return;
+ }
+ debug("ObList", "Notifying item change observers");
+ triggerItemChangedNotification(index);
+ }
+ }
+ public void triggerItemChangedNotification(int index) {
+ forceNotify(index);
+ }
+ public LockHolder lockForWriting() {
+ ReentrantReadWriteLock.WriteLock wLock = lock.writeLock();
+ wLock.lock();
+
+ ReentrantReadWriteLock.ReadLock rLock = lock.readLock();
+ rLock.lock();
+
+ return new LockHolder(rLock, wLock);
+ }
+ public LockHolder lockForReading() {
+ ReentrantReadWriteLock.ReadLock rLock = lock.readLock();
+ rLock.lock();
+ return new LockHolder(rLock);
+ }
+ public void blockNotifications() {
+ notificationBlocks++;
+ }
+ public void unblockNotifications() {
+ notificationBlocks--;
+ if ((notificationBlocks == 0) && notificationWasBlocked) notifyObservers();
+ }