Author: orbiter Date: 2008-01-24 00:08:32 +0100 (Thu, 24 Jan 2008) New Revision: 4382
Modified: trunk/source/de/anomic/plasma/urlPattern/abstractURLPattern.java trunk/source/de/anomic/plasma/urlPattern/defaultURLPattern.java trunk/source/de/anomic/plasma/urlPattern/plasmaURLPattern.java trunk/source/de/anomic/server/logging/ConsoleOutErrHandler.java trunk/source/de/anomic/server/logging/GuiHandler.java trunk/source/de/anomic/server/logging/LogalizerHandler.java trunk/source/de/anomic/server/logging/logParsers/LogParserPLASMA.java trunk/source/de/anomic/yacy/yacyNewsPool.java trunk/source/de/anomic/yacy/yacyNewsQueue.java Log: more generics Modified: trunk/source/de/anomic/plasma/urlPattern/abstractURLPattern.java =================================================================== --- trunk/source/de/anomic/plasma/urlPattern/abstractURLPattern.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/plasma/urlPattern/abstractURLPattern.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -61,7 +61,7 @@ public abstract class abstractURLPattern implements plasmaURLPattern { - protected static final HashSet BLACKLIST_TYPES = new HashSet(Arrays.asList(new String[]{ + protected static final HashSet<String> BLACKLIST_TYPES = new HashSet<String>(Arrays.asList(new String[]{ plasmaURLPattern.BLACKLIST_CRAWLER, plasmaURLPattern.BLACKLIST_PROXY, plasmaURLPattern.BLACKLIST_DHT, @@ -72,8 +72,8 @@ public static final String BLACKLIST_TYPES_STRING="proxy,crawler,dht,search,surftips,news"; protected File blacklistRootPath = null; - protected HashMap cachedUrlHashs = null; - protected HashMap /* <blacklistType,HashMap<host,ArrayList<path>>> */ hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here + protected HashMap<String, Set<String>> cachedUrlHashs = null; + protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here public abstractURLPattern(File rootPath) { this.setRootPath(rootPath); @@ -81,14 +81,14 @@ this.blacklistRootPath = rootPath; // prepare the data structure - this.hostpaths = new HashMap(); - this.cachedUrlHashs = new HashMap(); + this.hostpaths = new HashMap<String, HashMap<String, ArrayList<String>>>(); + this.cachedUrlHashs = new HashMap<String, Set<String>>(); - Iterator iter = BLACKLIST_TYPES.iterator(); + Iterator<String> iter = BLACKLIST_TYPES.iterator(); while (iter.hasNext()) { String blacklistType = (String) iter.next(); - this.hostpaths.put(blacklistType, new HashMap()); - this.cachedUrlHashs.put(blacklistType, Collections.synchronizedSet(new HashSet())); + this.hostpaths.put(blacklistType, new HashMap<String, ArrayList<String>>()); + this.cachedUrlHashs.put(blacklistType, Collections.synchronizedSet(new HashSet<String>())); } } @@ -103,39 +103,39 @@ this.blacklistRootPath = rootPath; } - protected HashMap getBlacklistMap(String blacklistType) { + protected HashMap<String, ArrayList<String>> getBlacklistMap(String blacklistType) { if (blacklistType == null) throw new IllegalArgumentException(); if (!BLACKLIST_TYPES.contains(blacklistType)) throw new IllegalArgumentException("Unknown blacklist type: "+blacklistType+"."); - return (HashMap) this.hostpaths.get(blacklistType); + return this.hostpaths.get(blacklistType); } - protected Set getCacheUrlHashsSet(String blacklistType) { + protected Set<String> getCacheUrlHashsSet(String blacklistType) { if (blacklistType == null) throw new IllegalArgumentException(); if (!BLACKLIST_TYPES.contains(blacklistType)) throw new IllegalArgumentException("Unknown backlist type."); - return (Set) this.cachedUrlHashs.get(blacklistType); + return this.cachedUrlHashs.get(blacklistType); } public void clear() { - Iterator iter = this.hostpaths.values().iterator(); - Iterator cIter = this.cachedUrlHashs.values().iterator(); + Iterator<HashMap<String, ArrayList<String>>> iter = this.hostpaths.values().iterator(); + Iterator<Set<String>> cIter = this.cachedUrlHashs.values().iterator(); while (iter.hasNext()) { - ((HashMap) iter.next()).clear(); + iter.next().clear(); } while (cIter.hasNext()) { // clear caches as well to avoid wrong/outdated matches after changing lists - ((Set) cIter.next()).clear(); + cIter.next().clear(); } } public int size() { int size = 0; - Iterator iter = this.hostpaths.keySet().iterator(); + Iterator<String> iter = this.hostpaths.keySet().iterator(); while (iter.hasNext()) { - Iterator blIter = ((HashMap)this.hostpaths.get(iter.next())).values().iterator(); + Iterator<ArrayList<String>> blIter = this.hostpaths.get(iter.next()).values().iterator(); while (blIter.hasNext()) - size += ((ArrayList)blIter.next()).size(); + size += blIter.next().size(); } return size; } @@ -148,10 +148,11 @@ } public void loadList(blacklistFile blFile, String sep) { - HashMap blacklistMap = getBlacklistMap(blFile.getType()); - Set loadedBlacklist; - Map.Entry loadedEntry; - ArrayList paths, loadedPaths; + HashMap<String, ArrayList<String>> blacklistMap = getBlacklistMap(blFile.getType()); + Set<Map.Entry<String, ArrayList<String>>> loadedBlacklist; + Map.Entry<String, ArrayList<String>> loadedEntry; + ArrayList<String> paths; + ArrayList<String> loadedPaths; String[] fileNames = blFile.getFileNamesUnified(); if (fileNames.length > 0) { @@ -164,13 +165,13 @@ // join all blacklists from files into one internal blacklist map loadedBlacklist = kelondroMSetTools.loadMapMultiValsPerKey(file.toString(), sep).entrySet(); - for (Iterator mi = loadedBlacklist.iterator(); mi.hasNext(); ) { - loadedEntry = (Map.Entry) mi.next(); - loadedPaths = (ArrayList) loadedEntry.getValue(); + for (Iterator<Map.Entry<String, ArrayList<String>>> mi = loadedBlacklist.iterator(); mi.hasNext(); ) { + loadedEntry = mi.next(); + loadedPaths = loadedEntry.getValue(); // create new entry if host mask unknown, otherwise merge // existing one with path patterns from blacklist file - paths = (ArrayList) blacklistMap.get(loadedEntry.getKey()); + paths = blacklistMap.get(loadedEntry.getKey()); if (paths == null) { blacklistMap.put(loadedEntry.getKey(), loadedPaths); } else { @@ -190,13 +191,13 @@ } public void removeAll(String blacklistType, String host) { - HashMap blacklistMap = getBlacklistMap(blacklistType); + HashMap<String, ArrayList<String>> blacklistMap = getBlacklistMap(blacklistType); blacklistMap.remove(host); } public void remove(String blacklistType, String host, String path) { - HashMap blacklistMap = getBlacklistMap(blacklistType); - ArrayList hostList = (ArrayList)blacklistMap.get(host); + HashMap<String, ArrayList<String>> blacklistMap = getBlacklistMap(blacklistType); + ArrayList<String> hostList = blacklistMap.get(host); hostList.remove(path); if (hostList.size() == 0) blacklistMap.remove(host); @@ -208,31 +209,30 @@ if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1); - HashMap blacklistMap = getBlacklistMap(blacklistType); - ArrayList hostList = (ArrayList)blacklistMap.get(host.toLowerCase()); - if (hostList == null) - blacklistMap.put(host.toLowerCase(), (hostList = new ArrayList())); + HashMap<String, ArrayList<String>> blacklistMap = getBlacklistMap(blacklistType); + ArrayList<String> hostList = blacklistMap.get(host.toLowerCase()); + if (hostList == null) blacklistMap.put(host.toLowerCase(), (hostList = new ArrayList<String>())); hostList.add(path); } public int blacklistCacheSize() { int size = 0; - Iterator iter = this.cachedUrlHashs.keySet().iterator(); + Iterator<String> iter = this.cachedUrlHashs.keySet().iterator(); while (iter.hasNext()) { - Set blacklistMap = (Set) this.cachedUrlHashs.get(iter.next()); + Set<String> blacklistMap = this.cachedUrlHashs.get(iter.next()); size += blacklistMap.size(); } return size; } public boolean hashInBlacklistedCache(String blacklistType, String urlHash) { - Set urlHashCache = getCacheUrlHashsSet(blacklistType); + Set<String> urlHashCache = getCacheUrlHashsSet(blacklistType); return urlHashCache.contains(urlHash); } public boolean isListed(String blacklistType, yacyURL url) { - Set urlHashCache = getCacheUrlHashsSet(blacklistType); + Set<String> urlHashCache = getCacheUrlHashsSet(blacklistType); if (!urlHashCache.contains(url.hash())) { boolean temp = isListed(blacklistType, url.getHost().toLowerCase(), url.getFile()); if (temp) { Modified: trunk/source/de/anomic/plasma/urlPattern/defaultURLPattern.java =================================================================== --- trunk/source/de/anomic/plasma/urlPattern/defaultURLPattern.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/plasma/urlPattern/defaultURLPattern.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -65,10 +65,10 @@ if (path == null) throw new NullPointerException(); // getting the proper blacklist - HashMap blacklistMap = super.getBlacklistMap(blacklistType); + HashMap<String, ArrayList<String>> blacklistMap = super.getBlacklistMap(blacklistType); if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1); - ArrayList app; + ArrayList<String> app; boolean matched = false; String pp = ""; // path-pattern @@ -76,7 +76,7 @@ // [TL] While "." are found within the string int index = 0; while (!matched && (index = hostlow.indexOf('.', index + 1)) != -1) { - if ((app = (ArrayList) blacklistMap.get(hostlow.substring(0, index + 1) + "*")) != null) { + if ((app = blacklistMap.get(hostlow.substring(0, index + 1) + "*")) != null) { for (int i=app.size()-1; !matched && i>-1; i--) { pp = (String)app.get(i); matched |= ((pp.equals("*")) || (path.matches(pp))); @@ -85,7 +85,7 @@ } index = hostlow.length(); while (!matched && (index = hostlow.lastIndexOf('.', index - 1)) != -1) { - if ((app = (ArrayList) blacklistMap.get("*" + hostlow.substring(index, hostlow.length()))) != null) { + if ((app = blacklistMap.get("*" + hostlow.substring(index, hostlow.length()))) != null) { for (int i=app.size()-1; !matched && i>-1; i--) { pp = (String)app.get(i); matched |= ((pp.equals("*")) || (path.matches(pp))); @@ -94,7 +94,7 @@ } // try to match without wildcard in domain - if (!matched && (app = (ArrayList)blacklistMap.get(hostlow)) != null) { + if (!matched && (app = blacklistMap.get(hostlow)) != null) { for (int i=app.size()-1; !matched && i>-1; i--) { pp = (String)app.get(i); matched |= ((pp.equals("*")) || (path.matches(pp))); Modified: trunk/source/de/anomic/plasma/urlPattern/plasmaURLPattern.java =================================================================== --- trunk/source/de/anomic/plasma/urlPattern/plasmaURLPattern.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/plasma/urlPattern/plasmaURLPattern.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -35,7 +35,7 @@ * @return unified String array of file names */ public String[] getFileNamesUnified() { - HashSet hs = new HashSet(Arrays.asList(this.filename.split(","))); + HashSet<String> hs = new HashSet<String>(Arrays.asList(this.filename.split(","))); return (String[]) hs.toArray(new String[hs.size()]); } Modified: trunk/source/de/anomic/server/logging/ConsoleOutErrHandler.java =================================================================== --- trunk/source/de/anomic/server/logging/ConsoleOutErrHandler.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/server/logging/ConsoleOutErrHandler.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -115,7 +115,7 @@ Filter f = null; try { - Class c = Class.forName(name); + Class<?> c = Class.forName(name); f = (Filter)c.newInstance(); } catch (Exception e) { if (name != null) { @@ -130,7 +130,7 @@ Formatter f = null; try { - Class c = Class.forName(name); + Class<?> c = Class.forName(name); f = (Formatter)c.newInstance(); } catch (Exception e) { f = new SimpleFormatter(); Modified: trunk/source/de/anomic/server/logging/GuiHandler.java =================================================================== --- trunk/source/de/anomic/server/logging/GuiHandler.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/server/logging/GuiHandler.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -103,7 +103,7 @@ Filter f = null; try { - Class c = Class.forName(name); + Class<?> c = Class.forName(name); f = (Filter)c.newInstance(); } catch (Exception e) { System.err.println("Unable to load filter: " + name); @@ -116,7 +116,7 @@ Formatter f = null; try { - Class c = Class.forName(name); + Class<?> c = Class.forName(name); f = (Formatter)c.newInstance(); } catch (Exception e) { f = new SimpleFormatter(); @@ -154,7 +154,7 @@ public synchronized LogRecord[] getLogArray(Long sequenceNumberStart) { - ArrayList tempBuffer = new ArrayList(this.count); + ArrayList<LogRecord> tempBuffer = new ArrayList<LogRecord>(this.count); for (int i = 0; i < this.count; i++) { int ix = (this.start+i)%this.buffer.length; @@ -197,7 +197,7 @@ if ((lineCount > this.count)||(lineCount < 0)) lineCount = this.count; - ArrayList logMessages = new ArrayList(this.count); + ArrayList<String> logMessages = new ArrayList<String>(this.count); Formatter logFormatter = getFormatter(); try { Modified: trunk/source/de/anomic/server/logging/LogalizerHandler.java =================================================================== --- trunk/source/de/anomic/server/logging/LogalizerHandler.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/server/logging/LogalizerHandler.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -64,15 +64,15 @@ public static boolean enabled=false; public static boolean debug=false; private String logParserPackage; - private HashMap parsers; + private HashMap<String, Object> parsers; public LogalizerHandler() { super(); configure(); } - private HashMap loadParsers() { - HashMap parsers = new HashMap(); + private HashMap<String, Object> loadParsers() { + HashMap<String, Object> parsers = new HashMap<String, Object>(); try { if (debug) System.out.println("Searching for additional content parsers in package " + logParserPackage); // getting an uri to the parser subpackage @@ -88,7 +88,7 @@ //System.out.println(parserDirFiles.length); for (int i=0; i<parserDirFiles.length; i++) { String tmp = parserDirFiles[i].substring(0,parserDirFiles[i].indexOf(".class")); - Class tempClass = Class.forName(logParserPackage+"."+tmp); + Class<?> tempClass = Class.forName(logParserPackage+"."+tmp); if (tempClass.isInterface()) { if (debug) System.out.println(tempClass.getName() + " is an Interface"); } else { @@ -145,18 +145,18 @@ } } - public Set getParserNames() { + public Set<String> getParserNames() { return parsers.keySet(); } public LogParser getParser(int number) { - Object o; - Iterator it = parsers.keySet().iterator(); + String o; + Iterator<String> it = parsers.keySet().iterator(); int i = 0; while (it.hasNext()) { o = it.next(); if (i++ == number) - return (LogParser)parsers.get(o); + return (LogParser) parsers.get(o); } return null; } Modified: trunk/source/de/anomic/server/logging/logParsers/LogParserPLASMA.java =================================================================== --- trunk/source/de/anomic/server/logging/logParsers/LogParserPLASMA.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/server/logging/logParsers/LogParserPLASMA.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -220,10 +220,10 @@ private long DHTSendTraffic=0; private int DHTSendURLs=0; private int RWIRejectCount=0; - private HashSet RWIRejectPeerNames = new HashSet(); - private HashSet RWIRejectPeerHashs = new HashSet(); - private HashSet DHTPeerNames = new HashSet(); - private HashSet DHTPeerHashs = new HashSet(); + private HashSet<String> RWIRejectPeerNames = new HashSet<String>(); + private HashSet<String> RWIRejectPeerHashs = new HashSet<String>(); + private HashSet<String> DHTPeerNames = new HashSet<String>(); + private HashSet<String> DHTPeerHashs = new HashSet<String>(); private int DHTSelectionTargetCount = 0; private int DHTSelectionWordsCount = 0; private int DHTSelectionWordsTimeCount = 0; @@ -440,8 +440,8 @@ return -1; } - public Hashtable getResults() { - Hashtable results = new Hashtable(); + public Hashtable<String, Object> getResults() { + Hashtable<String, Object> results = new Hashtable<String, Object>(); results.put(PARSER_VERSION , new Double(parserVersion)); results.put(URLS_RECEIVED , new Integer(urlSum)); results.put(URLS_REQUESTED , new Integer(urlReqSum)); Modified: trunk/source/de/anomic/yacy/yacyNewsPool.java =================================================================== --- trunk/source/de/anomic/yacy/yacyNewsPool.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/yacy/yacyNewsPool.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -254,9 +254,9 @@ CATEGORY_BLOG_ADD, CATEGORY_BLOG_DEL }; - public static HashSet categories; + public static HashSet<String> categories; static { - categories = new HashSet(); + categories = new HashSet<String>(); for (int i = 0; i < category.length; i++) categories.add(category[i]); } @@ -286,7 +286,7 @@ return newsDB.size(); } - public Iterator recordIterator(int dbKey, boolean up) { + public Iterator<yacyNewsRecord> recordIterator(int dbKey, boolean up) { // returns an iterator of yacyNewsRecord-type objects yacyNewsQueue queue = switchQueue(dbKey); return queue.records(up); @@ -323,15 +323,15 @@ if (record.category() == null) return; if (!(categories.contains(record.category()))) return; if (record.created().getTime() == 0) return; - Map attributes = record.attributes(); + Map<String, String> attributes = record.attributes(); if (attributes.containsKey("url")){ - if(plasmaSwitchboard.urlBlacklist.isListed(plasmaURLPattern.BLACKLIST_NEWS, new yacyURL((String) attributes.get("url"), null))){ + if (plasmaSwitchboard.urlBlacklist.isListed(plasmaURLPattern.BLACKLIST_NEWS, new yacyURL((String) attributes.get("url"), null))){ System.out.println("DEBUG: ignored news-entry url blacklisted: " + attributes.get("url")); return; } } if (attributes.containsKey("startURL")){ - if(plasmaSwitchboard.urlBlacklist.isListed(plasmaURLPattern.BLACKLIST_NEWS, new yacyURL((String) attributes.get("startURL"), null))){ + if (plasmaSwitchboard.urlBlacklist.isListed(plasmaURLPattern.BLACKLIST_NEWS, new yacyURL((String) attributes.get("startURL"), null))){ System.out.println("DEBUG: ignored news-entry url blacklisted: " + attributes.get("startURL")); return; } @@ -352,7 +352,7 @@ yacyNewsRecord record; int pc = 0; synchronized (this.incomingNews) { - Iterator i = incomingNews.records(true); + Iterator<yacyNewsRecord> i = incomingNews.records(true); while (i.hasNext()) { // check for interruption if (Thread.currentThread().isInterrupted()) throw new InterruptedException("Shutdown in progress"); @@ -406,9 +406,9 @@ yacyNewsQueue queue = switchQueue(dbKey); yacyNewsRecord record; String s; - Iterator i = queue.records(true); + Iterator<yacyNewsRecord> i = queue.records(true); while (i.hasNext()) { - record = (yacyNewsRecord) i.next(); + record = i.next(); if ((record != null) && (record.category().equals(category))) { s = (String) record.attributes().get(key); if ((s != null) && (s.equals(value))) return record; @@ -420,9 +420,9 @@ public synchronized yacyNewsRecord getByOriginator(int dbKey, String category, String originatorHash) { yacyNewsQueue queue = switchQueue(dbKey); yacyNewsRecord record; - Iterator i = queue.records(true); + Iterator<yacyNewsRecord> i = queue.records(true); while (i.hasNext()) { - record = (yacyNewsRecord) i.next(); + record = i.next(); if ((record != null) && (record.category().equals(category)) && (record.originator().equals(originatorHash))) { @@ -500,7 +500,7 @@ private int moveOffAll(yacyNewsQueue fromqueue, yacyNewsQueue toqueue) throws IOException { // move off all news from a specific queue to another queue - Iterator i = fromqueue.records(true); + Iterator<yacyNewsRecord> i = fromqueue.records(true); yacyNewsRecord record; if (toqueue == null) return 0; int c = 0; Modified: trunk/source/de/anomic/yacy/yacyNewsQueue.java =================================================================== --- trunk/source/de/anomic/yacy/yacyNewsQueue.java 2008-01-23 22:19:23 UTC (rev 4381) +++ trunk/source/de/anomic/yacy/yacyNewsQueue.java 2008-01-23 23:08:32 UTC (rev 4382) @@ -123,9 +123,9 @@ public synchronized yacyNewsRecord get(String id) { yacyNewsRecord record; - Iterator i = records(true); + Iterator<yacyNewsRecord> i = records(true); while (i.hasNext()) { - record = (yacyNewsRecord) i.next(); + record = i.next(); if ((record != null) && (record.id().equals(id))) return record; } return null; @@ -133,9 +133,9 @@ public synchronized yacyNewsRecord remove(String id) { yacyNewsRecord record; - Iterator i = records(true); + Iterator<yacyNewsRecord> i = records(true); while (i.hasNext()) { - record = (yacyNewsRecord) i.next(); + record = i.next(); if ((record != null) && (record.id().equals(id))) { i.remove(); return record; @@ -165,15 +165,15 @@ return b; } - public Iterator records(boolean up) { + public Iterator<yacyNewsRecord> records(boolean up) { // iterates yacyNewsRecord-type objects return new newsIterator(up); } - public class newsIterator implements Iterator { + public class newsIterator implements Iterator<yacyNewsRecord> { // iterates yacyNewsRecord-type objects - Iterator stackNodeIterator; + Iterator<kelondroRow.Entry> stackNodeIterator; public newsIterator(boolean up) { stackNodeIterator = queueStack.stackIterator(up); @@ -183,7 +183,7 @@ return stackNodeIterator.hasNext(); } - public Object next() { + public yacyNewsRecord next() { kelondroRow.Entry row = (kelondroRow.Entry) stackNodeIterator.next(); try { return b2r(row); _______________________________________________ YaCy-svn mailing list YaCy-svn@lists.berlios.de https://lists.berlios.de/mailman/listinfo/yacy-svn