diff options
author | eutarass | 2008-12-08 19:11:24 +0000 |
---|---|---|
committer | eutarass | 2008-12-08 19:11:24 +0000 |
commit | a1736b5b4f898736830ef39ad658d8fdb777ebb2 (patch) | |
tree | dab7c336d979660550eac5dbc6005bb002677f66 | |
parent | 0e3f1e4fd4721f4479913c9b12dfe5698b95689a (diff) | |
download | org.eclipse.tcf-a1736b5b4f898736830ef39ad658d8fdb777ebb2.tar.gz org.eclipse.tcf-a1736b5b4f898736830ef39ad658d8fdb777ebb2.tar.xz org.eclipse.tcf-a1736b5b4f898736830ef39ad658d8fdb777ebb2.zip |
Bug 257670: Why does TCF have its own implementation of ReadOnlyCollection and ReadOnlyMap?
8 files changed, 5 insertions, 221 deletions
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/ReadOnlyCollection.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/ReadOnlyCollection.java deleted file mode 100644 index 7c27d0806..000000000 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/ReadOnlyCollection.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.internal.tcf.core; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -public class ReadOnlyCollection<E> implements Set<E> { - - private final Collection<E> base; - - public ReadOnlyCollection(Collection<E> base) { - this.base = base; - } - - private void error() { - throw new Error("Read only Collection"); - } - - public boolean add(E e) { - error(); - return false; - } - - public boolean addAll(Collection<? extends E> c) { - error(); - return false; - } - - public void clear() { - error(); - } - - public boolean contains(Object o) { - return base.contains(o); - } - - public boolean containsAll(Collection<?> c) { - return base.containsAll(c); - } - - public boolean isEmpty() { - return base.isEmpty(); - } - - public Iterator<E> iterator() { - final Iterator<E> iterator = base.iterator(); - return new Iterator<E>() { - - public boolean hasNext() { - return iterator.hasNext(); - } - - public E next() { - return iterator.next(); - } - - public void remove() { - error(); - } - }; - } - - public boolean remove(Object o) { - error(); - return false; - } - - public boolean removeAll(Collection<?> c) { - error(); - return false; - } - - public boolean retainAll(Collection<?> c) { - error(); - return false; - } - - public int size() { - return base.size(); - } - - public Object[] toArray() { - return base.toArray(); - } - - public <T> T[] toArray(T[] a) { - return base.toArray(a); - } - - public boolean equals(Object o) { - return base.equals(o); - } - - public int hashCode() { - return base.hashCode(); - } - - public String toString() { - return base.toString(); - } -} diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/ReadOnlyMap.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/ReadOnlyMap.java deleted file mode 100644 index 538713a3a..000000000 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/ReadOnlyMap.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tm.internal.tcf.core; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -public class ReadOnlyMap<K,V> implements Map<K,V> { - - private final Map<K,V> base; - private Set<K> key_set; - private Set<Map.Entry<K, V>> entry_set; - private Collection<V> values; - - public ReadOnlyMap(Map<K,V> base) { - this.base = base; - } - - private void error() { - throw new Error("Read only Map"); - } - - public void clear() { - error(); - } - - public boolean containsKey(Object key) { - return base.containsKey(key); - } - - public boolean containsValue(Object value) { - return base.containsValue(value); - } - - public Set<Map.Entry<K, V>> entrySet() { - if (entry_set == null) entry_set = new ReadOnlyCollection<Map.Entry<K, V>>(base.entrySet()); - return entry_set; - } - - public V get(Object key) { - return base.get(key); - } - - public boolean isEmpty() { - return base.isEmpty(); - } - - public Set<K> keySet() { - if (key_set == null) key_set = new ReadOnlyCollection<K>(base.keySet()); - return key_set; - } - - public V put(K key, V value) { - error(); - return null; - } - - public void putAll(Map<? extends K, ? extends V> m) { - error(); - } - - public V remove(Object key) { - error(); - return null; - } - - public int size() { - return base.size(); - } - - public Collection<V> values() { - if (values == null) values = new ReadOnlyCollection<V>(base.values()); - return values; - } - - public boolean equals(Object o) { - return base.equals(o); - } - - public int hashCode() { - return base.hashCode(); - } - - public String toString() { - return base.toString(); - } -} diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/StandardServiceProvider.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/StandardServiceProvider.java index 3f64279bf..737b0624a 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/StandardServiceProvider.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/core/StandardServiceProvider.java @@ -15,7 +15,6 @@ import org.eclipse.tm.internal.tcf.services.remote.LocatorProxy; import org.eclipse.tm.tcf.protocol.IChannel; import org.eclipse.tm.tcf.protocol.IService; import org.eclipse.tm.tcf.protocol.IServiceProvider; -import org.eclipse.tm.tcf.protocol.Protocol; public class StandardServiceProvider implements IServiceProvider { diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/MemoryProxy.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/MemoryProxy.java index f0dae19f1..b2835df6e 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/MemoryProxy.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/MemoryProxy.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.eclipse.tm.internal.tcf.core.ReadOnlyMap; import org.eclipse.tm.tcf.core.Base64; import org.eclipse.tm.tcf.core.Command; import org.eclipse.tm.tcf.protocol.IChannel; @@ -146,7 +145,6 @@ public class MemoryProxy implements IMemory { private final Map<String,Object> props; MemContext(Map<String,Object> props) { - assert props instanceof ReadOnlyMap; this.props = props; } diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RunControlProxy.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RunControlProxy.java index f64f8f34d..df1edf285 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RunControlProxy.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/RunControlProxy.java @@ -15,7 +15,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.eclipse.tm.internal.tcf.core.ReadOnlyMap; import org.eclipse.tm.tcf.core.Command; import org.eclipse.tm.tcf.protocol.IChannel; import org.eclipse.tm.tcf.protocol.IToken; @@ -34,7 +33,6 @@ public class RunControlProxy implements IRunControl { private final Map<String, Object> props; RunContext(Map<String, Object> props) { - assert props instanceof ReadOnlyMap; this.props = props; } diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/SysMonitorProxy.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/SysMonitorProxy.java index 6382dc582..75a17d5d5 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/SysMonitorProxy.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/SysMonitorProxy.java @@ -13,7 +13,6 @@ package org.eclipse.tm.internal.tcf.services.remote; import java.util.Collection; import java.util.Map; -import org.eclipse.tm.internal.tcf.core.ReadOnlyMap; import org.eclipse.tm.tcf.core.Command; import org.eclipse.tm.tcf.protocol.IChannel; import org.eclipse.tm.tcf.protocol.IToken; @@ -29,7 +28,6 @@ public class SysMonitorProxy implements ISysMonitor { private final Map<String, Object> props; SysMonitorContext(Map<String, Object> props) { - assert props instanceof ReadOnlyMap; this.props = props; } diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractPeer.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractPeer.java index b8c548f2e..f5675d4c0 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractPeer.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractPeer.java @@ -11,11 +11,11 @@ package org.eclipse.tm.tcf.core; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.eclipse.tm.internal.tcf.core.ReadOnlyMap; import org.eclipse.tm.internal.tcf.core.Transport; import org.eclipse.tm.internal.tcf.services.local.LocatorService; import org.eclipse.tm.tcf.protocol.IChannel; @@ -43,7 +43,7 @@ public abstract class AbstractPeer implements IPeer { else { rw_attrs = new HashMap<String, String>(); } - ro_attrs = new ReadOnlyMap<String, String>(rw_attrs); + ro_attrs = Collections.unmodifiableMap(rw_attrs); assert getID() != null; LocatorService.addPeer(this); } diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/JSON.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/JSON.java index ff7ab6004..e73be7976 100644 --- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/JSON.java +++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/JSON.java @@ -20,14 +20,12 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import org.eclipse.tm.internal.tcf.core.ReadOnlyCollection; -import org.eclipse.tm.internal.tcf.core.ReadOnlyMap; - /** * JSON is TCF preferred marshaling. This class implements generation and parsing of JSON strings. @@ -291,7 +289,7 @@ public final class JSON { } } read(); - return new ReadOnlyCollection<Object>(l); + return Collections.unmodifiableCollection(l); case '{': Map<String,Object> m = new HashMap<String,Object>(); read(); @@ -309,7 +307,7 @@ public final class JSON { } } read(); - return new ReadOnlyMap<String,Object>(m); + return Collections.unmodifiableMap(m); case 'n': read(); if (cur_ch != 'u') error(); |