diff options
4 files changed, 189 insertions, 1 deletions
diff --git a/plugins/org.eclipse.net4j/TODOS.txt b/plugins/org.eclipse.net4j/TODOS.txt index e6b9e18569..fe0d4a26e0 100644 --- a/plugins/org.eclipse.net4j/TODOS.txt +++ b/plugins/org.eclipse.net4j/TODOS.txt @@ -1,2 +1 @@ SSL -SoftReferences in BufferPool diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/registry/UnmodifiableRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/registry/UnmodifiableRegistry.java new file mode 100644 index 0000000000..e97c23ca99 --- /dev/null +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/registry/UnmodifiableRegistry.java @@ -0,0 +1,123 @@ +package org.eclipse.internal.net4j.util.registry; + +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.registry.IRegistry; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public class UnmodifiableRegistry<K, V> implements IRegistry<K, V> +{ + private IRegistry<K, V> delegate; + + public UnmodifiableRegistry(IRegistry<K, V> delegate) + { + this.delegate = delegate; + } + + public void addListener(IListener listener) + { + delegate.addListener(listener); + } + + public void removeListener(IListener listener) + { + delegate.removeListener(listener); + } + + public V put(K key, V value) + { + throw new UnsupportedOperationException(); + } + + public void putAll(Map<? extends K, ? extends V> t) + { + throw new UnsupportedOperationException(); + } + + public V remove(Object key) + { + throw new UnsupportedOperationException(); + } + + public void clear() + { + throw new UnsupportedOperationException(); + } + + public void commit() + { + throw new UnsupportedOperationException(); + } + + public void commit(boolean notifications) + { + throw new UnsupportedOperationException(); + } + + public void setAutoCommit(boolean on) + { + throw new UnsupportedOperationException(); + } + + public boolean isAutoCommit() + { + return delegate.isAutoCommit(); + } + + public boolean isEmpty() + { + return delegate.isEmpty(); + } + + public int size() + { + return delegate.size(); + } + + public Entry<K, V>[] getElements() + { + return delegate.getElements(); + } + + public V get(Object key) + { + return delegate.get(key); + } + + public boolean containsKey(Object key) + { + return delegate.containsKey(key); + } + + public boolean containsValue(Object value) + { + return delegate.containsValue(value); + } + + public Set<Entry<K, V>> entrySet() + { + return delegate.entrySet(); + } + + public Set<K> keySet() + { + return delegate.keySet(); + } + + public Collection<V> values() + { + return delegate.values(); + } + + public boolean equals(Object o) + { + return delegate.equals(o); + } + + public int hashCode() + { + return delegate.hashCode(); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/container/ContainerUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/container/ContainerUtil.java new file mode 100644 index 0000000000..7f5b5e2b7a --- /dev/null +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/container/ContainerUtil.java @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, Germany. + * 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.container; + +/** + * @author Eike Stepper + */ +public final class ContainerUtil +{ + private static final Object[] NO_ELEMENTS = new Object[0]; + + private ContainerUtil() + { + } + + public Object[] getElements(Object container) + { + if (container instanceof IContainer) + { + return ((IContainer)container).getElements(); + } + + return NO_ELEMENTS; + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/RegistryUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/RegistryUtil.java new file mode 100644 index 0000000000..7831bdf598 --- /dev/null +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/RegistryUtil.java @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, Germany. + * 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.registry; + +import org.eclipse.internal.net4j.util.registry.UnmodifiableRegistry; + +/** + * @author Eike Stepper + */ +public final class RegistryUtil +{ + private RegistryUtil() + { + } + + public <K, V> IRegistry<K, V> unmodifiableRegistry(IRegistry<K, V> registry) + { + if (registry instanceof UnmodifiableRegistry) + { + return registry; + } + + return new UnmodifiableRegistry(registry); + } +} |