From 5f7c9713456fc24d0cb138664ea90d7fe7bb5670 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Mon, 17 Oct 2011 17:28:37 +0000 Subject: [PATCH] return unmodifiable collections --- .../networkdb/kademlia/TransientDataStore.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java index f7797c7853..5caa262eab 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java @@ -9,6 +9,7 @@ package net.i2p.router.networkdb.kademlia; */ import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.concurrent.ConcurrentHashMap; import java.util.HashSet; @@ -56,24 +57,27 @@ class TransientDataStore implements DataStore { return _data.size(); } + /** + * @return Unmodifiable view, not a copy + */ public Set<Hash> getKeys() { - return new HashSet(_data.keySet()); + return Collections.unmodifiableSet(_data.keySet()); } /** - * @return not a copy + * @return Unmodifiable view, not a copy * @since 0.8.3 */ public Collection<DatabaseEntry> getEntries() { - return _data.values(); + return Collections.unmodifiableCollection(_data.values()); } /** - * @return not a copy + * @return Unmodifiable view, not a copy * @since 0.8.3 */ public Set<Map.Entry<Hash, DatabaseEntry>> getMapEntries() { - return _data.entrySet(); + return Collections.unmodifiableSet(_data.entrySet()); } /** for PersistentDataStore only - don't use here @throws IAE always */ -- GitLab