more generics

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4379 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent 6dc679785f
commit 4e70dff8cf

@ -1,13 +1,15 @@
// dir.java
// -----------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004, 2005
// (C) 2004, 2005 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 2004 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
@ -21,30 +23,6 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
//
// You must compile this file with
// javac -classpath <application_root>/classes <application_root>/htroot/htdocsdefault/dir.java
// which most probably means to compile this with
// javac -classpath ../../classes dir.java
import java.io.ByteArrayInputStream;
import java.io.File;
@ -53,6 +31,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
@ -74,7 +53,6 @@ import de.anomic.server.serverMemory;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog;
import de.anomic.tools.dirlistComparator;
import de.anomic.tools.md5DirFileFilter;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;
@ -233,7 +211,7 @@ public class dir {
// sorting the dir list
dirlistComparator comparator = new dirlistComparator();
Arrays.sort(list,comparator);
Arrays.sort(list, comparator);
String md5s, description;
// tree += "<span class=\"tt\">path&nbsp;=&nbsp;" + path + "</span><br><br>";
@ -399,10 +377,10 @@ public class dir {
public static void deletePhrase(plasmaSwitchboard switchboard, String urlstring, String phrase, String descr) {
try {
final String urlhash = (new yacyURL(urlstring, null)).hash();
final Iterator words = plasmaCondenser.getWords(("yacyshare " + phrase + " " + descr).getBytes("UTF-8"), "UTF-8").keySet().iterator();
final Iterator<String> words = plasmaCondenser.getWords(("yacyshare " + phrase + " " + descr).getBytes("UTF-8"), "UTF-8").keySet().iterator();
String word;
while (words.hasNext()) {
word = (String) words.next();
word = words.next();
switchboard.wordIndex.removeEntry(plasmaCondenser.word2hash(word), urlhash);
}
switchboard.wordIndex.loadedURL.remove(urlhash);
@ -411,4 +389,17 @@ public class dir {
}
}
public static class dirlistComparator implements Comparator<File> {
public int compare(File file1, File file2) {
if (file1.isDirectory() && !file2.isDirectory()) {
return -1;
} else if (!file1.isDirectory() && file2.isDirectory()) {
return 1;
} else {
return file1.getName().compareToIgnoreCase(file2.getName());
}
}
}
}

@ -80,14 +80,13 @@ public class PKCS12Tool {
fileIn.close();
}
public Enumeration aliases() throws KeyStoreException {
Enumeration aliases = this.kspkcs12.aliases();
return aliases;
public Enumeration<String> aliases() throws KeyStoreException {
return this.kspkcs12.aliases();
}
public void printAliases() throws KeyStoreException {
Enumeration aliases = aliases();
while(aliases.hasMoreElements()) {
Enumeration<String> aliases = aliases();
while (aliases.hasMoreElements()) {
System.out.println(aliases.nextElement());
}
}
@ -109,7 +108,7 @@ public class PKCS12Tool {
jks.load(jksFileIn,(jksPassword!=null)?jksPassword.toCharArray():null);
if (jksFileIn != null) jksFileIn.close();
Enumeration pkcs12Aliases = aliases();
Enumeration<String> pkcs12Aliases = aliases();
while (pkcs12Aliases.hasMoreElements()) {
String strAlias = (String)pkcs12Aliases.nextElement();
System.err.println("Importing Alias '" + strAlias + "'");

@ -194,15 +194,15 @@ public class cryptbig {
// This method returns the available implementations for a service type
public static Set listCryptoMethods(String serviceType) {
Set result = new HashSet();
public static Set<String> listCryptoMethods(String serviceType) {
Set<String> result = new HashSet<String>();
// All providers
Provider[] providers = Security.getProviders();
for (int i = 0; i < providers.length; i++) {
// Get services provided by each provider
Set keys = providers[i].keySet();
for (Iterator it = keys.iterator(); it.hasNext(); ) {
Set<?> keys = providers[i].keySet();
for (Iterator<?> it = keys.iterator(); it.hasNext(); ) {
String key = (String) it.next();
key = key.split(" ")[0];
if (key.startsWith(serviceType + ".")) {
@ -216,9 +216,9 @@ public class cryptbig {
return result;
}
public static void testCryptMethods(Set methods) {
public static void testCryptMethods(Set<String> methods) {
String method;
Iterator i = methods.iterator();
Iterator<String> i = methods.iterator();
while (i.hasNext()) {
method = (String) i.next();
System.out.print(method + " : ");
@ -569,7 +569,7 @@ public class cryptbig {
}
if (s[0].equals("-tc")) {
// list all available crypt mehtods:
Set methods = listCryptoMethods("Cipher");
Set<String> methods = listCryptoMethods("Cipher");
System.out.println(methods.size() + " crypt methods:" + methods.toString());
testCryptMethods(methods);
System.exit(0);

@ -1,68 +0,0 @@
package de.anomic.tools;
// dirlistComparator.java
// -----------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004, 2005
//
// This file is contributed by Martin Thelian
//
// $LastChangedDate: 2006-08-06 10:09:39 +0200 (So, 06 Aug 2006) $
// $LastChangedRevision: 2349 $
// $LastChangedBy: theli $
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
import java.io.File;
import java.util.Comparator;
public class dirlistComparator implements Comparator {
public int compare(Object obj1, Object obj2) {
if (!(obj1 instanceof File)) throw new IllegalArgumentException();
if (!(obj2 instanceof File)) throw new IllegalArgumentException();
File file1 = (File)obj1;
File file2 = (File)obj2;
if (file1.isDirectory() && !file2.isDirectory()) {
return -1;
} else if (!file1.isDirectory() && file2.isDirectory()) {
return 1;
} else {
return file1.getName().compareToIgnoreCase(file2.getName());
}
}
}

@ -45,51 +45,51 @@ import java.util.LinkedList;
public class disorderHeap {
LinkedList list;
LinkedList<String> list;
public disorderHeap() {
list = new LinkedList();
list = new LinkedList<String>();
}
public disorderHeap(int numbers) {
// create a disorder heap with numbers in it
// the numbers are 0..numbers-1
this();
for (int i = 0; i < numbers; i++) add(Integer.toString(i));
// create a disorder heap with numbers in it
// the numbers are 0..numbers-1
this();
for (int i = 0; i < numbers; i++) add(Integer.toString(i));
}
public synchronized void add(Object element) {
// add one element into the list at an arbitrary position
int pos = (int) ((System.currentTimeMillis() / 7) % (list.size() + 1));
list.add(pos, element);
public synchronized void add(String element) {
// add one element into the list at an arbitrary position
int pos = (int) ((System.currentTimeMillis() / 7) % (list.size() + 1));
list.add(pos, element);
}
public synchronized Object remove() {
if (list.size() == 0) return null;
int pos = (int) ((System.currentTimeMillis() / 13) % list.size());
return list.remove(pos);
public synchronized String remove() {
if (list.size() == 0) return null;
int pos = (int) ((System.currentTimeMillis() / 13) % list.size());
return list.remove(pos);
}
public synchronized int number() {
String n = (String) this.remove();
if (n == null) return -1;
try {
return Integer.parseInt(n);
} catch (Exception e) {
return -1;
}
String n = this.remove();
if (n == null) return -1;
try {
return Integer.parseInt(n);
} catch (Exception e) {
return -1;
}
}
public synchronized int size() {
return list.size();
return list.size();
}
public static void main(String[] args) {
disorderHeap ul = new disorderHeap();
for (int i = 0; i < args.length; i++) ul.add(args[i]);
for (int i = 0; i < args.length; i++) System.out.print((String) ul.remove() + " ");
System.out.println();
disorderHeap ul = new disorderHeap();
for (int i = 0; i < args.length; i++) ul.add(args[i]);
for (int i = 0; i < args.length; i++) System.out.print(ul.remove() + " ");
System.out.println();
}
}

@ -38,44 +38,43 @@
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
package de.anomic.tools;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class disorderSet extends HashSet implements Set {
public class disorderSet extends HashSet<String> implements Set<String> {
private static final long serialVersionUID = 1L;
disorderHeap dh;
disorderHeap dh;
public disorderSet() {
super();
dh = null;
super();
dh = null;
}
public boolean hasAny() {
return (this.size() > 0);
return (this.size() > 0);
}
public Object any() {
// return just any element
if ((dh == null) || (dh.size() == 0)) {
if (this.size() == 0) return null;
// fill up the queue
dh = new disorderHeap();
Iterator elements = this.iterator();
while (elements.hasNext()) dh.add(elements.next());
}
return dh.remove();
// return just any element
if ((dh == null) || (dh.size() == 0)) {
if (this.size() == 0) return null;
// fill up the queue
dh = new disorderHeap();
Iterator<String> elements = this.iterator();
while (elements.hasNext()) dh.add(elements.next());
}
return dh.remove();
}
public static void main(String[] args) {
disorderSet ds = new disorderSet();
for (int i = 0; i < args.length; i++) ds.add(args[i]);
for (int i = 0; i < args.length * 3; i++) System.out.print((String) ds.any() + " ");
System.out.println();
disorderSet ds = new disorderSet();
for (int i = 0; i < args.length; i++) ds.add(args[i]);
for (int i = 0; i < args.length * 3; i++) System.out.print((String) ds.any() + " ");
System.out.println();
}
}

@ -45,14 +45,14 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.TreeSet;
public class enumerateFiles implements Enumeration {
public class enumerateFiles implements Enumeration<File> {
// implements iterative search through recursively defined subdirectories
// and return all paths to the files
private ArrayList hierarchy; // contains TreeSet elements, each TreeSet contains File Entries
private ArrayList<TreeSet<File>> hierarchy; // contains TreeSet elements, each TreeSet contains File Entries
private boolean incOrder; // if true, the smallest value is returned first
private Object buffer; // the prefetch-buffer
private File buffer; // the prefetch-buffer
private boolean return_files;
private boolean return_folders;
private boolean delete_emptyFolders;
@ -62,10 +62,10 @@ public class enumerateFiles implements Enumeration {
this.return_files = files;
this.return_folders = folders;
this.delete_emptyFolders = deleteEmptyFolders;
this.hierarchy = new ArrayList();
this.hierarchy = new ArrayList<TreeSet<File>>();
this.incOrder = increasing;
// the we initially fill the hierarchy with the content of the root folder
TreeSet t = new TreeSet();
TreeSet<File> t = new TreeSet<File>();
String[] l = root.list();
// System.out.println("D " + l.toString());
if (l != null) for (int i = 0; i < l.length; i++) t.add(new File(root, l[i]));
@ -74,15 +74,15 @@ public class enumerateFiles implements Enumeration {
this.buffer = nextElement0();
}
private Object nextElement0() {
private File nextElement0() {
// the object is a File pointing to the corresponding file
File f;
TreeSet t;
TreeSet<File> t;
do {
// System.out.println("D " + hierarchy.toString());
t = null;
while ((t == null) && (hierarchy.size() > 0)) {
t = (TreeSet) hierarchy.get(hierarchy.size() - 1);
t = hierarchy.get(hierarchy.size() - 1);
if (t.size() == 0) {
hierarchy.remove(hierarchy.size() - 1); // we step up one hierarchy
t = null;
@ -94,7 +94,7 @@ public class enumerateFiles implements Enumeration {
t.remove(f);
// if the value represents another folder, we step into the next hierarchy
if (f.isDirectory()) {
t = new TreeSet();
t = new TreeSet<File>();
String[] l = f.list();
if (l == null) {
// f has disappeared
@ -125,8 +125,8 @@ public class enumerateFiles implements Enumeration {
return buffer != null;
}
public Object nextElement() {
Object r = buffer;
public File nextElement() {
File r = buffer;
buffer = nextElement0();
return r;
}

@ -57,7 +57,7 @@ public class loaderThreads {
protected httpRemoteProxyConfig remoteProxyConfig;
// management objects for collection of threads
Hashtable threads;
Hashtable<String, Thread> threads;
int completed, failed;
public loaderThreads() {
@ -78,7 +78,7 @@ public class loaderThreads {
this.user = user;
this.password = password;
this.remoteProxyConfig = theremoteProxyConfig;
this.threads = new Hashtable();
this.threads = new Hashtable<String, Thread>();
this.completed = 0;
this.failed = 0;
}
@ -199,7 +199,7 @@ public class loaderThreads {
int line = 0;
String s, key, value;
int p;
ArrayList lines = nxTools.strings(v);
ArrayList<String> lines = nxTools.strings(v);
try {
while ((this.run) && (line < lines.size())) {
// parse line and construct a property

@ -54,7 +54,7 @@ public class crawlHandler extends DefaultHandler {
"docs" //
};
private static final HashSet startpointTagsSet = new HashSet();
private static final HashSet<String> startpointTagsSet = new HashSet<String>();
static {
for (int i = 0; i < startpointTags.length; i++) {
startpointTagsSet.add(startpointTags[i]);
@ -65,8 +65,8 @@ public class crawlHandler extends DefaultHandler {
private Startpoint channel, startpoint;
private StringBuffer buffer;
private boolean parsingAttributes, parsingStartpoint;
private ArrayList startpointsGUID; // a list of GUIDs, so the items can be retrieved by a specific order
private HashMap startpoints; // a guid:Item map
private ArrayList<String> startpointsGUID; // a list of GUIDs, so the items can be retrieved by a specific order
private HashMap<String, Startpoint> startpoints; // a guid:Item map
public crawlHandler(String path) {
@ -80,8 +80,8 @@ public class crawlHandler extends DefaultHandler {
}
private void init() {
startpointsGUID = new ArrayList();
startpoints = new HashMap();
startpointsGUID = new ArrayList<String>();
startpoints = new HashMap<String, Startpoint>();
buffer = new StringBuffer();
startpoint = null;
channel = null;
@ -165,10 +165,10 @@ public class crawlHandler extends DefaultHandler {
public static class Attributes {
private HashMap map;
private HashMap<String, String> map;
public Attributes() {
this.map = new HashMap();
this.map = new HashMap<String, String>();
}
public void setValue(String name, String value) {
@ -222,10 +222,10 @@ public class crawlHandler extends DefaultHandler {
public static class Startpoint {
private HashMap map;
private HashMap<String, String> map;
public Startpoint() {
this.map = new HashMap();
this.map = new HashMap<String, String>();
this.map.put("guid", Long.toHexString(System.currentTimeMillis()) + ":" + guidcount++);
}

@ -62,7 +62,7 @@ public class rssReader extends DefaultHandler {
"docs" //
};
private static final HashSet tags = new HashSet();
private static final HashSet<String> tags = new HashSet<String>();
static {
for (int i = 0; i < tagsDef.length; i++) {
tags.add(tagsDef[i]);
@ -74,13 +74,13 @@ public class rssReader extends DefaultHandler {
private StringBuffer buffer;
private boolean parsingChannel, parsingImage, parsingItem;
private String imageURL;
private ArrayList itemsGUID; // a list of GUIDs, so the items can be retrieved by a specific order
private HashMap items; // a guid:Item map
private ArrayList<String> itemsGUID; // a list of GUIDs, so the items can be retrieved by a specific order
private HashMap<String, Item> items; // a guid:Item map
public rssReader() {
itemsGUID = new ArrayList();
items = new HashMap();
itemsGUID = new ArrayList<String>();
items = new HashMap<String, Item>();
buffer = new StringBuffer();
item = null;
channel = null;
@ -215,10 +215,10 @@ public class rssReader extends DefaultHandler {
public static class Item {
private HashMap map;
private HashMap<String, String> map;
public Item() {
this.map = new HashMap();
this.map = new HashMap<String, String>();
this.map.put("guid", Long.toHexString(System.currentTimeMillis()) + ":" + guidcount++);
}

Loading…
Cancel
Save