From 72adbeae90120840ec67fd1ddd963f4ca270c73f Mon Sep 17 00:00:00 2001 From: Marek Otahal Date: Sat, 7 Jan 2012 00:38:42 +0100 Subject: [PATCH] !Important: move from Hashtable to HashMap Hashtable is an obsolete collection v1, now since v2 offers HashMap with same or better functionality. Please review, almost all code was already moved, so only a few changes. That is not the issue, but I found notices that some (ugly big) helper classes had to be created in past to compensate missing Hashtable's functionality. I'd like input if we can remove some of them. look for //FIX: if these commits Signed-off-by: Marek Otahal --- source/de/anomic/data/Translator.java | 2 +- source/de/anomic/http/server/TemplateEngine.java | 6 +++--- source/de/anomic/server/serverObjects.java | 1 + source/de/anomic/tools/loaderThreads.java | 10 ++++++---- source/net/yacy/document/importer/OAIPMHImporter.java | 1 + source/net/yacy/kelondro/util/ByteArray.java | 2 ++ source/net/yacy/kelondro/util/OS.java | 6 +++--- source/net/yacy/peers/SeedDB.java | 10 +++++----- source/net/yacy/search/Switchboard.java | 3 +-- 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/source/de/anomic/data/Translator.java b/source/de/anomic/data/Translator.java index 15c16052d..17a4cb68e 100644 --- a/source/de/anomic/data/Translator.java +++ b/source/de/anomic/data/Translator.java @@ -80,7 +80,7 @@ public class Translator { /** * Load multiple translationLists from one File. Each List starts with #File: relative/path/to/file * @param translationFile the File, which contains the Lists - * @return a Hashtable, which contains for each File a Hashtable with translations. + * @return a HashMap, which contains for each File a HashMap with translations. */ public static Map> loadTranslationsLists(final File translationFile){ final Map> lists = new HashMap>(); //list of translationLists for different files. diff --git a/source/de/anomic/http/server/TemplateEngine.java b/source/de/anomic/http/server/TemplateEngine.java index 499ed5e0a..a047689f7 100644 --- a/source/de/anomic/http/server/TemplateEngine.java +++ b/source/de/anomic/http/server/TemplateEngine.java @@ -87,10 +87,10 @@ import net.yacy.kelondro.util.FileUtils; * </body></html> * *

- * The corresponding Hashtable to use this Template:
+ * The corresponding HashMap to use this Template:
* Java Example
*

