+ 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) {
+ Log.d("ObList", "??? not sending notifications for item not found in the list");
+ return;
+ }
+ Log.d("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);