001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.project.internal.impl;
016:
017: import java.util.Collection;
018: import java.util.concurrent.locks.Lock;
019:
020: import net.refractions.udig.ui.UDIGDisplaySafeLock;
021:
022: import org.eclipse.emf.ecore.InternalEObject;
023: import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
024:
025: /**
026: * Synchronizes reads and writes but not within synchronization block during notification. When
027: * iterating make sure to use: synchronized( list ){ do iterations }
028: *
029: * @author Jesse
030: * @since 1.1.0
031: */
032: public class SynchronizedEObjectWithInverseResolvingEList extends
033: EObjectWithInverseResolvingEList {
034:
035: /** long serialVersionUID field */
036: private static final long serialVersionUID = -7051345525714825128L;
037:
038: private transient final Lock lock = new UDIGDisplaySafeLock();
039:
040: public SynchronizedEObjectWithInverseResolvingEList(
041: Class dataClass, InternalEObject owner, int featureID,
042: int inverseFeatureID) {
043: super (dataClass, owner, featureID, inverseFeatureID);
044: }
045:
046: @Override
047: protected Object assign(int index, Object object) {
048: lock.lock();
049: try {
050: return super .assign(index, object);
051: } finally {
052: lock.unlock();
053: }
054: }
055:
056: @Override
057: protected Object doRemove(int index) {
058: lock.lock();
059: try {
060: return super .doRemove(index);
061: } finally {
062: lock.unlock();
063: }
064: }
065:
066: @Override
067: protected void doClear() {
068: lock.lock();
069: try {
070: super .doClear();
071: } finally {
072: lock.unlock();
073: }
074: }
075:
076: @Override
077: public Object get(int index) {
078: lock.lock();
079: try {
080: return super .get(index);
081: } finally {
082: lock.unlock();
083: }
084: }
085:
086: @Override
087: public boolean contains(Object object) {
088: lock.lock();
089: try {
090: return super .contains(object);
091: } finally {
092: lock.unlock();
093: }
094: }
095:
096: @Override
097: public boolean containsAll(Collection collection) {
098: lock.lock();
099: try {
100: return super .containsAll(collection);
101: } finally {
102: lock.unlock();
103: }
104: }
105:
106: @Override
107: public boolean equals(Object object) {
108: lock.lock();
109: try {
110: return super .equals(object);
111: } finally {
112: lock.unlock();
113: }
114: }
115:
116: @Override
117: public int hashCode() {
118: lock.lock();
119: try {
120: return super.hashCode();
121: } finally {
122: lock.unlock();
123: }
124: }
125: }
|