From 15db70380888e5aa54fab03f2046330841989c56 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 15 May 2012 13:13:07 +0200 Subject: [PATCH] added missing serialization to remove all warnings --- .../data/citation/CitationReference.java | 5 +- .../citation/CitationReferenceFactory.java | 6 +- .../data/image/ImageReferenceFactory.java | 13 ++- .../data/image/ImageReferenceVars.java | 8 +- .../NavigationReferenceFactory.java | 15 +++- .../navigation/NavigationReferenceVars.java | 47 +++++++---- .../data/word/WordReferenceFactory.java | 11 ++- source/net/yacy/kelondro/index/Row.java | 9 ++- source/net/yacy/kelondro/order/Bitfield.java | 81 ++++++++++--------- .../yacy/kelondro/rwi/ReferenceContainer.java | 7 ++ .../peers/graphics/WebStructureGraph.java | 11 ++- 11 files changed, 137 insertions(+), 76 deletions(-) diff --git a/source/net/yacy/kelondro/data/citation/CitationReference.java b/source/net/yacy/kelondro/data/citation/CitationReference.java index ce1fb73ce..38e3612e1 100644 --- a/source/net/yacy/kelondro/data/citation/CitationReference.java +++ b/source/net/yacy/kelondro/data/citation/CitationReference.java @@ -20,6 +20,7 @@ package net.yacy.kelondro.data.citation; +import java.io.Serializable; import java.util.Collection; import net.yacy.cora.document.ASCII; @@ -33,10 +34,12 @@ import net.yacy.kelondro.order.MicroDate; import net.yacy.kelondro.rwi.Reference; import net.yacy.kelondro.util.ByteArray; -public class CitationReference implements Reference /*, Cloneable*/ { +public class CitationReference implements Reference, Serializable { // this object stores citation attributes to URL references + private static final long serialVersionUID=1920200210928897131L; + public static final Row citationRow = new Row(new Column[]{ new Column("h", Column.celltype_string, Column.encoder_bytes, Word.commonHashLength, "urlhash"), new Column("m", Column.celltype_cardinal, Column.encoder_b256, 2, "lastModified"), diff --git a/source/net/yacy/kelondro/data/citation/CitationReferenceFactory.java b/source/net/yacy/kelondro/data/citation/CitationReferenceFactory.java index 4fe251ac6..c827a64a8 100644 --- a/source/net/yacy/kelondro/data/citation/CitationReferenceFactory.java +++ b/source/net/yacy/kelondro/data/citation/CitationReferenceFactory.java @@ -20,11 +20,15 @@ package net.yacy.kelondro.data.citation; +import java.io.Serializable; + import net.yacy.kelondro.index.Row; import net.yacy.kelondro.index.Row.Entry; import net.yacy.kelondro.rwi.ReferenceFactory; -public class CitationReferenceFactory implements ReferenceFactory { +public class CitationReferenceFactory implements ReferenceFactory, Serializable { + + private static final long serialVersionUID=-1098504892965986149L; @Override public CitationReference produceSlow(final Entry e) { diff --git a/source/net/yacy/kelondro/data/image/ImageReferenceFactory.java b/source/net/yacy/kelondro/data/image/ImageReferenceFactory.java index 7564f7c67..692912900 100644 --- a/source/net/yacy/kelondro/data/image/ImageReferenceFactory.java +++ b/source/net/yacy/kelondro/data/image/ImageReferenceFactory.java @@ -9,7 +9,7 @@ // $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 @@ -26,21 +26,28 @@ package net.yacy.kelondro.data.image; +import java.io.Serializable; + import net.yacy.kelondro.index.Row; import net.yacy.kelondro.index.Row.Entry; import net.yacy.kelondro.rwi.ReferenceFactory; -public class ImageReferenceFactory implements ReferenceFactory { +public class ImageReferenceFactory implements ReferenceFactory, Serializable { + private static final long serialVersionUID=-2209473508756878863L; + + @Override public ImageReference produceSlow(Entry e) { return null; //new ImageReferenceRow(e); } - + + @Override public ImageReference produceFast(ImageReference r) { if (r instanceof ImageReferenceVars) return r; return new ImageReferenceVars(r); } + @Override public Row getRow() { return ImageReferenceRow.urlEntryRow; } diff --git a/source/net/yacy/kelondro/data/image/ImageReferenceVars.java b/source/net/yacy/kelondro/data/image/ImageReferenceVars.java index 5a75be5a8..e4415f155 100644 --- a/source/net/yacy/kelondro/data/image/ImageReferenceVars.java +++ b/source/net/yacy/kelondro/data/image/ImageReferenceVars.java @@ -26,6 +26,7 @@ package net.yacy.kelondro.data.image; +import java.io.Serializable; import java.util.Collection; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; @@ -38,9 +39,12 @@ import net.yacy.kelondro.rwi.Reference; import net.yacy.kelondro.util.ByteArray; -public class ImageReferenceVars extends AbstractReference implements ImageReference, Reference, Cloneable { +public class ImageReferenceVars extends AbstractReference implements ImageReference, Reference, Cloneable, Serializable { - /** + private static final long serialVersionUID=3669156620967277347L; + + + /** * object for termination of concurrent blocking queue processing */ public static final ImageReferenceVars poison = new ImageReferenceVars(); diff --git a/source/net/yacy/kelondro/data/navigation/NavigationReferenceFactory.java b/source/net/yacy/kelondro/data/navigation/NavigationReferenceFactory.java index 8359dfb1e..e0d3547d2 100644 --- a/source/net/yacy/kelondro/data/navigation/NavigationReferenceFactory.java +++ b/source/net/yacy/kelondro/data/navigation/NavigationReferenceFactory.java @@ -9,7 +9,7 @@ // $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 @@ -26,21 +26,28 @@ package net.yacy.kelondro.data.navigation; +import java.io.Serializable; + import net.yacy.kelondro.index.Row; import net.yacy.kelondro.index.Row.Entry; import net.yacy.kelondro.rwi.ReferenceFactory; -public class NavigationReferenceFactory implements ReferenceFactory { +public class NavigationReferenceFactory implements ReferenceFactory, Serializable { + + private static final long serialVersionUID=-3440570952034279619L; + @Override public NavigationReference produceSlow(final Entry e) { return new NavigationReferenceRow(e); } - + + @Override public NavigationReference produceFast(final NavigationReference r) { if (r instanceof NavigationReferenceVars) return r; return new NavigationReferenceVars(r); } - + + @Override public Row getRow() { return NavigationReferenceRow.navEntryRow; } diff --git a/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java b/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java index d9137db3b..2c90cf8fb 100644 --- a/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java +++ b/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java @@ -9,7 +9,7 @@ // $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 @@ -26,6 +26,7 @@ package net.yacy.kelondro.data.navigation; +import java.io.Serializable; import java.util.Collection; import net.yacy.cora.document.ASCII; @@ -33,12 +34,14 @@ import net.yacy.kelondro.index.Row.Entry; import net.yacy.kelondro.rwi.AbstractReference; import net.yacy.kelondro.rwi.Reference; -public class NavigationReferenceVars extends AbstractReference implements NavigationReference, Reference, Cloneable { +public class NavigationReferenceVars extends AbstractReference implements NavigationReference, Reference, Cloneable, Serializable { + + private static final long serialVersionUID=2873544331190937594L; public byte[] termhash, refhash; public int hitcount, position; byte flags; - + public NavigationReferenceVars( final byte[] termhash, final byte[] refhash, @@ -52,7 +55,7 @@ public class NavigationReferenceVars extends AbstractReference implements Navig this.position = pos; this.flags = flags; } - + public NavigationReferenceVars(final NavigationReference e) { this.refhash = e.urlhash(); this.termhash = e.termHash(); @@ -60,7 +63,7 @@ public class NavigationReferenceVars extends AbstractReference implements Navig this.position = e.position(0); this.flags = e.flags(); } - + @Override public NavigationReferenceVars clone() { final NavigationReferenceVars c = new NavigationReferenceVars( @@ -72,7 +75,7 @@ public class NavigationReferenceVars extends AbstractReference implements Navig ); return c; } - + public NavigationReferenceRow toRowEntry() { return new NavigationReferenceRow( this.termhash, @@ -81,50 +84,58 @@ public class NavigationReferenceVars extends AbstractReference implements Navig this.position, this.flags); } - + + @Override public String toPropertyForm() { return toRowEntry().toPropertyForm(); } + @Override public Entry toKelondroEntry() { return toRowEntry().toKelondroEntry(); } + @Override public String navigationHash() { return ASCII.String(this.termhash) + ASCII.String(this.refhash); } - + + @Override public byte[] urlhash() { return this.refhash; } + @Override public byte[] termHash() { return this.termhash; } - + + @Override public int hitcount() { return this.hitcount; } + @Override public int position(final int p) { assert p == 0 : "p = " + p; return this.position; } - + + @Override public byte flags() { return this.flags; } - + @Override public String toString() { return toPropertyForm(); } - + @Override public int hashCode() { return this.navigationHash().hashCode(); } - + @Override public boolean equals(final Object obj) { if (this == obj) return true; @@ -133,24 +144,28 @@ public class NavigationReferenceVars extends AbstractReference implements Navig NavigationReferenceVars other = (NavigationReferenceVars) obj; return this.navigationHash().equals(other.navigationHash()); } - + + @Override public boolean isOlder(final Reference other) { return false; } - + // unsupported operations: + @Override public void join(final Reference oe) { throw new UnsupportedOperationException(); } + @Override public long lastModified() { throw new UnsupportedOperationException(); } + @Override public Collection positions() { throw new UnsupportedOperationException(); } - + } diff --git a/source/net/yacy/kelondro/data/word/WordReferenceFactory.java b/source/net/yacy/kelondro/data/word/WordReferenceFactory.java index 908355daa..85d57e7d4 100644 --- a/source/net/yacy/kelondro/data/word/WordReferenceFactory.java +++ b/source/net/yacy/kelondro/data/word/WordReferenceFactory.java @@ -9,7 +9,7 @@ // $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 @@ -26,6 +26,7 @@ package net.yacy.kelondro.data.word; +import java.io.Serializable; import java.util.Collections; import java.util.Iterator; import java.util.Map; @@ -39,13 +40,15 @@ import net.yacy.kelondro.rwi.ReferenceContainer; import net.yacy.kelondro.rwi.ReferenceFactory; import net.yacy.kelondro.util.ByteBuffer; -public class WordReferenceFactory implements ReferenceFactory { +public class WordReferenceFactory implements ReferenceFactory, Serializable { + + private static final long serialVersionUID=-7168706947127349876L; @Override public WordReference produceSlow(final Entry e) { return new WordReferenceRow(e); } - + @Override public WordReference produceFast(final WordReference r) { if (r instanceof WordReferenceVars) return r; @@ -134,7 +137,7 @@ public class WordReferenceFactory implements ReferenceFactory { urlsb.append(dom); url = urlsb.toString(); ci.trim(6); - + peers = target.get(url); if (peers == null) { peers = new StringBuilder(24); diff --git a/source/net/yacy/kelondro/index/Row.java b/source/net/yacy/kelondro/index/Row.java index 1b0def059..6f1e40cae 100644 --- a/source/net/yacy/kelondro/index/Row.java +++ b/source/net/yacy/kelondro/index/Row.java @@ -237,7 +237,9 @@ public final class Row implements Serializable { } - public class Entry implements Comparable, Comparator, Cloneable { + public class Entry implements Comparable, Comparator, Cloneable, Serializable { + + private static final long serialVersionUID=-2576312347345553495L; private byte[] rowinstance; private int offset; // the offset where the row starts within rowinstance @@ -634,7 +636,10 @@ public final class Row implements Serializable { } - public final class EntryIndex extends Entry { + public final class EntryIndex extends Entry implements Serializable { + + private static final long serialVersionUID=153069052590699231L; + private final int index; public EntryIndex(final byte[] row, final int i) { super(row, false); diff --git a/source/net/yacy/kelondro/order/Bitfield.java b/source/net/yacy/kelondro/order/Bitfield.java index f338bd3c0..79e8ea29c 100644 --- a/source/net/yacy/kelondro/order/Bitfield.java +++ b/source/net/yacy/kelondro/order/Bitfield.java @@ -7,7 +7,7 @@ // $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 @@ -24,88 +24,91 @@ package net.yacy.kelondro.order; +import java.io.Serializable; + -public class Bitfield implements Cloneable { +public class Bitfield implements Cloneable, Serializable { // the bitfield implements a binary array. Such arrays may be exported in a base64-String - - private byte[] bb; + + private static final long serialVersionUID=3605122793792478052L; + private byte[] bb; public Bitfield() { this(0); } - + public Bitfield(final byte[] b) { if (b == null) this.bb = new byte[0]; else this.bb = b; } - + public Bitfield(final int bytelength) { this.bb= new byte[bytelength]; - for (int i = 0 ; i < bytelength; i++) bb[i] = 0; + for (int i = 0 ; i < bytelength; i++) this.bb[i] = 0; } public Bitfield(final int bytelength, final String exported) { // imports a b64-encoded bitfield final byte[] b = Base64Order.enhancedCoder.decode(exported); if (b.length == bytelength) { - bb = b; + this.bb = b; } else { - bb = new byte[bytelength]; + this.bb = new byte[bytelength]; assert (b.length <= bytelength) : "exported = " + exported + " has bytelength = " + b.length + " > " + bytelength; - System.arraycopy(b, 0, bb, 0, Math.min(b.length, bytelength)); + System.arraycopy(b, 0, this.bb, 0, Math.min(b.length, bytelength)); } } - + @Override public Bitfield clone() { final Bitfield theClone = new Bitfield(new byte[this.bb.length]); System.arraycopy(this.bb, 0, theClone.bb, 0, this.bb.length); return theClone; } - + public void set(final int pos, final boolean value) { assert (pos >= 0); final int slot = pos >> 3; // /8 - if (slot >= bb.length) { + if (slot >= this.bb.length) { // extend capacity byte[] nb = new byte[slot + 1]; - System.arraycopy(bb, 0, nb, 0, bb.length); - for (int i = bb.length; i < nb.length; i++) nb[i] = 0; - bb = nb; + System.arraycopy(this.bb, 0, nb, 0, this.bb.length); + for (int i = this.bb.length; i < nb.length; i++) nb[i] = 0; + this.bb = nb; } if (value) { - bb[slot] = (byte) (bb[slot] | (1 << (pos % 8))); + this.bb[slot] = (byte) (this.bb[slot] | (1 << (pos % 8))); } else { - bb[slot] = (byte) (bb[slot] & (0xff ^ (1 << (pos % 8)))); + this.bb[slot] = (byte) (this.bb[slot] & (0xff ^ (1 << (pos % 8)))); } } - + public boolean get(final int pos) { assert (pos >= 0); final int slot = pos >> 3; // /8 - if (slot >= bb.length) return false; - return (bb[slot] & (1 << (pos % 8))) > 0; + if (slot >= this.bb.length) return false; + return (this.bb[slot] & (1 << (pos % 8))) > 0; } public int length() { - return bb.length << 3; + return this.bb.length << 3; } - + public String exportB64() { - return Base64Order.enhancedCoder.encode(bb); + return Base64Order.enhancedCoder.encode(this.bb); } - + public byte[] bytes() { - return bb; + return this.bb; } - + @Override public String toString() { final StringBuilder sb = new StringBuilder(length()); for (int i = length() - 1; i >= 0; i--) sb.append((this.get(i)) ? '1' : '0'); return sb.toString(); } - + @Override public boolean equals(final Object obj) { if (this == obj) return true; @@ -116,17 +119,17 @@ public class Bitfield implements Cloneable { for (int i = 0; i < this.bb.length; i++) if (this.bb[i] != other.bb[i]) return false; return true; } - + @Override public int hashCode() { return this.toString().hashCode(); } - + public void and(final Bitfield x) { final int c = Math.min(x.length(), this.length()); for (int i = 0; i < c; i++) set(i, this.get(i) && x.get(i)); } - + public void or(final Bitfield x) { final int c = Math.min(x.length(), this.length()); for (int i = 0; i < c; i++) set(i, this.get(i) || x.get(i)); @@ -134,7 +137,7 @@ public class Bitfield implements Cloneable { for (int i = c; i < x.length(); i++) set(i, x.get(i)); } } - + public void xor(final Bitfield x) { final int c = Math.min(x.length(), this.length()); for (int i = 0; i < c; i++) set(i, this.get(i) != x.get(i)); @@ -142,13 +145,13 @@ public class Bitfield implements Cloneable { for (int i = c; i < x.length(); i++) set(i, x.get(i)); } } - + public boolean anyOf(final Bitfield x) { final int c = Math.min(x.length(), this.length()); for (int i = 0; i < c; i++) if ((x.get(i)) && (this.get(i))) return true; return false; } - + public boolean allOf(final Bitfield x) { final int c = Math.min(x.length(), this.length()); for (int i = 0; i < c; i++) if ((x.get(i)) && (!(this.get(i)))) return false; @@ -157,7 +160,7 @@ public class Bitfield implements Cloneable { } return true; } - + public static void main(final String[] args) { Bitfield test = new Bitfield(4); final int l = test.length(); @@ -166,19 +169,19 @@ public class Bitfield implements Cloneable { for (int i = 0; i < l/2; i++) { System.out.println(test.exportB64()); test.set(i, true); - System.out.println(i + ":" + test.toString()); + System.out.println(i + ":" + test.toString()); } for (int i = l/2; i < l; i++) { System.out.println(test.exportB64()); test = new Bitfield(4, test.exportB64()); test.set(i, true); - System.out.println(i + ":" + test.toString()); + System.out.println(i + ":" + test.toString()); } System.out.println(test.exportB64()); for (int i = l - 1; i >= 0; i--) { test.set(i, false); - System.out.println(i + ":" + test.toString()); + System.out.println(i + ":" + test.toString()); } - System.out.println("after: " + test.toString()); + System.out.println("after: " + test.toString()); } } diff --git a/source/net/yacy/kelondro/rwi/ReferenceContainer.java b/source/net/yacy/kelondro/rwi/ReferenceContainer.java index f799abb8f..5b5382501 100644 --- a/source/net/yacy/kelondro/rwi/ReferenceContainer.java +++ b/source/net/yacy/kelondro/rwi/ReferenceContainer.java @@ -54,6 +54,8 @@ import net.yacy.kelondro.order.Base64Order; */ public class ReferenceContainer extends RowSet { + private static final long serialVersionUID=-540567425172727979L; + private byte[] termHash; protected ReferenceFactory factory; public static int maxReferences = 0; // overwrite this to enable automatic index shrinking. 0 means no shrinking @@ -255,16 +257,19 @@ public class ReferenceContainer extends RowSet this.rowEntryIterator = iterator(); } + @Override public boolean hasNext() { return this.rowEntryIterator.hasNext(); } + @Override public ReferenceType next() { final Row.Entry rentry = this.rowEntryIterator.next(); if (rentry == null) return null; return ReferenceContainer.this.factory.produceSlow(rentry); } + @Override public void remove() { this.rowEntryIterator.remove(); } @@ -562,10 +567,12 @@ public class ReferenceContainer extends RowSet return pivot; } + @Override public synchronized String toString() { return "C[" + ASCII.String(this.termHash) + "] has " + size() + " entries"; } + @Override public int hashCode() { return (int) Base64Order.enhancedCoder.decodeLong(this.termHash, 0, 4); } diff --git a/source/net/yacy/peers/graphics/WebStructureGraph.java b/source/net/yacy/peers/graphics/WebStructureGraph.java index 9530f9bd5..9b38ca136 100644 --- a/source/net/yacy/peers/graphics/WebStructureGraph.java +++ b/source/net/yacy/peers/graphics/WebStructureGraph.java @@ -28,6 +28,7 @@ package net.yacy.peers.graphics; import java.io.File; +import java.io.Serializable; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; @@ -342,8 +343,9 @@ public class WebStructureGraph hosthashes); } - public static class HostReferenceFactory implements ReferenceFactory - { + public static class HostReferenceFactory implements ReferenceFactory, Serializable { + + private static final long serialVersionUID=7461135579006223155L; private static final Row hostReferenceRow = new Row( "String h-6, Cardinal m-4 {b256}, Cardinal c-4 {b256}", @@ -369,8 +371,9 @@ public class WebStructureGraph } - public static class HostReference extends AbstractReference implements Reference - { + public static class HostReference extends AbstractReference implements Reference, Serializable { + + private static final long serialVersionUID=-9170091435821206765L; private final Row.Entry entry;