Skip to content

Commit

Permalink
more generics
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4382 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jan 23, 2008
1 parent 6f9f821 commit db25425
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 84 deletions.
76 changes: 38 additions & 38 deletions source/de/anomic/plasma/urlPattern/abstractURLPattern.java
Expand Up @@ -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,
Expand All @@ -72,23 +72,23 @@ public abstract class abstractURLPattern implements plasmaURLPattern {
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);

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>()));
}
}

Expand All @@ -103,39 +103,39 @@ public void setRootPath(File rootPath) {
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;
}
Expand All @@ -148,10 +148,11 @@ public void loadList(blacklistFile[] blFiles, String sep) {
}

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) {
Expand All @@ -164,13 +165,13 @@ public void loadList(blacklistFile blFile, String sep) {

// 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 {
Expand All @@ -190,13 +191,13 @@ public void loadList(String blacklistType, String fileNames, String sep) {
}

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);
Expand All @@ -208,31 +209,30 @@ public void add(String blacklistType, String host, String path) {

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) {
Expand Down
10 changes: 5 additions & 5 deletions source/de/anomic/plasma/urlPattern/defaultURLPattern.java
Expand Up @@ -65,18 +65,18 @@ public boolean isListed(String blacklistType, String hostlow, String path) {
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

// first try to match the domain with wildcard '*'
// [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)));
Expand All @@ -85,7 +85,7 @@ public boolean isListed(String blacklistType, String hostlow, String path) {
}
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)));
Expand All @@ -94,7 +94,7 @@ public boolean isListed(String blacklistType, String hostlow, String path) {
}

// 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)));
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/plasma/urlPattern/plasmaURLPattern.java
Expand Up @@ -35,7 +35,7 @@ public blacklistFile(String filename, String type) {
* @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()]);
}
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/server/logging/ConsoleOutErrHandler.java
Expand Up @@ -115,7 +115,7 @@ private Filter makeFilter(String name) {

Filter f = null;
try {
Class c = Class.forName(name);
Class<?> c = Class.forName(name);
f = (Filter)c.newInstance();
} catch (Exception e) {
if (name != null) {
Expand All @@ -130,7 +130,7 @@ private Formatter makeFormatter(String name) {

Formatter f = null;
try {
Class c = Class.forName(name);
Class<?> c = Class.forName(name);
f = (Formatter)c.newInstance();
} catch (Exception e) {
f = new SimpleFormatter();
Expand Down
8 changes: 4 additions & 4 deletions source/de/anomic/server/logging/GuiHandler.java
Expand Up @@ -103,7 +103,7 @@ private Filter makeFilter(String name) {

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);
Expand All @@ -116,7 +116,7 @@ private Formatter makeFormatter(String name) {

Formatter f = null;
try {
Class c = Class.forName(name);
Class<?> c = Class.forName(name);
f = (Formatter)c.newInstance();
} catch (Exception e) {
f = new SimpleFormatter();
Expand Down Expand Up @@ -154,7 +154,7 @@ public synchronized LogRecord[] getLogArray() {


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;
Expand Down Expand Up @@ -197,7 +197,7 @@ public synchronized String[] getLogLines(boolean reversed, int lineCount) {

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 {
Expand Down
16 changes: 8 additions & 8 deletions source/de/anomic/server/logging/LogalizerHandler.java
Expand Up @@ -64,15 +64,15 @@ public class LogalizerHandler extends Handler {
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
Expand All @@ -88,7 +88,7 @@ private HashMap loadParsers() {
//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 {
Expand Down Expand Up @@ -145,18 +145,18 @@ public void publish(LogRecord record) {
}
}

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;
}
Expand Down
12 changes: 6 additions & 6 deletions source/de/anomic/server/logging/logParsers/LogParserPLASMA.java
Expand Up @@ -220,10 +220,10 @@ public class LogParserPLASMA implements LogParser{
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;
Expand Down Expand Up @@ -440,8 +440,8 @@ public int parse(String logLevel, String logLine) {
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));
Expand Down

0 comments on commit db25425

Please sign in to comment.