diff options
9 files changed, 249 insertions, 128 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java index 710cb4455c..2b343dde74 100644 --- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java +++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java @@ -329,10 +329,7 @@ public final class EMFUtil synchronized (notifier) { EList<Adapter> adapters = notifier.eAdapters(); - if (!adapters.contains(adapter)) - { - adapters.add(adapter); - } + adapters.add(adapter); } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java index c7a803fbc1..2fd08ab44f 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java @@ -108,7 +108,7 @@ import org.eclipse.emf.internal.cdo.view.CDOViewImpl; import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.WrappedException; import org.eclipse.net4j.util.collection.ByteArrayWrapper; -import org.eclipse.net4j.util.collection.FastList; +import org.eclipse.net4j.util.collection.ConcurrentArray; import org.eclipse.net4j.util.collection.Pair; import org.eclipse.net4j.util.event.IEvent; import org.eclipse.net4j.util.event.IListener; @@ -169,7 +169,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa private Object transactionHandlersLock = new Object(); - private FastList<CDOTransactionHandler1> transactionHandlers1 = new FastList<CDOTransactionHandler1>() + private ConcurrentArray<CDOTransactionHandler1> transactionHandlers1 = new ConcurrentArray<CDOTransactionHandler1>() { @Override protected CDOTransactionHandler1[] newArray(int length) @@ -178,7 +178,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa } }; - private FastList<CDOTransactionHandler2> transactionHandlers2 = new FastList<CDOTransactionHandler2>() + private ConcurrentArray<CDOTransactionHandler2> transactionHandlers2 = new ConcurrentArray<CDOTransactionHandler2>() { @Override protected CDOTransactionHandler2[] newArray(int length) @@ -2880,12 +2880,9 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa IEvent event = null; synchronized (CDOTransactionImpl.this) { - if (!conflictResolvers.contains(resolver)) - { - validateResolver(resolver); - conflictResolvers.add(resolver); - event = new ConflictResolversEventImpl(); - } + validateResolver(resolver); + conflictResolvers.add(resolver); + event = new ConflictResolversEventImpl(); } fireEvent(event); diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java index b44379ba2c..a018dfd394 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java @@ -61,7 +61,7 @@ import org.eclipse.net4j.util.ImplementationError; import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.collection.CloseableIterator; -import org.eclipse.net4j.util.collection.FastList; +import org.eclipse.net4j.util.collection.ConcurrentArray; import org.eclipse.net4j.util.collection.Pair; import org.eclipse.net4j.util.event.IListener; import org.eclipse.net4j.util.lifecycle.Lifecycle; @@ -115,7 +115,7 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi private CDOResourceImpl rootResource; - private final FastList<CDOObjectHandler> objectHandlers = new FastList<CDOObjectHandler>() + private final ConcurrentArray<CDOObjectHandler> objectHandlers = new ConcurrentArray<CDOObjectHandler>() { @Override protected CDOObjectHandler[] newArray(int length) @@ -212,7 +212,7 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi { throw new IllegalStateException("RootResourceID is null; is the repository not yet initialized?"); } - + CDOResourceImpl resource = (CDOResourceImpl)getObject(rootResourceID); setRootResource(resource); } diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java index ef16ca1702..b410756898 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java @@ -172,6 +172,9 @@ public abstract class AbstractOMTest extends TestCase @Override public void tearDown() throws Exception { + OMPlatform platform = OMPlatform.INSTANCE; + System.out.println(platform); + enableConsole(); if (!SUPPRESS_OUTPUT) { diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java index 9b7ad42f7c..0f7f24d9f7 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java @@ -11,7 +11,7 @@ */ package org.eclipse.net4j.util.tests; -import org.eclipse.net4j.util.collection.FastList; +import org.eclipse.net4j.util.collection.ConcurrentArray; /** * @author Eike Stepper @@ -251,7 +251,7 @@ public class FastListTest extends AbstractOMTest /** * @author Eike Stepper */ - public static class TestList extends FastList<Integer> + public static class TestList extends ConcurrentArray<Integer> { public int added; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java index 5e57d1a322..103b9ebb53 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java @@ -12,6 +12,7 @@ package org.eclipse.net4j.internal.util.bundle; import org.eclipse.net4j.internal.util.om.LegacyPlatform; import org.eclipse.net4j.internal.util.om.OSGiPlatform; +import org.eclipse.net4j.util.collection.ConcurrentArray; import org.eclipse.net4j.util.io.IORuntimeException; import org.eclipse.net4j.util.io.IOUtil; import org.eclipse.net4j.util.om.OMBundle; @@ -30,9 +31,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.Properties; -import java.util.Queue; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; /** * @author Eike Stepper @@ -51,11 +50,32 @@ public abstract class AbstractPlatform implements OMPlatform private Map<String, AbstractBundle> bundles = new ConcurrentHashMap<String, AbstractBundle>(0); - private Queue<OMLogFilter> logFilters = new ConcurrentLinkedQueue<OMLogFilter>(); + private ConcurrentArray<OMLogFilter> logFilters = new ConcurrentArray.Unique<OMLogFilter>() + { + @Override + protected OMLogFilter[] newArray(int length) + { + return new OMLogFilter[length]; + } + }; - private Queue<OMLogHandler> logHandlers = new ConcurrentLinkedQueue<OMLogHandler>(); + private ConcurrentArray<OMLogHandler> logHandlers = new ConcurrentArray.Unique<OMLogHandler>() + { + @Override + protected OMLogHandler[] newArray(int length) + { + return new OMLogHandler[length]; + } + }; - private Queue<OMTraceHandler> traceHandlers = new ConcurrentLinkedQueue<OMTraceHandler>(); + private ConcurrentArray<OMTraceHandler> traceHandlers = new ConcurrentArray.Unique<OMTraceHandler>() + { + @Override + protected OMTraceHandler[] newArray(int length) + { + return new OMTraceHandler[length]; + } + }; private boolean debugging; @@ -77,10 +97,7 @@ public abstract class AbstractPlatform implements OMPlatform public void addLogFilter(OMLogFilter logFilter) { - if (!logFilters.contains(logFilter)) - { - logFilters.add(logFilter); - } + logFilters.add(logFilter); } public void removeLogFilter(OMLogFilter logFilter) @@ -90,10 +107,7 @@ public abstract class AbstractPlatform implements OMPlatform public void addLogHandler(OMLogHandler logHandler) { - if (!logHandlers.contains(logHandler)) - { - logHandlers.add(logHandler); - } + logHandlers.add(logHandler); } public void removeLogHandler(OMLogHandler logHandler) @@ -103,10 +117,7 @@ public abstract class AbstractPlatform implements OMPlatform public void addTraceHandler(OMTraceHandler traceHandler) { - if (!traceHandlers.contains(traceHandler)) - { - traceHandlers.add(traceHandler); - } + traceHandlers.add(traceHandler); } public void removeTraceHandler(OMTraceHandler traceHandler) @@ -242,7 +253,7 @@ public abstract class AbstractPlatform implements OMPlatform { if (!logFilters.isEmpty()) { - for (OMLogFilter logFilter : logFilters) + for (OMLogFilter logFilter : logFilters.get()) { try { @@ -268,7 +279,7 @@ public abstract class AbstractPlatform implements OMPlatform if (!logHandlers.isEmpty()) { - for (OMLogHandler logHandler : logHandlers) + for (OMLogHandler logHandler : logHandlers.get()) { try { @@ -289,7 +300,7 @@ public abstract class AbstractPlatform implements OMPlatform { if (!traceHandlers.isEmpty()) { - for (OMTraceHandler traceHandler : traceHandlers) + for (OMTraceHandler traceHandler : traceHandlers.get()) { try { diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ConcurrentArray.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ConcurrentArray.java new file mode 100644 index 0000000000..489550ceb1 --- /dev/null +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ConcurrentArray.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.util.collection; + +/** + * @author Eike Stepper + * @since 3.2 + */ +public abstract class ConcurrentArray<E> +{ + protected E[] elements; + + public ConcurrentArray() + { + } + + public boolean isEmpty() + { + return elements == null; + } + + public E[] get() + { + return elements; + } + + public synchronized void add(E element) + { + if (!validate(element)) + { + return; + } + + if (elements == null) + { + E[] array = newArray(1); + array[0] = element; + elements = array; + firstElementAdded(); + } + else + { + int length = elements.length; + E[] array = newArray(length + 1); + System.arraycopy(elements, 0, array, 0, length); + array[length] = element; + elements = array; + } + } + + public synchronized boolean remove(E element) + { + if (elements != null) + { + int length = elements.length; + if (length == 1) + { + if (elements[0] == element) + { + elements = null; + lastElementRemoved(); + return true; + } + } + else + { + for (int i = 0; i < length; i++) + { + E e = elements[i]; + if (e == element) + { + E[] array = newArray(length - 1); + + if (i > 0) + { + System.arraycopy(elements, 0, array, 0, i); + } + + if (i + 1 <= length - 1) + { + System.arraycopy(elements, i + 1, array, i, length - 1 - i); + } + + elements = array; + return true; + } + } + } + } + + return false; + } + + protected boolean validate(E element) + { + return true; + } + + protected void firstElementAdded() + { + } + + protected void lastElementRemoved() + { + } + + protected abstract E[] newArray(int length); + + /** + * @author Eike Stepper + */ + public abstract static class Unique<E> extends ConcurrentArray<E> + { + public Unique() + { + } + + @Override + protected boolean validate(E element) + { + if (elements != null) + { + for (int i = 0; i < elements.length; i++) + { + if (equals(element, elements[i])) + { + violatingUniqueness(element); + return false; + } + } + } + + return true; + } + + protected boolean equals(E e1, E e2) + { + return e1 == e2; + } + + protected void violatingUniqueness(E element) + { + } + } + + /** + * @author Eike Stepper + */ + public abstract static class DuplicateCounter<E> extends ConcurrentArray<E> + { + private int maxDuplicates; + + public DuplicateCounter() + { + } + + public final int getMaxDuplicates() + { + return maxDuplicates; + } + + @Override + protected boolean validate(E element) + { + if (elements != null) + { + int duplicates = 0; + for (int i = 0; i < elements.length; i++) + { + if (equals(element, elements[i])) + { + ++duplicates; + } + } + + if (duplicates > maxDuplicates) + { + maxDuplicates = duplicates; + } + } + + return true; + } + + protected boolean equals(E e1, E e2) + { + return e1 == e2; + } + } +} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/FastList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/FastList.java index 70e2021423..d4cc252669 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/FastList.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/FastList.java @@ -13,94 +13,9 @@ package org.eclipse.net4j.util.collection; /** * @author Eike Stepper * @since 3.0 + * @deprecated As of 3.2 use {@link ConcurrentArray}. */ -public abstract class FastList<E> +@Deprecated +public abstract class FastList<E> extends ConcurrentArray<E> { - protected E[] elements; - - public FastList() - { - } - - public boolean isEmpty() - { - return elements == null; - } - - public E[] get() - { - return elements; - } - - public synchronized void add(E element) - { - if (elements == null) - { - E[] array = newArray(1); - array[0] = element; - elements = array; - firstElementAdded(); - } - else - { - int length = elements.length; - E[] array = newArray(length + 1); - System.arraycopy(elements, 0, array, 0, length); - array[length] = element; - elements = array; - } - } - - public synchronized boolean remove(E element) - { - if (elements != null) - { - int length = elements.length; - if (length == 1) - { - if (elements[0] == element) - { - elements = null; - lastElementRemoved(); - return true; - } - } - else - { - for (int i = 0; i < length; i++) - { - E e = elements[i]; - if (e == element) - { - E[] array = newArray(length - 1); - - if (i > 0) - { - System.arraycopy(elements, 0, array, 0, i); - } - - if (i + 1 <= length - 1) - { - System.arraycopy(elements, i + 1, array, i, length - 1 - i); - } - - elements = array; - return true; - } - } - } - } - - return false; - } - - protected void firstElementAdded() - { - } - - protected void lastElementRemoved() - { - } - - protected abstract E[] newArray(int length); } diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java index aef1d1336f..ea7bedfb4f 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java @@ -12,7 +12,7 @@ package org.eclipse.net4j.util.event; import org.eclipse.net4j.internal.util.bundle.OM; import org.eclipse.net4j.util.CheckUtil; -import org.eclipse.net4j.util.collection.FastList; +import org.eclipse.net4j.util.collection.ConcurrentArray; import java.util.concurrent.ExecutorService; @@ -24,7 +24,7 @@ import java.util.concurrent.ExecutorService; */ public class Notifier implements INotifier { - private FastList<IListener> listeners = new FastList<IListener>() + private ConcurrentArray<IListener> listeners = new ConcurrentArray<IListener>() { @Override protected IListener[] newArray(int length) |