Author: j16sdiz
Date: 2008-12-18 06:17:11 +0000 (Thu, 18 Dec 2008)
New Revision: 24512
Added:
trunk/plugins/XMLSpider/MaxPageId.java
trunk/plugins/XMLSpider/Page.java
trunk/plugins/XMLSpider/Status.java
trunk/plugins/XMLSpider/Term.java
trunk/plugins/XMLSpider/TermPosition.java
Log:
move inner static class to top-level
Added: trunk/plugins/XMLSpider/MaxPageId.java
===================================================================
--- trunk/plugins/XMLSpider/MaxPageId.java (rev 0)
+++ trunk/plugins/XMLSpider/MaxPageId.java 2008-12-18 06:17:11 UTC (rev
24512)
@@ -0,0 +1,19 @@
+/**
+ * @author j16sdiz (1024D/75494252)
+ */
+package plugins.XMLSpider;
+
+class MaxPageId {
+ volatile long v;
+
+ MaxPageId() {
+ }
+
+ MaxPageId(long v) {
+ this.v = v;
+ }
+
+ synchronized long incrementAndGet() {
+ return ++v;
+ }
+}
\ No newline at end of file
Added: trunk/plugins/XMLSpider/Page.java
===================================================================
--- trunk/plugins/XMLSpider/Page.java (rev 0)
+++ trunk/plugins/XMLSpider/Page.java 2008-12-18 06:17:11 UTC (rev 24512)
@@ -0,0 +1,45 @@
+/**
+ * @author j16sdiz (1024D/75494252)
+ */
+package plugins.XMLSpider;
+
+class Page {
+ /** Page Id */
+ long id;
+ /** URI of the page */
+ String uri;
+ /** Title */
+ String pageTitle;
+ /** Status */
+ Status status = Status.QUEUED;
+ /** Last Change Time */
+ long lastChange = System.currentTimeMillis();
+ /** Comment, for debugging */
+ String comment;
+
+ public Page() {} // for db4o callConstructors(true)
+
+ @Override
+ public int hashCode() {
+ return (int) (id ^ (id >>> 32));
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ return id == ((Page) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "[PAGE: id=" + id + ", title=" + pageTitle + ", uri=" +
uri + ", status=" + status + ", comment="
+ + comment
+ + "]";
+ }
+}
\ No newline at end of file
Added: trunk/plugins/XMLSpider/Status.java
===================================================================
--- trunk/plugins/XMLSpider/Status.java (rev 0)
+++ trunk/plugins/XMLSpider/Status.java 2008-12-18 06:17:11 UTC (rev 24512)
@@ -0,0 +1,9 @@
+/**
+ * @author j16sdiz (1024D/75494252)
+ */
+package plugins.XMLSpider;
+
+enum Status {
+ /** For simplicity, running is also mark as QUEUED */
+ QUEUED, SUCCEEDED, FAILED
+}
\ No newline at end of file
Added: trunk/plugins/XMLSpider/Term.java
===================================================================
--- trunk/plugins/XMLSpider/Term.java (rev 0)
+++ trunk/plugins/XMLSpider/Term.java 2008-12-18 06:17:11 UTC (rev 24512)
@@ -0,0 +1,57 @@
+/**
+ * @author j16sdiz (1024D/75494252)
+ */
+package plugins.XMLSpider;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+class Term {
+ /** MD5 of the term */
+ String md5;
+ /** Term */
+ String word;
+
+ public Term(String word) {
+ this.word = word;
+ md5 = MD5(word);
+ }
+
+ public Term() {
+ }
+
+ /*
+ * calculate the md5 for a given string
+ */
+ public static String MD5(String text) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ byte[] md5hash = new byte[32];
+ byte[] b = text.getBytes("UTF-8");
+ md.update(b, 0, b.length);
+ md5hash = md.digest();
+ return convertToHex(md5hash);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 not supported", e);
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("MD5 not supported", e);
+ }
+ }
+
+ public static String convertToHex(byte[] data) {
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < data.length; i++) {
+ int halfbyte = (data[i] >>> 4) & 0x0F;
+ int two_halfs = 0;
+ do {
+ if ((0 <= halfbyte) && (halfbyte <= 9))
+ buf.append((char) ('0' + halfbyte));
+ else
+ buf.append((char) ('a' + (halfbyte -
10)));
+ halfbyte = data[i] & 0x0F;
+ } while (two_halfs++ < 1);
+ }
+ return buf.toString();
+ }
+}
\ No newline at end of file
Added: trunk/plugins/XMLSpider/TermPosition.java
===================================================================
--- trunk/plugins/XMLSpider/TermPosition.java (rev 0)
+++ trunk/plugins/XMLSpider/TermPosition.java 2008-12-18 06:17:11 UTC (rev
24512)
@@ -0,0 +1,16 @@
+/**
+ * @author j16sdiz (1024D/75494252)
+ */
+package plugins.XMLSpider;
+
+class TermPosition {
+ /** Term */
+ String word;
+ /** Page id */
+ long pageId;
+ /** Position List */
+ int[] positions;
+
+ public TermPosition() {
+ }
+}
\ No newline at end of file
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs