Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ArrayIterator.java144
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/BidiMapper.java160
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ByteArrayWrapper.java152
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CaseInsensitiveStringSet.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Closeable.java48
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CloseableIterator.java44
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ConcurrentArray.java406
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/DynamicArray.java194
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/FastList.java42
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java372
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/History.java434
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryElement.java148
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java66
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java78
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java52
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java46
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IndexedList.java560
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MapEntry.java168
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableArrayList.java168
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableList.java42
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MultiMap.java1550
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java200
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PreferenceHistory.java108
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/RoundRobinBlockingQueue.java736
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Triplet.java158
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/package-info.java2
27 files changed, 3041 insertions, 3041 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java
index 897a487bb0..37a4ffd0ed 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/AbstractIterator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 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
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ArrayIterator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ArrayIterator.java
index 9f8b282702..c7ecb0b8b9 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ArrayIterator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ArrayIterator.java
@@ -1,72 +1,72 @@
-/*
- * 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;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * An object that iterates over the elements of an array
- *
- * @author Eike Stepper
- * @since 3.0
- */
-public class ArrayIterator<T> implements Iterator<T>
-{
- private T[] elements;
-
- private int index;
-
- private int lastElement;
-
- public ArrayIterator(T[] elements)
- {
- this(elements, 0, elements.length - 1);
- }
-
- public ArrayIterator(T[] elements, int firstElement)
- {
- this(elements, firstElement, elements.length - 1);
- }
-
- public ArrayIterator(T[] elements, int firstElement, int lastElement)
- {
- this.elements = elements;
- index = firstElement;
- this.lastElement = lastElement;
- }
-
- public boolean hasNext()
- {
- return elements != null && index <= lastElement;
- }
-
- public T next() throws NoSuchElementException
- {
- if (!hasNext())
- {
- throw new NoSuchElementException();
- }
-
- return elements[index++];
- }
-
- /**
- * Unsupported.
- *
- * @throws UnsupportedOperationException
- * always
- */
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An object that iterates over the elements of an array
+ *
+ * @author Eike Stepper
+ * @since 3.0
+ */
+public class ArrayIterator<T> implements Iterator<T>
+{
+ private T[] elements;
+
+ private int index;
+
+ private int lastElement;
+
+ public ArrayIterator(T[] elements)
+ {
+ this(elements, 0, elements.length - 1);
+ }
+
+ public ArrayIterator(T[] elements, int firstElement)
+ {
+ this(elements, firstElement, elements.length - 1);
+ }
+
+ public ArrayIterator(T[] elements, int firstElement, int lastElement)
+ {
+ this.elements = elements;
+ index = firstElement;
+ this.lastElement = lastElement;
+ }
+
+ public boolean hasNext()
+ {
+ return elements != null && index <= lastElement;
+ }
+
+ public T next() throws NoSuchElementException
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+
+ return elements[index++];
+ }
+
+ /**
+ * Unsupported.
+ *
+ * @throws UnsupportedOperationException
+ * always
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/BidiMapper.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/BidiMapper.java
index 6c5867de5c..8d04d15bff 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/BidiMapper.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/BidiMapper.java
@@ -1,80 +1,80 @@
-/*
- * 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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 2.0
- * @author Eike Stepper
- */
-public class BidiMapper<T1, T2>
-{
- private Map<T1, T2> map1 = new HashMap<T1, T2>();
-
- private Map<T2, T1> map2 = new HashMap<T2, T1>();
-
- public BidiMapper()
- {
- }
-
- public synchronized void map(T1 v1, T2 v2)
- {
- map1.put(v1, v2);
- map2.put(v2, v1);
- }
-
- public synchronized int size()
- {
- return map1.size();
- }
-
- public synchronized void clear()
- {
- map1.clear();
- map2.clear();
- }
-
- public synchronized T2 lookup1(T1 v1)
- {
- return map1.get(v1);
- }
-
- public synchronized T1 lookup2(T2 v2)
- {
- return map2.get(v2);
- }
-
- public synchronized boolean remove1(T1 v1)
- {
- T2 v2 = map1.remove(v1);
- if (v2 != null)
- {
- map2.remove(v2);
- return true;
- }
-
- return false;
- }
-
- public synchronized boolean remove2(T2 v2)
- {
- T1 v1 = map2.remove(v2);
- if (v1 != null)
- {
- map1.remove(v1);
- return true;
- }
-
- return false;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @since 2.0
+ * @author Eike Stepper
+ */
+public class BidiMapper<T1, T2>
+{
+ private Map<T1, T2> map1 = new HashMap<T1, T2>();
+
+ private Map<T2, T1> map2 = new HashMap<T2, T1>();
+
+ public BidiMapper()
+ {
+ }
+
+ public synchronized void map(T1 v1, T2 v2)
+ {
+ map1.put(v1, v2);
+ map2.put(v2, v1);
+ }
+
+ public synchronized int size()
+ {
+ return map1.size();
+ }
+
+ public synchronized void clear()
+ {
+ map1.clear();
+ map2.clear();
+ }
+
+ public synchronized T2 lookup1(T1 v1)
+ {
+ return map1.get(v1);
+ }
+
+ public synchronized T1 lookup2(T2 v2)
+ {
+ return map2.get(v2);
+ }
+
+ public synchronized boolean remove1(T1 v1)
+ {
+ T2 v2 = map1.remove(v1);
+ if (v2 != null)
+ {
+ map2.remove(v2);
+ return true;
+ }
+
+ return false;
+ }
+
+ public synchronized boolean remove2(T2 v2)
+ {
+ T1 v1 = map2.remove(v2);
+ if (v1 != null)
+ {
+ map1.remove(v1);
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ByteArrayWrapper.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ByteArrayWrapper.java
index 5b0e66f672..cfb6629f7f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ByteArrayWrapper.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/ByteArrayWrapper.java
@@ -1,76 +1,76 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.CheckUtil;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @since 3.2
- */
-public final class ByteArrayWrapper
-{
- private final byte[] data;
-
- public ByteArrayWrapper(byte[] data)
- {
- CheckUtil.checkArg(data, "data");
- this.data = data;
- }
-
- public byte[] getData()
- {
- return data;
- }
-
- @Override
- public boolean equals(Object other)
- {
- if (other instanceof ByteArrayWrapper)
- {
- return Arrays.equals(data, ((ByteArrayWrapper)other).data);
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return Arrays.hashCode(data);
- }
-
- @Override
- public String toString()
- {
- return data.toString();
- }
-
- public static Set<byte[]> toByteArray(Set<ByteArrayWrapper> wrappers)
- {
- if (wrappers == null)
- {
- return null;
- }
-
- Set<byte[]> result = new HashSet<byte[]>();
- for (ByteArrayWrapper wrapper : wrappers)
- {
- result.add(wrapper.getData());
- }
-
- return result;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.CheckUtil;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ * @since 3.2
+ */
+public final class ByteArrayWrapper
+{
+ private final byte[] data;
+
+ public ByteArrayWrapper(byte[] data)
+ {
+ CheckUtil.checkArg(data, "data");
+ this.data = data;
+ }
+
+ public byte[] getData()
+ {
+ return data;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof ByteArrayWrapper)
+ {
+ return Arrays.equals(data, ((ByteArrayWrapper)other).data);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Arrays.hashCode(data);
+ }
+
+ @Override
+ public String toString()
+ {
+ return data.toString();
+ }
+
+ public static Set<byte[]> toByteArray(Set<ByteArrayWrapper> wrappers)
+ {
+ if (wrappers == null)
+ {
+ return null;
+ }
+
+ Set<byte[]> result = new HashSet<byte[]>();
+ for (ByteArrayWrapper wrapper : wrappers)
+ {
+ result.add(wrapper.getData());
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CaseInsensitiveStringSet.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CaseInsensitiveStringSet.java
index 453e2e451f..2aafff27bd 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CaseInsensitiveStringSet.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CaseInsensitiveStringSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 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
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Closeable.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Closeable.java
index f6708a338c..1933ca6609 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Closeable.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Closeable.java
@@ -1,24 +1,24 @@
-/*
- * 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
- */
-public interface Closeable
-{
- public void close();
-
- /**
- * @since 2.0
- */
- public boolean isClosed();
-}
+/*
+ * Copyright (c) 2004 - 2012 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
+ */
+public interface Closeable
+{
+ public void close();
+
+ /**
+ * @since 2.0
+ */
+ public boolean isClosed();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CloseableIterator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CloseableIterator.java
index 917dd11cc6..6af4c708cc 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CloseableIterator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/CloseableIterator.java
@@ -1,22 +1,22 @@
-/*
- * 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;
-
-import java.util.Iterator;
-
-/**
- * A closeable iterator.
- *
- * @author Eike Stepper
- */
-public interface CloseableIterator<E> extends Iterator<E>, Closeable
-{
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.Iterator;
+
+/**
+ * A closeable iterator.
+ *
+ * @author Eike Stepper
+ */
+public interface CloseableIterator<E> extends Iterator<E>, Closeable
+{
+}
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
index 6bd88eba81..4dc217c537 100644
--- 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
@@ -1,203 +1,203 @@
-/*
- * 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;
-
- private final E[] EMPTY = newArray(0);
-
- public ConcurrentArray()
- {
- }
-
- public boolean isEmpty()
- {
- return elements == null;
- }
-
- /**
- * Returns the elements, never <code>null</code>.
- */
- public E[] get()
- {
- return elements == null ? EMPTY : 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;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+ private final E[] EMPTY = newArray(0);
+
+ public ConcurrentArray()
+ {
+ }
+
+ public boolean isEmpty()
+ {
+ return elements == null;
+ }
+
+ /**
+ * Returns the elements, never <code>null</code>.
+ */
+ public E[] get()
+ {
+ return elements == null ? EMPTY : 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/DynamicArray.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/DynamicArray.java
index 54ef6c436b..c6b345d73d 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/DynamicArray.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/DynamicArray.java
@@ -1,97 +1,97 @@
-/*
- * 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 2.0
- */
-public class DynamicArray<E>
-{
- private Object[] elements = {};
-
- public DynamicArray()
- {
- }
-
- public int add(E element)
- {
- int length = elements.length;
- for (int i = 0; i < length; i++)
- {
- if (elements[i] == null)
- {
- elements[i] = element;
- return i;
- }
- }
-
- grow(length);
- elements[length] = element;
- return length;
- }
-
- @SuppressWarnings("unchecked")
- public E add(int index, E element)
- {
- grow(index);
- Object old = elements[index];
- elements[index] = element;
- return (E)old;
- }
-
- @SuppressWarnings("unchecked")
- public E remove(int index)
- {
- Object old = elements[index];
- if (old != null)
- {
- elements[index] = null;
- shrink();
- }
-
- return (E)old;
- }
-
- @SuppressWarnings("unchecked")
- public E get(int index)
- {
- return (E)elements[index];
- }
-
- private void grow(int index)
- {
- if (index >= elements.length)
- {
- Object[] newChannels = new Object[index + 1];
- System.arraycopy(elements, 0, newChannels, 0, elements.length);
- elements = newChannels;
- }
- }
-
- private void shrink()
- {
- boolean shrink = false;
- int lastIndex = elements.length - 1;
- while (lastIndex > 0 && (shrink = elements[lastIndex] == null))
- {
- --lastIndex;
- }
-
- if (shrink)
- {
- int newLength = lastIndex + 1;
- Object[] newChannels = new Object[newLength];
- System.arraycopy(elements, 0, newChannels, 0, newLength);
- elements = newChannels;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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 2.0
+ */
+public class DynamicArray<E>
+{
+ private Object[] elements = {};
+
+ public DynamicArray()
+ {
+ }
+
+ public int add(E element)
+ {
+ int length = elements.length;
+ for (int i = 0; i < length; i++)
+ {
+ if (elements[i] == null)
+ {
+ elements[i] = element;
+ return i;
+ }
+ }
+
+ grow(length);
+ elements[length] = element;
+ return length;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E add(int index, E element)
+ {
+ grow(index);
+ Object old = elements[index];
+ elements[index] = element;
+ return (E)old;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E remove(int index)
+ {
+ Object old = elements[index];
+ if (old != null)
+ {
+ elements[index] = null;
+ shrink();
+ }
+
+ return (E)old;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E get(int index)
+ {
+ return (E)elements[index];
+ }
+
+ private void grow(int index)
+ {
+ if (index >= elements.length)
+ {
+ Object[] newChannels = new Object[index + 1];
+ System.arraycopy(elements, 0, newChannels, 0, elements.length);
+ elements = newChannels;
+ }
+ }
+
+ private void shrink()
+ {
+ boolean shrink = false;
+ int lastIndex = elements.length - 1;
+ while (lastIndex > 0 && (shrink = elements[lastIndex] == null))
+ {
+ --lastIndex;
+ }
+
+ if (shrink)
+ {
+ int newLength = lastIndex + 1;
+ Object[] newChannels = new Object[newLength];
+ System.arraycopy(elements, 0, newChannels, 0, newLength);
+ elements = newChannels;
+ }
+ }
+}
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 d4cc252669..44faf57b38 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
@@ -1,21 +1,21 @@
-/*
- * 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.0
- * @deprecated As of 3.2 use {@link ConcurrentArray}.
- */
-@Deprecated
-public abstract class FastList<E> extends ConcurrentArray<E>
-{
-}
+/*
+ * Copyright (c) 2004 - 2012 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.0
+ * @deprecated As of 3.2 use {@link ConcurrentArray}.
+ */
+@Deprecated
+public abstract class FastList<E> extends ConcurrentArray<E>
+{
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java
index dd22a2a963..8afd492dd4 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java
@@ -1,186 +1,186 @@
-/*
- * 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;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public final class HashBag<T> implements Set<T>
-{
- private Map<T, HashBag.Counter> map;
-
- public HashBag()
- {
- map = new HashMap<T, Counter>();
- }
-
- public HashBag(int initialCapacity, float loadFactor)
- {
- map = new HashMap<T, Counter>(initialCapacity, loadFactor);
- }
-
- public HashBag(int initialCapacity)
- {
- map = new HashMap<T, Counter>(initialCapacity);
- }
-
- public HashBag(Map<? extends T, ? extends HashBag.Counter> m)
- {
- map = new HashMap<T, Counter>(m);
- }
-
- /**
- * @since 3.0
- */
- public int getCounterFor(T o)
- {
- Counter counter = map.get(o);
- if (counter == null)
- {
- return 0;
- }
-
- return counter.getValue();
- }
-
- public boolean add(T o)
- {
- HashBag.Counter counter = map.get(o);
- if (counter == null)
- {
- counter = new Counter();
- map.put(o, counter);
- return true;
- }
-
- counter.incValue();
- return false;
- }
-
- public boolean addAll(Collection<? extends T> c)
- {
- for (T t : c)
- {
- add(t);
- }
-
- return true;
- }
-
- public void clear()
- {
- map.clear();
- }
-
- public boolean contains(Object o)
- {
- return map.containsKey(o);
- }
-
- public boolean containsAll(Collection<?> c)
- {
- return map.keySet().containsAll(c);
- }
-
- public boolean isEmpty()
- {
- return map.isEmpty();
- }
-
- public Iterator<T> iterator()
- {
- return map.keySet().iterator();
- }
-
- public boolean remove(Object o)
- {
- HashBag.Counter counter = map.get(o);
- if (counter == null)
- {
- return false;
- }
-
- if (counter.decValue() == 0)
- {
- map.remove(o);
- }
-
- return true;
- }
-
- public boolean removeAll(Collection<?> c)
- {
- boolean changed = false;
- for (Object object : c)
- {
- if (remove(object))
- {
- changed = true;
- }
- }
-
- return changed;
- }
-
- public boolean retainAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public int size()
- {
- return map.size();
- }
-
- public Object[] toArray()
- {
- return map.keySet().toArray();
- }
-
- @SuppressWarnings("hiding")
- public <T> T[] toArray(T[] a)
- {
- return map.keySet().toArray(a);
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class Counter
- {
- private int value = 1;
-
- public Counter()
- {
- }
-
- public int getValue()
- {
- return value;
- }
-
- public int incValue()
- {
- return ++value;
- }
-
- public int decValue()
- {
- return --value;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public final class HashBag<T> implements Set<T>
+{
+ private Map<T, HashBag.Counter> map;
+
+ public HashBag()
+ {
+ map = new HashMap<T, Counter>();
+ }
+
+ public HashBag(int initialCapacity, float loadFactor)
+ {
+ map = new HashMap<T, Counter>(initialCapacity, loadFactor);
+ }
+
+ public HashBag(int initialCapacity)
+ {
+ map = new HashMap<T, Counter>(initialCapacity);
+ }
+
+ public HashBag(Map<? extends T, ? extends HashBag.Counter> m)
+ {
+ map = new HashMap<T, Counter>(m);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public int getCounterFor(T o)
+ {
+ Counter counter = map.get(o);
+ if (counter == null)
+ {
+ return 0;
+ }
+
+ return counter.getValue();
+ }
+
+ public boolean add(T o)
+ {
+ HashBag.Counter counter = map.get(o);
+ if (counter == null)
+ {
+ counter = new Counter();
+ map.put(o, counter);
+ return true;
+ }
+
+ counter.incValue();
+ return false;
+ }
+
+ public boolean addAll(Collection<? extends T> c)
+ {
+ for (T t : c)
+ {
+ add(t);
+ }
+
+ return true;
+ }
+
+ public void clear()
+ {
+ map.clear();
+ }
+
+ public boolean contains(Object o)
+ {
+ return map.containsKey(o);
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ return map.keySet().containsAll(c);
+ }
+
+ public boolean isEmpty()
+ {
+ return map.isEmpty();
+ }
+
+ public Iterator<T> iterator()
+ {
+ return map.keySet().iterator();
+ }
+
+ public boolean remove(Object o)
+ {
+ HashBag.Counter counter = map.get(o);
+ if (counter == null)
+ {
+ return false;
+ }
+
+ if (counter.decValue() == 0)
+ {
+ map.remove(o);
+ }
+
+ return true;
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ boolean changed = false;
+ for (Object object : c)
+ {
+ if (remove(object))
+ {
+ changed = true;
+ }
+ }
+
+ return changed;
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ return map.size();
+ }
+
+ public Object[] toArray()
+ {
+ return map.keySet().toArray();
+ }
+
+ @SuppressWarnings("hiding")
+ public <T> T[] toArray(T[] a)
+ {
+ return map.keySet().toArray(a);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class Counter
+ {
+ private int value = 1;
+
+ public Counter()
+ {
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public int incValue()
+ {
+ return ++value;
+ }
+
+ public int decValue()
+ {
+ return --value;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/History.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/History.java
index 553422a884..67fc3f5ce0 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/History.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/History.java
@@ -1,217 +1,217 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.event.Notifier;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public class History<T> extends Notifier implements IHistory<T>
-{
- protected List<IHistoryElement<T>> elements = new ArrayList<IHistoryElement<T>>(0);
-
- private boolean loaded;
-
- public History()
- {
- }
-
- public List<IHistoryElement<T>> getElements()
- {
- lazyLoad();
- return elements;
- }
-
- public void setElements(List<IHistoryElement<T>> newElements)
- {
- if (newElements == null)
- {
- newElements = new ArrayList<IHistoryElement<T>>(0);
- }
-
- if (!elements.equals(newElements))
- {
- elements = newElements;
- changed();
- }
- }
-
- public boolean isEmpty()
- {
- lazyLoad();
- return elements.isEmpty();
- }
-
- public int size()
- {
- lazyLoad();
- return elements.size();
- }
-
- public int indexOf(T data)
- {
- lazyLoad();
- for (int i = 0; i < elements.size(); i++)
- {
- if (elements.get(i).getData().equals(data))
- {
- return i;
- }
- }
-
- return -1;
- }
-
- public IHistoryElement<T> get(int index)
- {
- lazyLoad();
- return elements.get(index);
- }
-
- public boolean add(T data)
- {
- lazyLoad();
- int index = indexOf(data);
- IHistoryElement<T> element = index != -1 ? elements.remove(index) : createElement(data);
- elements.add(0, element);
-
- boolean changed = index != 0;
- if (changed)
- {
- changed();
- }
-
- return changed;
- }
-
- public IHistoryElement<T> remove(int index)
- {
- lazyLoad();
- IHistoryElement<T> element = elements.remove(index);
- if (element != null)
- {
- changed();
- }
-
- return element;
- }
-
- public boolean clear()
- {
- if (elements.isEmpty())
- {
- return false;
- }
-
- elements.clear();
- changed();
- return true;
- }
-
- public T getMostRecent()
- {
- lazyLoad();
- if (isEmpty())
- {
- return null;
- }
-
- return elements.get(0).getData();
- }
-
- @SuppressWarnings("unchecked")
- public <D> D[] getData(D[] a)
- {
- lazyLoad();
- int size = elements.size();
- if (a.length < size)
- {
- a = (D[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);
- }
-
- for (int i = 0; i < size; i++)
- {
- a[i] = (D)elements.get(i).getData();
- }
-
- if (a.length > size)
- {
- a[size] = null;
- }
-
- return a;
- }
-
- @SuppressWarnings("unchecked")
- public IHistoryElement<T>[] toArray()
- {
- lazyLoad();
- return elements.toArray(new IHistoryElement[elements.size()]);
- }
-
- public Iterator<IHistoryElement<T>> iterator()
- {
- lazyLoad();
- return elements.iterator();
- }
-
- @SuppressWarnings("unchecked")
- protected IHistoryElement<T> createElement(T data)
- {
- @SuppressWarnings("rawtypes")
- HistoryElement result = new HistoryElement(this, data);
- return result;
- }
-
- protected void load()
- {
- }
-
- protected void save()
- {
- }
-
- protected final void changed()
- {
- save();
- fireChangedEvent();
- }
-
- private void lazyLoad()
- {
- if (!loaded)
- {
- loaded = true;
- load();
- }
- }
-
- private void fireChangedEvent()
- {
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new IHistoryChangeEvent()
- {
- public IHistory<?> getSource()
- {
- return History.this;
- }
- }, listeners);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.event.Notifier;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class History<T> extends Notifier implements IHistory<T>
+{
+ protected List<IHistoryElement<T>> elements = new ArrayList<IHistoryElement<T>>(0);
+
+ private boolean loaded;
+
+ public History()
+ {
+ }
+
+ public List<IHistoryElement<T>> getElements()
+ {
+ lazyLoad();
+ return elements;
+ }
+
+ public void setElements(List<IHistoryElement<T>> newElements)
+ {
+ if (newElements == null)
+ {
+ newElements = new ArrayList<IHistoryElement<T>>(0);
+ }
+
+ if (!elements.equals(newElements))
+ {
+ elements = newElements;
+ changed();
+ }
+ }
+
+ public boolean isEmpty()
+ {
+ lazyLoad();
+ return elements.isEmpty();
+ }
+
+ public int size()
+ {
+ lazyLoad();
+ return elements.size();
+ }
+
+ public int indexOf(T data)
+ {
+ lazyLoad();
+ for (int i = 0; i < elements.size(); i++)
+ {
+ if (elements.get(i).getData().equals(data))
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ public IHistoryElement<T> get(int index)
+ {
+ lazyLoad();
+ return elements.get(index);
+ }
+
+ public boolean add(T data)
+ {
+ lazyLoad();
+ int index = indexOf(data);
+ IHistoryElement<T> element = index != -1 ? elements.remove(index) : createElement(data);
+ elements.add(0, element);
+
+ boolean changed = index != 0;
+ if (changed)
+ {
+ changed();
+ }
+
+ return changed;
+ }
+
+ public IHistoryElement<T> remove(int index)
+ {
+ lazyLoad();
+ IHistoryElement<T> element = elements.remove(index);
+ if (element != null)
+ {
+ changed();
+ }
+
+ return element;
+ }
+
+ public boolean clear()
+ {
+ if (elements.isEmpty())
+ {
+ return false;
+ }
+
+ elements.clear();
+ changed();
+ return true;
+ }
+
+ public T getMostRecent()
+ {
+ lazyLoad();
+ if (isEmpty())
+ {
+ return null;
+ }
+
+ return elements.get(0).getData();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <D> D[] getData(D[] a)
+ {
+ lazyLoad();
+ int size = elements.size();
+ if (a.length < size)
+ {
+ a = (D[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ a[i] = (D)elements.get(i).getData();
+ }
+
+ if (a.length > size)
+ {
+ a[size] = null;
+ }
+
+ return a;
+ }
+
+ @SuppressWarnings("unchecked")
+ public IHistoryElement<T>[] toArray()
+ {
+ lazyLoad();
+ return elements.toArray(new IHistoryElement[elements.size()]);
+ }
+
+ public Iterator<IHistoryElement<T>> iterator()
+ {
+ lazyLoad();
+ return elements.iterator();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected IHistoryElement<T> createElement(T data)
+ {
+ @SuppressWarnings("rawtypes")
+ HistoryElement result = new HistoryElement(this, data);
+ return result;
+ }
+
+ protected void load()
+ {
+ }
+
+ protected void save()
+ {
+ }
+
+ protected final void changed()
+ {
+ save();
+ fireChangedEvent();
+ }
+
+ private void lazyLoad()
+ {
+ if (!loaded)
+ {
+ loaded = true;
+ load();
+ }
+ }
+
+ private void fireChangedEvent()
+ {
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new IHistoryChangeEvent()
+ {
+ public IHistory<?> getSource()
+ {
+ return History.this;
+ }
+ }, listeners);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryElement.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryElement.java
index 821191ca86..56b6713425 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryElement.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryElement.java
@@ -1,74 +1,74 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-/**
- * @author Eike Stepper
- */
-public class HistoryElement<T> implements IHistoryElement<T>
-{
- private IHistory<IHistoryElement<T>> history;
-
- private T data;
-
- public HistoryElement(IHistory<IHistoryElement<T>> history, T data)
- {
- this.history = history;
- this.data = data;
- }
-
- public IHistory<IHistoryElement<T>> getHistory()
- {
- return history;
- }
-
- public T getData()
- {
- return data;
- }
-
- public String getText()
- {
- return data.toString();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof IHistoryElement<?>)
- {
- @SuppressWarnings("unchecked")
- IHistoryElement<T> that = (IHistoryElement<T>)obj;
- return ObjectUtil.equals(history, that.getHistory()) && ObjectUtil.equals(data, that.getData());
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return history.hashCode() ^ data.hashCode();
- }
-
- @Override
- public String toString()
- {
- return getText();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class HistoryElement<T> implements IHistoryElement<T>
+{
+ private IHistory<IHistoryElement<T>> history;
+
+ private T data;
+
+ public HistoryElement(IHistory<IHistoryElement<T>> history, T data)
+ {
+ this.history = history;
+ this.data = data;
+ }
+
+ public IHistory<IHistoryElement<T>> getHistory()
+ {
+ return history;
+ }
+
+ public T getData()
+ {
+ return data;
+ }
+
+ public String getText()
+ {
+ return data.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof IHistoryElement<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IHistoryElement<T> that = (IHistoryElement<T>)obj;
+ return ObjectUtil.equals(history, that.getHistory()) && ObjectUtil.equals(data, that.getData());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return history.hashCode() ^ data.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return getText();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java
index f51f502b31..cd17e499a7 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HistoryUtil.java
@@ -1,33 +1,33 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.om.pref.OMPreference;
-
-/**
- * @author Eike Stepper
- */
-public final class HistoryUtil
-{
- private HistoryUtil()
- {
- }
-
- public static IHistory<String> createHistory()
- {
- return new History<String>();
- }
-
- public static IHistory<String> createPreferenceHistory(OMPreference<String[]> preference)
- {
- return new PreferenceHistory(preference);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+/**
+ * @author Eike Stepper
+ */
+public final class HistoryUtil
+{
+ private HistoryUtil()
+ {
+ }
+
+ public static IHistory<String> createHistory()
+ {
+ return new History<String>();
+ }
+
+ public static IHistory<String> createPreferenceHistory(OMPreference<String[]> preference)
+ {
+ return new PreferenceHistory(preference);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java
index 9236ecea54..b240ab4b7e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistory.java
@@ -1,39 +1,39 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.event.INotifier;
-
-/**
- * @author Eike Stepper
- */
-public interface IHistory<T> extends INotifier, Iterable<IHistoryElement<T>>
-{
- public boolean isEmpty();
-
- public int size();
-
- public boolean clear();
-
- public int indexOf(T data);
-
- public boolean add(T data);
-
- public IHistoryElement<T> remove(int index);
-
- public IHistoryElement<T> get(int index);
-
- public T getMostRecent();
-
- public <D> D[] getData(D[] a);
-
- public IHistoryElement<T>[] toArray();
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.event.INotifier;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IHistory<T> extends INotifier, Iterable<IHistoryElement<T>>
+{
+ public boolean isEmpty();
+
+ public int size();
+
+ public boolean clear();
+
+ public int indexOf(T data);
+
+ public boolean add(T data);
+
+ public IHistoryElement<T> remove(int index);
+
+ public IHistoryElement<T> get(int index);
+
+ public T getMostRecent();
+
+ public <D> D[] getData(D[] a);
+
+ public IHistoryElement<T>[] toArray();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java
index 9f1586313b..d644429c88 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryChangeEvent.java
@@ -1,26 +1,26 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.event.IEvent;
-
-/**
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IHistoryChangeEvent extends IEvent
-{
- /**
- * @since 3.0
- */
- public IHistory<?> getSource();
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.event.IEvent;
+
+/**
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IHistoryChangeEvent extends IEvent
+{
+ /**
+ * @since 3.0
+ */
+ public IHistory<?> getSource();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java
index 11e9d9bfc1..3481f573bb 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IHistoryElement.java
@@ -1,23 +1,23 @@
-/*
- * 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
- */
-public interface IHistoryElement<T>
-{
- public IHistory<IHistoryElement<T>> getHistory();
-
- public T getData();
-
- public String getText();
-}
+/*
+ * Copyright (c) 2004 - 2012 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
+ */
+public interface IHistoryElement<T>
+{
+ public IHistory<IHistoryElement<T>> getHistory();
+
+ public T getData();
+
+ public String getText();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IndexedList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IndexedList.java
index c822b54103..791a66ffae 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IndexedList.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/IndexedList.java
@@ -1,280 +1,280 @@
-/*
- * 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;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.NoSuchElementException;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- */
-public abstract class IndexedList<E> implements List<E>
-{
- public IndexedList()
- {
- }
-
- public abstract E get(int index);
-
- public abstract int size();
-
- public boolean isEmpty()
- {
- return size() == 0;
- }
-
- public boolean contains(Object o)
- {
- int size = size();
- for (int i = 0; i < size; i++)
- {
- if (get(i).equals(o))
- {
- return true;
- }
- }
-
- return false;
- }
-
- public boolean containsAll(Collection<?> c)
- {
- for (Object object : c)
- {
- if (!contains(object))
- {
- return false;
- }
- }
-
- return true;
- }
-
- public int indexOf(Object o)
- {
- return 0;
- }
-
- public int lastIndexOf(Object o)
- {
- return 0;
- }
-
- public Iterator<E> iterator()
- {
- return new IndexedIterator();
- }
-
- public ListIterator<E> listIterator()
- {
- return new IndexedListIterator(0);
- }
-
- public ListIterator<E> listIterator(int index)
- {
- if (index < 0 || index > size())
- {
- throw new IndexOutOfBoundsException("Index: " + index);
- }
-
- return new IndexedListIterator(index);
- }
-
- public List<E> subList(int fromIndex, int toIndex)
- {
- return null;
- }
-
- public Object[] toArray()
- {
- throw new UnsupportedOperationException();
- }
-
- public <T> T[] toArray(T[] a)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean add(E o)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean remove(Object o)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection<? extends E> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(int index, Collection<? extends E> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean removeAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean retainAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- public E set(int index, E element)
- {
- throw new UnsupportedOperationException();
- }
-
- public void add(int index, E element)
- {
- throw new UnsupportedOperationException();
- }
-
- public E remove(int index)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String toString()
- {
- StringBuilder builder = new StringBuilder();
- builder.append("{"); //$NON-NLS-1$
- for (int i = 0; i < size(); i++)
- {
- if (i != 0)
- {
- builder.append(", "); //$NON-NLS-1$
- }
-
- builder.append(get(i).toString());
- }
-
- builder.append("}"); //$NON-NLS-1$
- return builder.toString();
- }
-
- /**
- * @author Eike Stepper
- */
- private class IndexedIterator implements Iterator<E>
- {
- int pos = 0;
-
- public boolean hasNext()
- {
- return pos != size();
- }
-
- public E next()
- {
- try
- {
- return get(pos++);
- }
- catch (IndexOutOfBoundsException ex)
- {
- throw new NoSuchElementException();
- }
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private class IndexedListIterator extends IndexedIterator implements ListIterator<E>
- {
- IndexedListIterator(int index)
- {
- pos = index;
- }
-
- public boolean hasPrevious()
- {
- return pos != 0;
- }
-
- public E previous()
- {
- try
- {
- return get(--pos);
- }
- catch (IndexOutOfBoundsException ex)
- {
- throw new NoSuchElementException();
- }
- }
-
- public int nextIndex()
- {
- return pos;
- }
-
- public int previousIndex()
- {
- return pos - 1;
- }
-
- public void set(E o)
- {
- throw new UnsupportedOperationException();
- }
-
- public void add(E o)
- {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static abstract class ArrayBacked<E> extends IndexedList<E>
- {
- public ArrayBacked()
- {
- }
-
- protected abstract E[] getArray();
-
- @Override
- public E get(int i)
- {
- return getArray()[i];
- }
-
- @Override
- public int size()
- {
- return getArray().length;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+/**
+ * @author Eike Stepper
+ * @since 3.0
+ */
+public abstract class IndexedList<E> implements List<E>
+{
+ public IndexedList()
+ {
+ }
+
+ public abstract E get(int index);
+
+ public abstract int size();
+
+ public boolean isEmpty()
+ {
+ return size() == 0;
+ }
+
+ public boolean contains(Object o)
+ {
+ int size = size();
+ for (int i = 0; i < size; i++)
+ {
+ if (get(i).equals(o))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ for (Object object : c)
+ {
+ if (!contains(object))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public int indexOf(Object o)
+ {
+ return 0;
+ }
+
+ public int lastIndexOf(Object o)
+ {
+ return 0;
+ }
+
+ public Iterator<E> iterator()
+ {
+ return new IndexedIterator();
+ }
+
+ public ListIterator<E> listIterator()
+ {
+ return new IndexedListIterator(0);
+ }
+
+ public ListIterator<E> listIterator(int index)
+ {
+ if (index < 0 || index > size())
+ {
+ throw new IndexOutOfBoundsException("Index: " + index);
+ }
+
+ return new IndexedListIterator(index);
+ }
+
+ public List<E> subList(int fromIndex, int toIndex)
+ {
+ return null;
+ }
+
+ public Object[] toArray()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T[] toArray(T[] a)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(int index, Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public E set(int index, E element)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(int index, E element)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public E remove(int index)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("{"); //$NON-NLS-1$
+ for (int i = 0; i < size(); i++)
+ {
+ if (i != 0)
+ {
+ builder.append(", "); //$NON-NLS-1$
+ }
+
+ builder.append(get(i).toString());
+ }
+
+ builder.append("}"); //$NON-NLS-1$
+ return builder.toString();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private class IndexedIterator implements Iterator<E>
+ {
+ int pos = 0;
+
+ public boolean hasNext()
+ {
+ return pos != size();
+ }
+
+ public E next()
+ {
+ try
+ {
+ return get(pos++);
+ }
+ catch (IndexOutOfBoundsException ex)
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private class IndexedListIterator extends IndexedIterator implements ListIterator<E>
+ {
+ IndexedListIterator(int index)
+ {
+ pos = index;
+ }
+
+ public boolean hasPrevious()
+ {
+ return pos != 0;
+ }
+
+ public E previous()
+ {
+ try
+ {
+ return get(--pos);
+ }
+ catch (IndexOutOfBoundsException ex)
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public int nextIndex()
+ {
+ return pos;
+ }
+
+ public int previousIndex()
+ {
+ return pos - 1;
+ }
+
+ public void set(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class ArrayBacked<E> extends IndexedList<E>
+ {
+ public ArrayBacked()
+ {
+ }
+
+ protected abstract E[] getArray();
+
+ @Override
+ public E get(int i)
+ {
+ return getArray()[i];
+ }
+
+ @Override
+ public int size()
+ {
+ return getArray().length;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MapEntry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MapEntry.java
index 8600cd05cb..95326270ba 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MapEntry.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MapEntry.java
@@ -1,84 +1,84 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-import java.text.MessageFormat;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class MapEntry<K, V> implements Map.Entry<K, V>
-{
- private K key;
-
- private V value;
-
- public MapEntry(K key, V value)
- {
- this.key = key;
- this.value = value;
- }
-
- public MapEntry(Map.Entry<K, V> entry)
- {
- key = entry.getKey();
- value = entry.getValue();
- }
-
- public K getKey()
- {
- return key;
- }
-
- public V getValue()
- {
- return value;
- }
-
- public V setValue(V value)
- {
- V oldValue = this.value;
- this.value = value;
- return oldValue;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof Map.Entry<?, ?>)
- {
- Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
- return ObjectUtil.equals(key, entry.getKey()) && ObjectUtil.equals(value, entry.getValue());
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return ObjectUtil.hashCode(key) ^ ObjectUtil.hashCode(value);
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("{0}={1}", key, value); //$NON-NLS-1$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+import java.text.MessageFormat;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class MapEntry<K, V> implements Map.Entry<K, V>
+{
+ private K key;
+
+ private V value;
+
+ public MapEntry(K key, V value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ public MapEntry(Map.Entry<K, V> entry)
+ {
+ key = entry.getKey();
+ value = entry.getValue();
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ public V getValue()
+ {
+ return value;
+ }
+
+ public V setValue(V value)
+ {
+ V oldValue = this.value;
+ this.value = value;
+ return oldValue;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof Map.Entry<?, ?>)
+ {
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
+ return ObjectUtil.equals(key, entry.getKey()) && ObjectUtil.equals(value, entry.getValue());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(key) ^ ObjectUtil.hashCode(value);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}={1}", key, value); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableArrayList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableArrayList.java
index b723d3a4f2..94bb0f0648 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableArrayList.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableArrayList.java
@@ -1,84 +1,84 @@
-/*
- * 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;
-
-import java.util.ArrayList;
-
-/**
- * A list with O(1) effort for random access.
- *
- * @author Eike Stepper
- */
-public class MoveableArrayList<E> extends ArrayList<E> implements MoveableList<E>
-{
- private static final long serialVersionUID = 1L;
-
- public MoveableArrayList(int initialCapacity)
- {
- super(initialCapacity);
- }
-
- /**
- * @since 3.0
- */
- public void move(int newPosition, Object object)
- {
- move(newPosition, indexOf(object));
- }
-
- public E move(int targetIndex, int sourceIndex)
- {
- int size = size();
- if (sourceIndex >= size)
- {
- throw new IndexOutOfBoundsException("sourceIndex=" + sourceIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (targetIndex >= size)
- {
- throw new IndexOutOfBoundsException("targetIndex=" + targetIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- E object = get(sourceIndex);
- if (targetIndex == sourceIndex)
- {
- return object;
- }
-
- if (targetIndex < sourceIndex)
- {
- moveUp1(targetIndex, sourceIndex - targetIndex);
- }
- else
- {
- moveDown1(targetIndex, targetIndex - sourceIndex);
- }
-
- set(targetIndex, object);
- return object;
- }
-
- private void moveUp1(int index, int count)
- {
- for (int i = count; i > 0; i--)
- {
- set(index + i, get(index + i - 1));
- }
- }
-
- private void moveDown1(int index, int count)
- {
- for (int i = count; i > 0; i--)
- {
- set(index - i, get(index - i + 1));
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.ArrayList;
+
+/**
+ * A list with O(1) effort for random access.
+ *
+ * @author Eike Stepper
+ */
+public class MoveableArrayList<E> extends ArrayList<E> implements MoveableList<E>
+{
+ private static final long serialVersionUID = 1L;
+
+ public MoveableArrayList(int initialCapacity)
+ {
+ super(initialCapacity);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void move(int newPosition, Object object)
+ {
+ move(newPosition, indexOf(object));
+ }
+
+ public E move(int targetIndex, int sourceIndex)
+ {
+ int size = size();
+ if (sourceIndex >= size)
+ {
+ throw new IndexOutOfBoundsException("sourceIndex=" + sourceIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (targetIndex >= size)
+ {
+ throw new IndexOutOfBoundsException("targetIndex=" + targetIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ E object = get(sourceIndex);
+ if (targetIndex == sourceIndex)
+ {
+ return object;
+ }
+
+ if (targetIndex < sourceIndex)
+ {
+ moveUp1(targetIndex, sourceIndex - targetIndex);
+ }
+ else
+ {
+ moveDown1(targetIndex, targetIndex - sourceIndex);
+ }
+
+ set(targetIndex, object);
+ return object;
+ }
+
+ private void moveUp1(int index, int count)
+ {
+ for (int i = count; i > 0; i--)
+ {
+ set(index + i, get(index + i - 1));
+ }
+ }
+
+ private void moveDown1(int index, int count)
+ {
+ for (int i = count; i > 0; i--)
+ {
+ set(index - i, get(index - i + 1));
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableList.java
index 9b77cdb070..4b1751ee3e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableList.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MoveableList.java
@@ -1,21 +1,21 @@
-/*
- * 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;
-
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public interface MoveableList<E> extends List<E>
-{
- public E move(int targetIndex, int sourceIndex);
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public interface MoveableList<E> extends List<E>
+{
+ public E move(int targetIndex, int sourceIndex);
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MultiMap.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MultiMap.java
index 268cc231ea..f025e66147 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MultiMap.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/MultiMap.java
@@ -1,775 +1,775 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-import java.util.AbstractCollection;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public abstract class MultiMap<K, V> implements Map<K, V>
-{
- private transient Entries entries;
-
- private transient Set<K> keys;
-
- private transient Collection<V> values;
-
- public MultiMap()
- {
- }
-
- public abstract int getDelegateCount();
-
- public Map<K, V> getDelegate(int index)
- {
- if (0 <= index && index < getDelegateCount())
- {
- return doGetDelegate(index);
- }
-
- return null;
- }
-
- /**
- * @category WRITE
- */
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- public V put(K key, V value)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- public void putAll(Map<? extends K, ? extends V> t)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- public V remove(Object key)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- public boolean containsKey(Object key)
- {
- return containsKey(key, getDelegateCount());
- }
-
- /**
- * @category READ
- */
- public boolean containsValue(Object value)
- {
- for (int i = 0; i < getDelegateCount(); i++)
- {
- Map<K, V> delegate = getDelegate(i);
- if (delegate != null)
- {
- if (delegate.containsValue(value))
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * @category READ
- */
- public V get(Object key)
- {
- for (int i = 0; i < getDelegateCount(); i++)
- {
- Map<K, V> delegate = getDelegate(i);
- if (delegate != null)
- {
- if (delegate.containsKey(key))
- {
- return delegate.get(key);
- }
- }
- }
-
- return null;
- }
-
- /**
- * @category READ
- */
- public int size()
- {
- int size = 0;
- Map<K, V> delegate = getDelegate(0);
- if (delegate != null)
- {
- size += delegate.size();
- for (int i = 1; i < getDelegateCount(); i++)
- {
- delegate = getDelegate(i);
- if (delegate != null)
- {
- Set<K> keySet = delegate.keySet();
- for (K key : keySet)
- {
- if (!containsKey(key, i))
- {
- ++size;
- }
- }
- }
- }
- }
-
- return size;
- }
-
- /**
- * @category READ
- */
- public boolean isEmpty()
- {
- for (int i = 0; i < getDelegateCount(); i++)
- {
- Map<K, V> delegate = getDelegate(i);
- if (delegate != null)
- {
- if (!delegate.isEmpty())
- {
- return false;
- }
- }
- }
-
- return true;
- }
-
- public synchronized Set<Map.Entry<K, V>> entrySet()
- {
- if (entries == null)
- {
- entries = new Entries();
- }
-
- return entries;
- }
-
- public synchronized Set<K> keySet()
- {
- if (keys == null)
- {
- keys = new Keys();
- }
-
- return keys;
- }
-
- public synchronized Collection<V> values()
- {
- if (values == null)
- {
- values = new Values();
- }
-
- return values;
- }
-
- protected boolean containsKey(Object key, int delegateCount)
- {
- for (int i = 0; i < delegateCount; i++)
- {
- Map<K, V> delegate = getDelegate(i);
- if (delegate != null)
- {
- if (delegate.containsKey(key))
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- protected abstract Map<K, V> doGetDelegate(int index);
-
- /**
- * @author Eike Stepper
- */
- public static class ListBased<K, V> extends MultiMap<K, V>
- {
- private List<Map<K, V>> delegates;
-
- public ListBased()
- {
- }
-
- public ListBased(List<Map<K, V>> delegates)
- {
- this.delegates = delegates;
- }
-
- public synchronized List<Map<K, V>> getDelegates()
- {
- if (delegates == null)
- {
- delegates = createDelegates();
- }
-
- return delegates;
- }
-
- public void setDelegates(List<Map<K, V>> delegates)
- {
- this.delegates = delegates;
- }
-
- @Override
- public int getDelegateCount()
- {
- return getDelegates().size();
- }
-
- @Override
- protected Map<K, V> doGetDelegate(int index)
- {
- return getDelegates().get(index);
- }
-
- protected List<Map<K, V>> createDelegates()
- {
- return new ArrayList<Map<K, V>>();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class Entries extends AbstractSet<Entry<K, V>>
- {
- public Entries()
- {
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean add(Entry<K, V> o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean addAll(Collection<? extends Entry<K, V>> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean remove(Object o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean removeAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean retainAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- @Override
- public boolean contains(Object o)
- {
- if (o instanceof Map.Entry<?, ?>)
- {
- for (int i = 0; i < getDelegateCount(); i++)
- {
- Map<K, V> delegate = getDelegate(i);
- if (delegate != null)
- {
- @SuppressWarnings("unchecked")
- K key = ((Map.Entry<K, V>)o).getKey();
- if (delegate.containsKey(key))
- {
- @SuppressWarnings("unchecked")
- V value = ((Map.Entry<K, V>)o).getValue();
- if (ObjectUtil.equals(delegate.get(key), value))
- {
- return true;
- }
- }
- }
- }
- }
-
- return false;
- }
-
- /**
- * @category READ
- */
- @Override
- public boolean isEmpty()
- {
- return MultiMap.this.isEmpty();
- }
-
- /**
- * @category READ
- */
- @Override
- public int size()
- {
- return MultiMap.this.size();
- }
-
- @Override
- public Iterator<Entry<K, V>> iterator()
- {
- return new Iterator<Entry<K, V>>()
- {
- private Entry<K, V> next;
-
- private int delegateIndex = -1;
-
- private Iterator<Entry<K, V>> delegateIt;
-
- /**
- * @category WRITE
- */
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- public boolean hasNext()
- {
- next = null;
- while (next == null)
- {
- if (delegateIt == null)
- {
- Map<K, V> delegate = getDelegate(++delegateIndex);
- if (delegate == null)
- {
- // All delegates have been iterated
- break;
- }
-
- delegateIt = delegate.entrySet().iterator();
- }
-
- if (delegateIt.hasNext())
- {
- next = delegateIt.next();
-
- // Check if this key has been returned previously
- if (containsKey(next.getKey(), delegateIndex))
- {
- next = null;
- }
- }
- else
- {
- // Determine next delegate iterator in next loop
- delegateIt = null;
- }
- }
-
- return next != null;
- }
-
- /**
- * @category READ
- */
- public Map.Entry<K, V> next()
- {
- if (next == null)
- {
- throw new NoSuchElementException();
- }
-
- try
- {
- return next;
- }
- finally
- {
- next = null;
- }
- }
- };
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class Keys extends AbstractSet<K>
- {
- public Keys()
- {
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean add(K o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean addAll(Collection<? extends K> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean remove(Object o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean removeAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean retainAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- @Override
- public boolean contains(Object o)
- {
- return MultiMap.this.containsKey(o);
- }
-
- /**
- * @category READ
- */
- @Override
- public boolean isEmpty()
- {
- return MultiMap.this.isEmpty();
- }
-
- /**
- * @category READ
- */
- @Override
- public int size()
- {
- return MultiMap.this.size();
- }
-
- /**
- * @category READ
- */
- @Override
- public Iterator<K> iterator()
- {
- return new Iterator<K>()
- {
- private K next;
-
- private int delegateIndex = -1;
-
- private Iterator<K> delegateIt;
-
- /**
- * @category WRITE
- */
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- public boolean hasNext()
- {
- next = null;
- while (next == null)
- {
- if (delegateIt == null)
- {
- Map<K, V> delegate = getDelegate(++delegateIndex);
- if (delegate == null)
- {
- // All delegates have been iterated
- break;
- }
-
- delegateIt = delegate.keySet().iterator();
- }
-
- if (delegateIt.hasNext())
- {
- next = delegateIt.next();
-
- // Check if this key has been returned previously
- if (containsKey(next, delegateIndex))
- {
- next = null;
- }
- }
- else
- {
- // Determine next delegate iterator in next loop
- delegateIt = null;
- }
- }
-
- return next != null;
- }
-
- /**
- * @category READ
- */
- public K next()
- {
- if (next == null)
- {
- throw new NoSuchElementException();
- }
-
- try
- {
- return next;
- }
- finally
- {
- next = null;
- }
- }
- };
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class Values extends AbstractCollection<V>
- {
- public Values()
- {
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean add(V o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean addAll(Collection<? extends V> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean remove(Object o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean removeAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category WRITE
- */
- @Override
- public boolean retainAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- @Override
- public boolean contains(Object o)
- {
- return MultiMap.this.containsValue(o);
- }
-
- /**
- * @category READ
- */
- @Override
- public boolean isEmpty()
- {
- return MultiMap.this.isEmpty();
- }
-
- /**
- * @category READ
- */
- @Override
- public int size()
- {
- return MultiMap.this.size();
- }
-
- /**
- * @category READ
- */
- @Override
- public Iterator<V> iterator()
- {
- return new Iterator<V>()
- {
- private Iterator<Entry<K, V>> delegateIt = entrySet().iterator();
-
- /**
- * @category WRITE
- */
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @category READ
- */
- public boolean hasNext()
- {
- return delegateIt.hasNext();
- }
-
- /**
- * @category READ
- */
- public V next()
- {
- return delegateIt.next().getValue();
- }
- };
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+import java.util.AbstractCollection;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class MultiMap<K, V> implements Map<K, V>
+{
+ private transient Entries entries;
+
+ private transient Set<K> keys;
+
+ private transient Collection<V> values;
+
+ public MultiMap()
+ {
+ }
+
+ public abstract int getDelegateCount();
+
+ public Map<K, V> getDelegate(int index)
+ {
+ if (0 <= index && index < getDelegateCount())
+ {
+ return doGetDelegate(index);
+ }
+
+ return null;
+ }
+
+ /**
+ * @category WRITE
+ */
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ public V put(K key, V value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ public void putAll(Map<? extends K, ? extends V> t)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ public V remove(Object key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ public boolean containsKey(Object key)
+ {
+ return containsKey(key, getDelegateCount());
+ }
+
+ /**
+ * @category READ
+ */
+ public boolean containsValue(Object value)
+ {
+ for (int i = 0; i < getDelegateCount(); i++)
+ {
+ Map<K, V> delegate = getDelegate(i);
+ if (delegate != null)
+ {
+ if (delegate.containsValue(value))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @category READ
+ */
+ public V get(Object key)
+ {
+ for (int i = 0; i < getDelegateCount(); i++)
+ {
+ Map<K, V> delegate = getDelegate(i);
+ if (delegate != null)
+ {
+ if (delegate.containsKey(key))
+ {
+ return delegate.get(key);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @category READ
+ */
+ public int size()
+ {
+ int size = 0;
+ Map<K, V> delegate = getDelegate(0);
+ if (delegate != null)
+ {
+ size += delegate.size();
+ for (int i = 1; i < getDelegateCount(); i++)
+ {
+ delegate = getDelegate(i);
+ if (delegate != null)
+ {
+ Set<K> keySet = delegate.keySet();
+ for (K key : keySet)
+ {
+ if (!containsKey(key, i))
+ {
+ ++size;
+ }
+ }
+ }
+ }
+ }
+
+ return size;
+ }
+
+ /**
+ * @category READ
+ */
+ public boolean isEmpty()
+ {
+ for (int i = 0; i < getDelegateCount(); i++)
+ {
+ Map<K, V> delegate = getDelegate(i);
+ if (delegate != null)
+ {
+ if (!delegate.isEmpty())
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public synchronized Set<Map.Entry<K, V>> entrySet()
+ {
+ if (entries == null)
+ {
+ entries = new Entries();
+ }
+
+ return entries;
+ }
+
+ public synchronized Set<K> keySet()
+ {
+ if (keys == null)
+ {
+ keys = new Keys();
+ }
+
+ return keys;
+ }
+
+ public synchronized Collection<V> values()
+ {
+ if (values == null)
+ {
+ values = new Values();
+ }
+
+ return values;
+ }
+
+ protected boolean containsKey(Object key, int delegateCount)
+ {
+ for (int i = 0; i < delegateCount; i++)
+ {
+ Map<K, V> delegate = getDelegate(i);
+ if (delegate != null)
+ {
+ if (delegate.containsKey(key))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ protected abstract Map<K, V> doGetDelegate(int index);
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ListBased<K, V> extends MultiMap<K, V>
+ {
+ private List<Map<K, V>> delegates;
+
+ public ListBased()
+ {
+ }
+
+ public ListBased(List<Map<K, V>> delegates)
+ {
+ this.delegates = delegates;
+ }
+
+ public synchronized List<Map<K, V>> getDelegates()
+ {
+ if (delegates == null)
+ {
+ delegates = createDelegates();
+ }
+
+ return delegates;
+ }
+
+ public void setDelegates(List<Map<K, V>> delegates)
+ {
+ this.delegates = delegates;
+ }
+
+ @Override
+ public int getDelegateCount()
+ {
+ return getDelegates().size();
+ }
+
+ @Override
+ protected Map<K, V> doGetDelegate(int index)
+ {
+ return getDelegates().get(index);
+ }
+
+ protected List<Map<K, V>> createDelegates()
+ {
+ return new ArrayList<Map<K, V>>();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class Entries extends AbstractSet<Entry<K, V>>
+ {
+ public Entries()
+ {
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean add(Entry<K, V> o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean addAll(Collection<? extends Entry<K, V>> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public boolean contains(Object o)
+ {
+ if (o instanceof Map.Entry<?, ?>)
+ {
+ for (int i = 0; i < getDelegateCount(); i++)
+ {
+ Map<K, V> delegate = getDelegate(i);
+ if (delegate != null)
+ {
+ @SuppressWarnings("unchecked")
+ K key = ((Map.Entry<K, V>)o).getKey();
+ if (delegate.containsKey(key))
+ {
+ @SuppressWarnings("unchecked")
+ V value = ((Map.Entry<K, V>)o).getValue();
+ if (ObjectUtil.equals(delegate.get(key), value))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public boolean isEmpty()
+ {
+ return MultiMap.this.isEmpty();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public int size()
+ {
+ return MultiMap.this.size();
+ }
+
+ @Override
+ public Iterator<Entry<K, V>> iterator()
+ {
+ return new Iterator<Entry<K, V>>()
+ {
+ private Entry<K, V> next;
+
+ private int delegateIndex = -1;
+
+ private Iterator<Entry<K, V>> delegateIt;
+
+ /**
+ * @category WRITE
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ public boolean hasNext()
+ {
+ next = null;
+ while (next == null)
+ {
+ if (delegateIt == null)
+ {
+ Map<K, V> delegate = getDelegate(++delegateIndex);
+ if (delegate == null)
+ {
+ // All delegates have been iterated
+ break;
+ }
+
+ delegateIt = delegate.entrySet().iterator();
+ }
+
+ if (delegateIt.hasNext())
+ {
+ next = delegateIt.next();
+
+ // Check if this key has been returned previously
+ if (containsKey(next.getKey(), delegateIndex))
+ {
+ next = null;
+ }
+ }
+ else
+ {
+ // Determine next delegate iterator in next loop
+ delegateIt = null;
+ }
+ }
+
+ return next != null;
+ }
+
+ /**
+ * @category READ
+ */
+ public Map.Entry<K, V> next()
+ {
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+
+ try
+ {
+ return next;
+ }
+ finally
+ {
+ next = null;
+ }
+ }
+ };
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class Keys extends AbstractSet<K>
+ {
+ public Keys()
+ {
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean add(K o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean addAll(Collection<? extends K> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public boolean contains(Object o)
+ {
+ return MultiMap.this.containsKey(o);
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public boolean isEmpty()
+ {
+ return MultiMap.this.isEmpty();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public int size()
+ {
+ return MultiMap.this.size();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public Iterator<K> iterator()
+ {
+ return new Iterator<K>()
+ {
+ private K next;
+
+ private int delegateIndex = -1;
+
+ private Iterator<K> delegateIt;
+
+ /**
+ * @category WRITE
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ public boolean hasNext()
+ {
+ next = null;
+ while (next == null)
+ {
+ if (delegateIt == null)
+ {
+ Map<K, V> delegate = getDelegate(++delegateIndex);
+ if (delegate == null)
+ {
+ // All delegates have been iterated
+ break;
+ }
+
+ delegateIt = delegate.keySet().iterator();
+ }
+
+ if (delegateIt.hasNext())
+ {
+ next = delegateIt.next();
+
+ // Check if this key has been returned previously
+ if (containsKey(next, delegateIndex))
+ {
+ next = null;
+ }
+ }
+ else
+ {
+ // Determine next delegate iterator in next loop
+ delegateIt = null;
+ }
+ }
+
+ return next != null;
+ }
+
+ /**
+ * @category READ
+ */
+ public K next()
+ {
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+
+ try
+ {
+ return next;
+ }
+ finally
+ {
+ next = null;
+ }
+ }
+ };
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class Values extends AbstractCollection<V>
+ {
+ public Values()
+ {
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean add(V o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean addAll(Collection<? extends V> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category WRITE
+ */
+ @Override
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public boolean contains(Object o)
+ {
+ return MultiMap.this.containsValue(o);
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public boolean isEmpty()
+ {
+ return MultiMap.this.isEmpty();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public int size()
+ {
+ return MultiMap.this.size();
+ }
+
+ /**
+ * @category READ
+ */
+ @Override
+ public Iterator<V> iterator()
+ {
+ return new Iterator<V>()
+ {
+ private Iterator<Entry<K, V>> delegateIt = entrySet().iterator();
+
+ /**
+ * @category WRITE
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @category READ
+ */
+ public boolean hasNext()
+ {
+ return delegateIt.hasNext();
+ }
+
+ /**
+ * @category READ
+ */
+ public V next()
+ {
+ return delegateIt.next().getValue();
+ }
+ };
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java
index e74d5e46ec..f23cbb46cb 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java
@@ -1,100 +1,100 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-/**
- * @author Eike Stepper
- */
-public class Pair<T1, T2>
-{
- private T1 element1;
-
- private T2 element2;
-
- public Pair()
- {
- }
-
- public Pair(T1 element1, T2 element2)
- {
- this.element1 = element1;
- this.element2 = element2;
- }
-
- /**
- * @since 2.0
- */
- public Pair(Pair<T1, T2> source)
- {
- element1 = source.element1;
- element2 = source.element2;
- }
-
- public final T1 getElement1()
- {
- return element1;
- }
-
- public void setElement1(T1 element1)
- {
- this.element1 = element1;
- }
-
- public final T2 getElement2()
- {
- return element2;
- }
-
- public void setElement2(T2 element2)
- {
- this.element2 = element2;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
-
- if (obj instanceof Pair<?, ?>)
- {
- Pair<?, ?> that = (Pair<?, ?>)obj;
- return ObjectUtil.equals(element1, that.getElement1()) && ObjectUtil.equals(element2, that.getElement2());
- }
-
- return false;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public int hashCode()
- {
- return ObjectUtil.hashCode(element1) ^ ObjectUtil.hashCode(element2);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public String toString()
- {
- return "Pair[" + element1 + ", " + element2 + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class Pair<T1, T2>
+{
+ private T1 element1;
+
+ private T2 element2;
+
+ public Pair()
+ {
+ }
+
+ public Pair(T1 element1, T2 element2)
+ {
+ this.element1 = element1;
+ this.element2 = element2;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Pair(Pair<T1, T2> source)
+ {
+ element1 = source.element1;
+ element2 = source.element2;
+ }
+
+ public final T1 getElement1()
+ {
+ return element1;
+ }
+
+ public void setElement1(T1 element1)
+ {
+ this.element1 = element1;
+ }
+
+ public final T2 getElement2()
+ {
+ return element2;
+ }
+
+ public void setElement2(T2 element2)
+ {
+ this.element2 = element2;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj instanceof Pair<?, ?>)
+ {
+ Pair<?, ?> that = (Pair<?, ?>)obj;
+ return ObjectUtil.equals(element1, that.getElement1()) && ObjectUtil.equals(element2, that.getElement2());
+ }
+
+ return false;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(element1) ^ ObjectUtil.hashCode(element2);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String toString()
+ {
+ return "Pair[" + element1 + ", " + element2 + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PreferenceHistory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PreferenceHistory.java
index 88c251c9eb..b5cf423284 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PreferenceHistory.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PreferenceHistory.java
@@ -1,54 +1,54 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.CheckUtil;
-import org.eclipse.net4j.util.om.pref.OMPreference;
-
-/**
- * @author Eike Stepper
- */
-public class PreferenceHistory extends History<String>
-{
- private OMPreference<String[]> preference;
-
- public PreferenceHistory(OMPreference<String[]> preference)
- {
- CheckUtil.checkArg(preference, "preference");
- this.preference = preference;
- }
-
- public OMPreference<String[]> getPreference()
- {
- return preference;
- }
-
- @Override
- protected void load()
- {
- String[] value = preference.getValue();
- if (value != null)
- {
- for (String data : value)
- {
- IHistoryElement<String> element = createElement(data);
- elements.add(element);
- }
- }
- }
-
- @Override
- protected void save()
- {
- String[] array = getData(new String[size()]);
- preference.setValue(array);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.CheckUtil;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+/**
+ * @author Eike Stepper
+ */
+public class PreferenceHistory extends History<String>
+{
+ private OMPreference<String[]> preference;
+
+ public PreferenceHistory(OMPreference<String[]> preference)
+ {
+ CheckUtil.checkArg(preference, "preference");
+ this.preference = preference;
+ }
+
+ public OMPreference<String[]> getPreference()
+ {
+ return preference;
+ }
+
+ @Override
+ protected void load()
+ {
+ String[] value = preference.getValue();
+ if (value != null)
+ {
+ for (String data : value)
+ {
+ IHistoryElement<String> element = createElement(data);
+ elements.add(element);
+ }
+ }
+ }
+
+ @Override
+ protected void save()
+ {
+ String[] array = getData(new String[size()]);
+ preference.setValue(array);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/RoundRobinBlockingQueue.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/RoundRobinBlockingQueue.java
index 85f7d054e2..508c8d62a1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/RoundRobinBlockingQueue.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/RoundRobinBlockingQueue.java
@@ -1,368 +1,368 @@
-/*
- * 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;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Eike Stepper
- * @since 3.1
- */
-public class RoundRobinBlockingQueue<E> implements BlockingQueue<E>
-{
- private BlockingQueue<Entry<E>> list = new LinkedBlockingQueue<Entry<E>>();
-
- public RoundRobinBlockingQueue()
- {
- }
-
- public int remainingCapacity()
- {
- return Integer.MAX_VALUE;
- }
-
- public int size()
- {
- int size = 0;
- synchronized (list)
- {
- for (Entry<E> entry : list)
- {
- size += entry.getCount();
- }
- }
-
- return size;
- }
-
- public boolean isEmpty()
- {
- synchronized (list)
- {
- return list.isEmpty();
- }
- }
-
- public boolean offer(E e)
- {
- synchronized (list)
- {
- for (Entry<E> entry : list)
- {
- if (ObjectUtil.equals(entry.getElement(), e))
- {
- entry.increaseCount();
- return true;
- }
- }
-
- return list.add(new Entry<E>(e));
- }
- }
-
- public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
- {
- return offer(o);
- }
-
- public void put(E o) throws InterruptedException
- {
- offer(o);
- }
-
- public boolean add(E o)
- {
- return offer(o);
- }
-
- public E poll(long timeout, TimeUnit unit) throws InterruptedException
- {
- synchronized (list)
- {
- Entry<E> entry = list.poll(timeout, unit);
- if (entry == null)
- {
- return null;
- }
-
- if (entry.decreaseCount() > 0)
- {
- list.add(entry);
- }
-
- return entry.getElement();
- }
- }
-
- public E poll()
- {
- synchronized (list)
- {
- Entry<E> entry = list.poll();
- if (entry == null)
- {
- return null;
- }
-
- if (entry.decreaseCount() > 0)
- {
- list.add(entry);
- }
-
- return entry.getElement();
- }
- }
-
- public E take() throws InterruptedException
- {
- synchronized (list)
- {
- Entry<E> entry = list.take();
- if (entry.decreaseCount() > 0)
- {
- list.add(entry);
- }
-
- return entry.getElement();
- }
- }
-
- public E peek()
- {
- synchronized (list)
- {
- Entry<E> entry = list.peek();
- if (entry == null)
- {
- return null;
- }
-
- return entry.getElement();
- }
- }
-
- public E element()
- {
- synchronized (list)
- {
- Entry<E> entry = list.element();
- if (entry == null)
- {
- return null;
- }
-
- return entry.getElement();
- }
- }
-
- public E remove()
- {
- synchronized (list)
- {
- Entry<E> entry = list.remove();
- if (entry.decreaseCount() > 0)
- {
- list.add(entry);
- }
-
- return entry.getElement();
- }
- }
-
- public boolean remove(Object o)
- {
- synchronized (list)
- {
- for (Iterator<Entry<E>> it = list.iterator(); it.hasNext();)
- {
- Entry<E> entry = it.next();
- if (ObjectUtil.equals(entry.getElement(), o))
- {
- if (entry.decreaseCount() > 0)
- {
- it.remove();
- }
-
- return true;
- }
- }
- }
-
- return false;
- }
-
- public void clear()
- {
- synchronized (list)
- {
- list.clear();
- }
- }
-
- public Iterator<E> iterator()
- {
- List<E> copy = new ArrayList<E>();
-
- synchronized (list)
- {
- int round = 0;
- boolean again;
-
- do
- {
- again = false;
- for (Entry<E> entry : list)
- {
- int rest = entry.getCount() - round;
- if (rest > 0)
- {
- copy.add(entry.getElement());
- if (rest > 1)
- {
- again = true;
- }
- }
- }
-
- ++round;
- } while (again);
- }
-
- return copy.iterator();
- }
-
- public boolean contains(Object o)
- {
- synchronized (list)
- {
- for (Entry<E> entry : list)
- {
- if (ObjectUtil.equals(entry.getElement(), o))
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- public Object[] toArray()
- {
- synchronized (list)
- {
- return list.toArray();
- }
- }
-
- public <T> T[] toArray(T[] array)
- {
- synchronized (list)
- {
- return list.toArray(array);
- }
- }
-
- public boolean containsAll(Collection<?> c)
- {
- // TODO: implement RoundRobinBlockingQueue.containsAll(c)
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection<? extends E> c)
- {
- // TODO: implement RoundRobinBlockingQueue.addAll(c)
- throw new UnsupportedOperationException();
- }
-
- public boolean removeAll(Collection<?> c)
- {
- // TODO: implement RoundRobinBlockingQueue.removeAll(c)
- throw new UnsupportedOperationException();
- }
-
- public boolean retainAll(Collection<?> c)
- {
- // TODO: implement RoundRobinBlockingQueue.retainAll(c)
- throw new UnsupportedOperationException();
- }
-
- public int drainTo(Collection<? super E> c)
- {
- // TODO: implement RoundRobinBlockingQueue.drainTo(c)
- throw new UnsupportedOperationException();
- }
-
- public int drainTo(Collection<? super E> c, int maxElements)
- {
- // TODO: implement RoundRobinBlockingQueue.drainTo(c, maxElements)
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String toString()
- {
- synchronized (list)
- {
- return list.toString();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class Entry<E>
- {
- private E element;
-
- private int count;
-
- public Entry(E element)
- {
- this.element = element;
- count = 1;
- }
-
- public E getElement()
- {
- return element;
- }
-
- public int getCount()
- {
- return count;
- }
-
- public int increaseCount()
- {
- return ++count;
- }
-
- public int decreaseCount()
- {
- return --count;
- }
-
- @Override
- public String toString()
- {
- return element.toString() + "(" + count + ")";
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public class RoundRobinBlockingQueue<E> implements BlockingQueue<E>
+{
+ private BlockingQueue<Entry<E>> list = new LinkedBlockingQueue<Entry<E>>();
+
+ public RoundRobinBlockingQueue()
+ {
+ }
+
+ public int remainingCapacity()
+ {
+ return Integer.MAX_VALUE;
+ }
+
+ public int size()
+ {
+ int size = 0;
+ synchronized (list)
+ {
+ for (Entry<E> entry : list)
+ {
+ size += entry.getCount();
+ }
+ }
+
+ return size;
+ }
+
+ public boolean isEmpty()
+ {
+ synchronized (list)
+ {
+ return list.isEmpty();
+ }
+ }
+
+ public boolean offer(E e)
+ {
+ synchronized (list)
+ {
+ for (Entry<E> entry : list)
+ {
+ if (ObjectUtil.equals(entry.getElement(), e))
+ {
+ entry.increaseCount();
+ return true;
+ }
+ }
+
+ return list.add(new Entry<E>(e));
+ }
+ }
+
+ public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
+ {
+ return offer(o);
+ }
+
+ public void put(E o) throws InterruptedException
+ {
+ offer(o);
+ }
+
+ public boolean add(E o)
+ {
+ return offer(o);
+ }
+
+ public E poll(long timeout, TimeUnit unit) throws InterruptedException
+ {
+ synchronized (list)
+ {
+ Entry<E> entry = list.poll(timeout, unit);
+ if (entry == null)
+ {
+ return null;
+ }
+
+ if (entry.decreaseCount() > 0)
+ {
+ list.add(entry);
+ }
+
+ return entry.getElement();
+ }
+ }
+
+ public E poll()
+ {
+ synchronized (list)
+ {
+ Entry<E> entry = list.poll();
+ if (entry == null)
+ {
+ return null;
+ }
+
+ if (entry.decreaseCount() > 0)
+ {
+ list.add(entry);
+ }
+
+ return entry.getElement();
+ }
+ }
+
+ public E take() throws InterruptedException
+ {
+ synchronized (list)
+ {
+ Entry<E> entry = list.take();
+ if (entry.decreaseCount() > 0)
+ {
+ list.add(entry);
+ }
+
+ return entry.getElement();
+ }
+ }
+
+ public E peek()
+ {
+ synchronized (list)
+ {
+ Entry<E> entry = list.peek();
+ if (entry == null)
+ {
+ return null;
+ }
+
+ return entry.getElement();
+ }
+ }
+
+ public E element()
+ {
+ synchronized (list)
+ {
+ Entry<E> entry = list.element();
+ if (entry == null)
+ {
+ return null;
+ }
+
+ return entry.getElement();
+ }
+ }
+
+ public E remove()
+ {
+ synchronized (list)
+ {
+ Entry<E> entry = list.remove();
+ if (entry.decreaseCount() > 0)
+ {
+ list.add(entry);
+ }
+
+ return entry.getElement();
+ }
+ }
+
+ public boolean remove(Object o)
+ {
+ synchronized (list)
+ {
+ for (Iterator<Entry<E>> it = list.iterator(); it.hasNext();)
+ {
+ Entry<E> entry = it.next();
+ if (ObjectUtil.equals(entry.getElement(), o))
+ {
+ if (entry.decreaseCount() > 0)
+ {
+ it.remove();
+ }
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public void clear()
+ {
+ synchronized (list)
+ {
+ list.clear();
+ }
+ }
+
+ public Iterator<E> iterator()
+ {
+ List<E> copy = new ArrayList<E>();
+
+ synchronized (list)
+ {
+ int round = 0;
+ boolean again;
+
+ do
+ {
+ again = false;
+ for (Entry<E> entry : list)
+ {
+ int rest = entry.getCount() - round;
+ if (rest > 0)
+ {
+ copy.add(entry.getElement());
+ if (rest > 1)
+ {
+ again = true;
+ }
+ }
+ }
+
+ ++round;
+ } while (again);
+ }
+
+ return copy.iterator();
+ }
+
+ public boolean contains(Object o)
+ {
+ synchronized (list)
+ {
+ for (Entry<E> entry : list)
+ {
+ if (ObjectUtil.equals(entry.getElement(), o))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public Object[] toArray()
+ {
+ synchronized (list)
+ {
+ return list.toArray();
+ }
+ }
+
+ public <T> T[] toArray(T[] array)
+ {
+ synchronized (list)
+ {
+ return list.toArray(array);
+ }
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ // TODO: implement RoundRobinBlockingQueue.containsAll(c)
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends E> c)
+ {
+ // TODO: implement RoundRobinBlockingQueue.addAll(c)
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ // TODO: implement RoundRobinBlockingQueue.removeAll(c)
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ // TODO: implement RoundRobinBlockingQueue.retainAll(c)
+ throw new UnsupportedOperationException();
+ }
+
+ public int drainTo(Collection<? super E> c)
+ {
+ // TODO: implement RoundRobinBlockingQueue.drainTo(c)
+ throw new UnsupportedOperationException();
+ }
+
+ public int drainTo(Collection<? super E> c, int maxElements)
+ {
+ // TODO: implement RoundRobinBlockingQueue.drainTo(c, maxElements)
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString()
+ {
+ synchronized (list)
+ {
+ return list.toString();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class Entry<E>
+ {
+ private E element;
+
+ private int count;
+
+ public Entry(E element)
+ {
+ this.element = element;
+ count = 1;
+ }
+
+ public E getElement()
+ {
+ return element;
+ }
+
+ public int getCount()
+ {
+ return count;
+ }
+
+ public int increaseCount()
+ {
+ return ++count;
+ }
+
+ public int decreaseCount()
+ {
+ return --count;
+ }
+
+ @Override
+ public String toString()
+ {
+ return element.toString() + "(" + count + ")";
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Triplet.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Triplet.java
index 642d55f356..5656c815aa 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Triplet.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Triplet.java
@@ -1,79 +1,79 @@
-/*
- * 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:
- * Caspar De Groot - initial API and implementation
- */
-package org.eclipse.net4j.util.collection;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-/**
- * @author Caspar De Groot
- * @since 3.0
- */
-public class Triplet<T1, T2, T3> extends Pair<T1, T2>
-{
- private T3 element3;
-
- public Triplet()
- {
- }
-
- public Triplet(T1 element1, T2 element2, T3 element3)
- {
- super(element1, element2);
- this.element3 = element3;
- }
-
- public Triplet(Triplet<T1, T2, T3> source)
- {
- super(source.getElement1(), source.getElement2());
- element3 = source.element3;
- }
-
- public final T3 getElement3()
- {
- return element3;
- }
-
- public void setElement3(T3 element3)
- {
- this.element3 = element3;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
-
- if (obj instanceof Triplet<?, ?, ?>)
- {
- Triplet<?, ?, ?> that = (Triplet<?, ?, ?>)obj;
- return ObjectUtil.equals(getElement1(), that.getElement1()) //
- && ObjectUtil.equals(getElement2(), that.getElement2()) //
- && ObjectUtil.equals(element3, that.element3);
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return ObjectUtil.hashCode(getElement1()) ^ ObjectUtil.hashCode(getElement2()) ^ ObjectUtil.hashCode(element3);
- }
-
- @Override
- public String toString()
- {
- return "Triplet[" + getElement1() + ", " + getElement2() + ", " + element3 + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.net4j.util.collection;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+/**
+ * @author Caspar De Groot
+ * @since 3.0
+ */
+public class Triplet<T1, T2, T3> extends Pair<T1, T2>
+{
+ private T3 element3;
+
+ public Triplet()
+ {
+ }
+
+ public Triplet(T1 element1, T2 element2, T3 element3)
+ {
+ super(element1, element2);
+ this.element3 = element3;
+ }
+
+ public Triplet(Triplet<T1, T2, T3> source)
+ {
+ super(source.getElement1(), source.getElement2());
+ element3 = source.element3;
+ }
+
+ public final T3 getElement3()
+ {
+ return element3;
+ }
+
+ public void setElement3(T3 element3)
+ {
+ this.element3 = element3;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj instanceof Triplet<?, ?, ?>)
+ {
+ Triplet<?, ?, ?> that = (Triplet<?, ?, ?>)obj;
+ return ObjectUtil.equals(getElement1(), that.getElement1()) //
+ && ObjectUtil.equals(getElement2(), that.getElement2()) //
+ && ObjectUtil.equals(element3, that.element3);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(getElement1()) ^ ObjectUtil.hashCode(getElement2()) ^ ObjectUtil.hashCode(element3);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Triplet[" + getElement1() + ", " + getElement2() + ", " + element3 + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/package-info.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/package-info.java
index fe1d9ecea0..effa3c9d67 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/package-info.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 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

Back to the top