- * Hashtable pattern;
+ * HashMap pattern;
  * pattern.put("times", 10); //10 greetings
  * for(int i=0;i<=9;i++){
  * 	pattern.put("times_"+i+"_daytime", 1); //index: 1, second Entry, evening
@@ -112,7 +112,7 @@ import net.yacy.kelondro.util.FileUtils;
  * 
  • Multi templates: multitemplatename_index_
  • *
  • Alterantives: alternativename_
  • * - * So the Names in the Hashtable are: + * So the Names in the HashMap are: *
      *
    • Multi templates: multitemplatename_index_templatename
    • *
    • Alterantives: alternativename_templatename
    • diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java index 579ac5c52..46d25502f 100644 --- a/source/de/anomic/server/serverObjects.java +++ b/source/de/anomic/server/serverObjects.java @@ -33,6 +33,7 @@ Properties - setProperty would be needed, but only available in 1.2 HashMap, TreeMap - only in 1.2 Hashtable - available in 1.0, but 'put' does not accept null values +//FIXME: it's 2012, do we still need support for Java 1.0?! So this class was created as a convenience. It will also contain special methods that read data from internet-resources diff --git a/source/de/anomic/tools/loaderThreads.java b/source/de/anomic/tools/loaderThreads.java index 7a061b4e2..176525bda 100644 --- a/source/de/anomic/tools/loaderThreads.java +++ b/source/de/anomic/tools/loaderThreads.java @@ -24,7 +24,9 @@ package de.anomic.tools; -import java.util.Hashtable; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import net.yacy.cora.protocol.ClientIdentification; import net.yacy.cora.protocol.http.ProxySettings; @@ -39,8 +41,8 @@ public class loaderThreads { protected ProxySettings remoteProxyConfig; // management objects for collection of threads - Hashtable threads; - int completed, failed; + private Map threads; + private int completed, failed; public loaderThreads() { this(10000, null, null); @@ -54,7 +56,7 @@ public class loaderThreads { this.timeout = timeout; this.user = user; this.password = password; - this.threads = new Hashtable(); + this.threads = new HashMap(); this.completed = 0; this.failed = 0; } diff --git a/source/net/yacy/document/importer/OAIPMHImporter.java b/source/net/yacy/document/importer/OAIPMHImporter.java index a97c0b06a..8985f6686 100644 --- a/source/net/yacy/document/importer/OAIPMHImporter.java +++ b/source/net/yacy/document/importer/OAIPMHImporter.java @@ -118,6 +118,7 @@ public class OAIPMHImporter extends Thread implements Importer, Comparable 50) { try {Thread.sleep(10000 + 3000 * (System.currentTimeMillis() % 6));} catch (InterruptedException e) {} diff --git a/source/net/yacy/kelondro/util/ByteArray.java b/source/net/yacy/kelondro/util/ByteArray.java index eb4810818..0ac0b633a 100644 --- a/source/net/yacy/kelondro/util/ByteArray.java +++ b/source/net/yacy/kelondro/util/ByteArray.java @@ -37,6 +37,8 @@ import net.yacy.cora.order.ByteOrder; * a byte[] in a Hashtable does not work because the hash computation does not * work for byte[]. This class extends byte[] with a cached hashing function, * so it can be used in hashtables. + * //FIXME: so does storing byte[] in HashMap help? as I'm moving use of Hashtable to + * //FIXME: HashMap, if so, please remove this class- or notify me */ public class ByteArray { diff --git a/source/net/yacy/kelondro/util/OS.java b/source/net/yacy/kelondro/util/OS.java index 6c38396f8..72378dc91 100644 --- a/source/net/yacy/kelondro/util/OS.java +++ b/source/net/yacy/kelondro/util/OS.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.util.ArrayList; -import java.util.Hashtable; import java.util.List; import java.util.Properties; import java.util.Vector; @@ -35,6 +34,7 @@ import java.util.Vector; import net.yacy.cora.document.UTF8; import net.yacy.kelondro.logging.Log; import de.anomic.server.serverCore; +import java.util.*; public final class OS { @@ -63,8 +63,8 @@ public final class OS { public static int maxPathLength = 65535; // Macintosh-specific statics - public static final Hashtable macFSTypeCache = new Hashtable(); - public static final Hashtable macFSCreatorCache = new Hashtable(); + public static final Map macFSTypeCache = new HashMap(); + public static final Map macFSCreatorCache = new HashMap(); // static initialization static { diff --git a/source/net/yacy/peers/SeedDB.java b/source/net/yacy/peers/SeedDB.java index cb631d1f2..f5a11642d 100644 --- a/source/net/yacy/peers/SeedDB.java +++ b/source/net/yacy/peers/SeedDB.java @@ -33,7 +33,7 @@ import java.lang.ref.SoftReference; import java.net.InetAddress; import java.util.ArrayList; import java.util.HashSet; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -98,8 +98,8 @@ public final class SeedDB implements AlternativeDomainNames { private Seed mySeed; // my own seed private final Set myBotIDs; // list of id's that this bot accepts as robots.txt identification - private final Hashtable nameLookupCache; // a name-to-hash relation - private final Hashtable> ipLookupCache; + private final Map nameLookupCache; // a name-to-hash relation + private final Map> ipLookupCache; public SeedDB( final File networkRoot, @@ -129,10 +129,10 @@ public final class SeedDB implements AlternativeDomainNames { this.seedPotentialDB = openSeedTable(this.seedPotentialDBFile); // start our virtual DNS service for yacy peers with empty cache - this.nameLookupCache = new Hashtable(); + this.nameLookupCache = new HashMap(); // cache for reverse name lookup - this.ipLookupCache = new Hashtable>(); + this.ipLookupCache = new HashMap>(); // check if we are in the seedCaches: this can happen if someone else published our seed removeMySeed(); diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java index cd72ffb02..16c75c348 100644 --- a/source/net/yacy/search/Switchboard.java +++ b/source/net/yacy/search/Switchboard.java @@ -56,7 +56,6 @@ import java.security.spec.InvalidKeySpecException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -260,7 +259,7 @@ public final class Switchboard extends serverSwitch //private Object crawlingPausedSync = new Object(); //private boolean crawlingIsPaused = false; - public Hashtable crawlJobsStatus = new Hashtable(); + public HashMap crawlJobsStatus = new HashMap(); private static Switchboard sb = null;