From d77a8f3b3e2f2da64319a252be69d442c14ea78c Mon Sep 17 00:00:00 2001 From: orbiter Date: Sun, 10 Jan 2010 01:40:26 +0000 Subject: [PATCH] added some modifications recommended by PMD for better performance git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6560 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../domaingraph/applet/domaingraph.java | 1 - source/de/anomic/crawler/Balancer.java | 38 +++++++------- .../de/anomic/crawler/CrawlSwitchboard.java | 3 -- source/de/anomic/data/wiki/knwikiParser.java | 7 ++- .../anomic/http/server/HTTPDFileHandler.java | 2 +- .../anomic/http/server/HTTPDProxyHandler.java | 6 +-- source/de/anomic/search/Switchboard.java | 2 - .../net/yacy/ai/greedy/AbstractFinding.java | 10 ++-- source/net/yacy/kelondro/blob/Compressor.java | 8 +-- source/net/yacy/kelondro/index/Cache.java | 2 +- source/net/yacy/kelondro/index/Column.java | 6 +-- .../yacy/kelondro/index/ConcurrentARC.java | 10 ++-- source/net/yacy/kelondro/index/HandleMap.java | 32 ++++++------ source/net/yacy/kelondro/index/HandleSet.java | 10 ++-- source/net/yacy/kelondro/index/IndexTest.java | 40 +++++++------- .../yacy/kelondro/index/ObjectIndexCache.java | 28 +++++----- source/net/yacy/kelondro/index/Row.java | 40 +++++++------- .../yacy/kelondro/index/RowCollection.java | 21 ++++---- source/net/yacy/kelondro/index/RowSet.java | 18 +++---- .../net/yacy/kelondro/index/RowSetArray.java | 52 +++++++++---------- .../index/RowSpaceExceededException.java | 4 +- source/net/yacy/kelondro/index/SimpleARC.java | 14 ++--- source/net/yacy/kelondro/order/Digest.java | 2 +- .../net/yacy/kelondro/rwi/AbstractIndex.java | 10 ++-- source/net/yacy/kelondro/util/FileUtils.java | 2 - 25 files changed, 176 insertions(+), 192 deletions(-) diff --git a/htroot/processing/domaingraph/applet/domaingraph.java b/htroot/processing/domaingraph/applet/domaingraph.java index bc84521f5..a212a8c6e 100755 --- a/htroot/processing/domaingraph/applet/domaingraph.java +++ b/htroot/processing/domaingraph/applet/domaingraph.java @@ -161,7 +161,6 @@ public void processDomain(HashMap props) { public void processCitation(String host, HashMap props) { //println("Citation: " + props.toString()); String id = (String) props.get("id"); if (id == null) id = ""; - int count = 0; try { String counts = (String) props.get("count"); if (counts != null) count = Integer.parseInt(counts); } catch (NumberFormatException e) {} diff --git a/source/de/anomic/crawler/Balancer.java b/source/de/anomic/crawler/Balancer.java index cf409f78e..d302d2d34 100644 --- a/source/de/anomic/crawler/Balancer.java +++ b/source/de/anomic/crawler/Balancer.java @@ -77,7 +77,7 @@ public class Balancer { // create a stack for newly entered entries if (!(cachePath.exists())) cachePath.mkdir(); // make the path cacheStacksPath.mkdirs(); - File f = new File(cacheStacksPath, stackname + indexSuffix); + final File f = new File(cacheStacksPath, stackname + indexSuffix); try { urlFileIndex = new Table(f, Request.rowdef, EcoFSBufferSize, 0, useTailCache, exceed134217727); } catch (RowSpaceExceededException e) { @@ -177,7 +177,7 @@ public class Balancer { assert urlFileIndex.size() + removedCounter == s : "urlFileIndex.size() = " + urlFileIndex.size() + ", s = " + s; // iterate through the top list - Iterator j = top.iterator(); + final Iterator j = top.iterator(); String urlhash; while (j.hasNext()) { urlhash = j.next(); @@ -186,7 +186,7 @@ public class Balancer { // remove from delayed synchronized (this.delayed) { - Iterator> k = this.delayed.entrySet().iterator(); + final Iterator> k = this.delayed.entrySet().iterator(); while (k.hasNext()) { if (urlHashes.contains(k.next().getValue())) k.remove(); } @@ -199,7 +199,7 @@ public class Balancer { while (q.hasNext()) { se = q.next(); stack = se.getValue(); - Iterator i = stack.iterator(); + final Iterator i = stack.iterator(); while (i.hasNext()) { if (urlHashes.contains(i.next())) i.remove(); } @@ -240,7 +240,7 @@ public class Balancer { public void push(final Request entry) throws IOException, RowSpaceExceededException { assert entry != null; - String hash = entry.url().hash(); + final String hash = entry.url().hash(); synchronized (this) { if (urlFileIndex.has(hash.getBytes())) { //Log.logWarning("BALANCER", "double-check has failed for urlhash " + entry.url().hash() + " in " + stackname + " - fixed"); @@ -248,7 +248,7 @@ public class Balancer { } // add to index - int s = urlFileIndex.size(); + final int s = urlFileIndex.size(); urlFileIndex.put(entry.toRow()); assert s < urlFileIndex.size() : "hash = " + hash; assert urlFileIndex.has(hash.getBytes()) : "hash = " + hash; @@ -258,7 +258,7 @@ public class Balancer { } } - private void pushHashToDomainStacks(final String hash, int maxstacksize) { + private void pushHashToDomainStacks(final String hash, final int maxstacksize) { // extend domain stack final String dom = hash.substring(6); LinkedList domainList = domainStacks.get(dom); @@ -276,9 +276,9 @@ public class Balancer { private void removeHashFromDomainStacks(final String hash) { // extend domain stack final String dom = hash.substring(6); - LinkedList domainList = domainStacks.get(dom); + final LinkedList domainList = domainStacks.get(dom); if (domainList == null) return; - Iterator i = domainList.iterator(); + final Iterator i = domainList.iterator(); while (i.hasNext()) { if (i.next().equals(hash)) { i.remove(); @@ -289,7 +289,7 @@ public class Balancer { private String nextFromDelayed() { if (this.delayed.isEmpty()) return null; - Long first = this.delayed.firstKey(); + final Long first = this.delayed.firstKey(); if (first.longValue() < System.currentTimeMillis()) { return this.delayed.remove(first); } @@ -298,7 +298,7 @@ public class Balancer { private String anyFromDelayed() { if (this.delayed.isEmpty()) return null; - Long first = this.delayed.firstKey(); + final Long first = this.delayed.firstKey(); return this.delayed.remove(first); } @@ -376,7 +376,7 @@ public class Balancer { // at this point we must check if the crawlEntry has relevancy because the crawl profile still exists // if not: return null. A calling method must handle the null value and try again - CrawlProfile.entry profileEntry = (profile == null) ? null : profile.getEntry(crawlEntry.profileHandle()); + final CrawlProfile.entry profileEntry = (profile == null) ? null : profile.getEntry(crawlEntry.profileHandle()); if (profileEntry == null) { Log.logWarning("Balancer", "no profile entry for handle " + crawlEntry.profileHandle()); return null; @@ -435,7 +435,7 @@ public class Balancer { return crawlEntry; } - private void filltop(boolean delay, long maximumwaiting, boolean acceptonebest) { + private void filltop(final boolean delay, final long maximumwaiting, final boolean acceptonebest) { if (!this.top.isEmpty()) return; //System.out.println("*** DEBUG started filltop delay=" + ((delay) ? "true":"false") + ", maximumwaiting=" + maximumwaiting + ", acceptonebest=" + ((acceptonebest) ? "true":"false")); @@ -448,7 +448,7 @@ public class Balancer { } // iterate over the domain stacks - Iterator>> i = this.domainStacks.entrySet().iterator(); + final Iterator>> i = this.domainStacks.entrySet().iterator(); Map.Entry> entry; long smallestWaiting = Long.MAX_VALUE; String besthash = null; @@ -463,7 +463,7 @@ public class Balancer { String n = entry.getValue().getFirst(); if (delay) { - long w = Latency.waitingRemainingGuessed(n, minimumLocalDelta, minimumGlobalDelta); + final long w = Latency.waitingRemainingGuessed(n, minimumLocalDelta, minimumGlobalDelta); if (w > maximumwaiting) { if (w < smallestWaiting) { smallestWaiting = w; @@ -485,12 +485,12 @@ public class Balancer { } } - private void fillDomainStacks(int maxdomstacksize) throws IOException { + private void fillDomainStacks(final int maxdomstacksize) throws IOException { if (!this.domainStacks.isEmpty() && System.currentTimeMillis() - lastDomainStackFill < 120000L) return; this.domainStacks.clear(); //synchronized (this.delayed) { delayed.clear(); } this.lastDomainStackFill = System.currentTimeMillis(); - CloneableIterator i = this.urlFileIndex.keys(true, null); + final CloneableIterator i = this.urlFileIndex.keys(true, null); while (i.hasNext()) { pushHashToDomainStacks(new String(i.next()), 50); if (this.domainStacks.size() > maxdomstacksize) break; @@ -501,12 +501,12 @@ public class Balancer { public ArrayList top(int count) { count = Math.min(count, top.size()); - ArrayList cel = new ArrayList(); + final ArrayList cel = new ArrayList(); if (count == 0) return cel; synchronized (this) { for (String n: top) { try { - Row.Entry rowEntry = urlFileIndex.get(n.getBytes()); + final Row.Entry rowEntry = urlFileIndex.get(n.getBytes()); if (rowEntry == null) continue; final Request crawlEntry = new Request(rowEntry); cel.add(crawlEntry); diff --git a/source/de/anomic/crawler/CrawlSwitchboard.java b/source/de/anomic/crawler/CrawlSwitchboard.java index c613b0119..bc2f4ac19 100644 --- a/source/de/anomic/crawler/CrawlSwitchboard.java +++ b/source/de/anomic/crawler/CrawlSwitchboard.java @@ -34,8 +34,6 @@ import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.util.FileUtils; import net.yacy.kelondro.util.kelondroException; -import de.anomic.yacy.yacySeedDB; - public final class CrawlSwitchboard { public static final String CRAWL_PROFILE_PROXY = "proxy"; @@ -66,7 +64,6 @@ public final class CrawlSwitchboard { private final File queuesRoot; public CrawlSwitchboard( - final yacySeedDB peers, final String networkName, final Log log, final File queuesRoot) { diff --git a/source/de/anomic/data/wiki/knwikiParser.java b/source/de/anomic/data/wiki/knwikiParser.java index d067513ed..61b2c44ed 100644 --- a/source/de/anomic/data/wiki/knwikiParser.java +++ b/source/de/anomic/data/wiki/knwikiParser.java @@ -189,7 +189,7 @@ public class knwikiParser implements wikiParser { private String text; private final boolean nl; - public Text(final String text, final boolean escaped, final boolean newLineBefore) { + public Text(final String text, final boolean newLineBefore) { this.text = text; this.nl = newLineBefore; } @@ -223,13 +223,13 @@ public class knwikiParser implements wikiParser { if (text == null) return null; - if (text.length() < 2) return new Text[] {new Text(text, false, true) }; + if (text.length() < 2) return new Text[] {new Text(text, true) }; final int startLen = escapeBegin.length(); final int endLen = escapeEnd.length(); final ArrayList r = new ArrayList(); boolean escaped = text.startsWith(escapeBegin); - if (escaped) r.add(new Text("", false, true)); + if (escaped) r.add(new Text("", true)); int i, j = 0; while ((i = text.indexOf((escaped) ? escapeEnd : escapeBegin, j)) > -1) { r.add(resolve2Text(text, escaped, (j > 0) ? j + ((escaped) ? startLen : endLen) : 0, i, escapeEnd)); @@ -244,7 +244,6 @@ public class knwikiParser implements wikiParser { if (to == -1) to = text.length(); return new Text( text.substring(from, to), - escaped, from < escapeEnd.length() + 2 || (!escaped && text.charAt(from - escapeEnd.length() - 1) == '\n')); } diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.java index c5d255760..f130520ed 100644 --- a/source/de/anomic/http/server/HTTPDFileHandler.java +++ b/source/de/anomic/http/server/HTTPDFileHandler.java @@ -599,7 +599,7 @@ public final class HTTPDFileHandler { env.put("CONTENT_TYPE", requestHeader.getContentType()); } if (method.equalsIgnoreCase(HeaderFramework.METHOD_POST) && body != null) { - env.put("CONTENT_LENGTH", requestHeader.getContentLength() + ""); + env.put("CONTENT_LENGTH", Integer.toString(requestHeader.getContentLength())); } // add values from request header to environment (see: http://hoohoo.ncsa.uiuc.edu/cgi/env.html#headers) diff --git a/source/de/anomic/http/server/HTTPDProxyHandler.java b/source/de/anomic/http/server/HTTPDProxyHandler.java index c0acce0ca..44fa8f9c7 100644 --- a/source/de/anomic/http/server/HTTPDProxyHandler.java +++ b/source/de/anomic/http/server/HTTPDProxyHandler.java @@ -138,10 +138,10 @@ public final class HTTPDProxyHandler { if (pattern == null) pattern = "DATA/LOG/proxyAccess%u%g.log"; final String limitStr = manager.getProperty(className + ".logging.FileHandler.limit"); - if (limitStr != null) try { limit = Integer.valueOf(limitStr).intValue(); } catch (final NumberFormatException e) {} + if (limitStr != null) try { limit = Integer.parseInt(limitStr); } catch (final NumberFormatException e) {} final String countStr = manager.getProperty(className + ".logging.FileHandler.count"); - if (countStr != null) try { count = Integer.valueOf(countStr).intValue(); } catch (final NumberFormatException e) {} + if (countStr != null) try { count = Integer.parseInt(countStr); } catch (final NumberFormatException e) {} // creating the proxy access logger final Logger proxyLogger = Logger.getLogger("PROXY.access"); @@ -168,7 +168,7 @@ public final class HTTPDProxyHandler { sb = Switchboard.getSwitchboard(); if (sb != null) { - isTransparentProxy = Boolean.valueOf(sb.getConfig("isTransparentProxy","false")).booleanValue(); + isTransparentProxy = Boolean.parseBoolean(sb.getConfig("isTransparentProxy","false")); // set timeout timeout = Integer.parseInt(sb.getConfig("proxy.clientTimeout", "10000")); diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java index 88084e80a..6c76e8723 100644 --- a/source/de/anomic/search/Switchboard.java +++ b/source/de/anomic/search/Switchboard.java @@ -371,7 +371,6 @@ public final class Switchboard extends serverSwitch { this.useTailCache, this.exceed134217727); crawler = new CrawlSwitchboard( - peers, networkName, log, this.queuesRoot); @@ -847,7 +846,6 @@ public final class Switchboard extends serverSwitch { // startup crawler = new CrawlSwitchboard( - peers, networkName, log, this.queuesRoot); diff --git a/source/net/yacy/ai/greedy/AbstractFinding.java b/source/net/yacy/ai/greedy/AbstractFinding.java index 16fc9021a..f8969c3c2 100755 --- a/source/net/yacy/ai/greedy/AbstractFinding.java +++ b/source/net/yacy/ai/greedy/AbstractFinding.java @@ -59,7 +59,7 @@ public abstract class AbstractFinding implements Find * set the current priority * This may only be used internally as part of the engine process to create a result queue */ - public void setPriority(int newPriority) { + public void setPriority(final int newPriority) { this.priority = newPriority; } @@ -71,15 +71,15 @@ public abstract class AbstractFinding implements Find return this.role; } - public int compare(Finding f1, Finding f2) { - int p1 = f1.getPriority(); - int p2 = f2.getPriority(); + public int compare(final Finding f1, final Finding f2) { + final int p1 = f1.getPriority(); + final int p2 = f2.getPriority(); if (p1 < p2) return 1; if (p1 > p2) return -1; return 0; } - public int compareTo(Finding o) { + public int compareTo(final Finding o) { return compare(this, o); } diff --git a/source/net/yacy/kelondro/blob/Compressor.java b/source/net/yacy/kelondro/blob/Compressor.java index 0ba6a8d9b..3a6cc393a 100644 --- a/source/net/yacy/kelondro/blob/Compressor.java +++ b/source/net/yacy/kelondro/blob/Compressor.java @@ -5,8 +5,8 @@ // This is a part of YaCy, a peer-to-peer based web search engine // // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $ -// $LastChangedRevision: 1986 $ -// $LastChangedBy: orbiter $ +// $LastChangedRevision$ +// $LastChangedBy$ // // LICENSE // @@ -53,12 +53,10 @@ public class Compressor implements BLOB { private HashMap buffer; // entries which are not yet compressed, format is RAW (without magic) private long bufferlength; private long maxbufferlength; - private int cdr; public Compressor(BLOB backend, long buffersize) { this.backend = backend; this.maxbufferlength = buffersize; - this.cdr = 0; initBuffer(); } @@ -101,7 +99,6 @@ public class Compressor implements BLOB { private byte[] compressAddMagic(byte[] b) { // compress a byte array and add a leading magic for the compression try { - cdr++; //System.out.print("/(" + cdr + ")"); // DEBUG final ByteArrayOutputStream baos = new ByteArrayOutputStream(b.length / 5); baos.write(gzipMagic); @@ -130,7 +127,6 @@ public class Compressor implements BLOB { if (b == null) return null; if (ByteArray.startsWith(b, gzipMagic)) { //System.out.print("\\"); // DEBUG - cdr--; ByteArrayInputStream bais = new ByteArrayInputStream(b); // eat up the magic bais.read(); diff --git a/source/net/yacy/kelondro/index/Cache.java b/source/net/yacy/kelondro/index/Cache.java index af8fc413b..c83811613 100644 --- a/source/net/yacy/kelondro/index/Cache.java +++ b/source/net/yacy/kelondro/index/Cache.java @@ -72,7 +72,7 @@ public final class Cache implements ObjectIndex, Iterable { * @param hitLimit a limit of cache hit entries. If given as value <= 0, then only the RAM limits the size * @param missLimit a limit of cache miss entries. If given as value <= 0, then only the RAM limits the size */ - public Cache(final ObjectIndex backupIndex, int hitLimit, int missLimit) { + public Cache(final ObjectIndex backupIndex, final int hitLimit, final int missLimit) { this.index = backupIndex; this.hitLimit = hitLimit; this.missLimit = missLimit; diff --git a/source/net/yacy/kelondro/index/Column.java b/source/net/yacy/kelondro/index/Column.java index 61e23780b..190d6a966 100644 --- a/source/net/yacy/kelondro/index/Column.java +++ b/source/net/yacy/kelondro/index/Column.java @@ -63,7 +63,7 @@ public final class Column { // cut quotes etc. celldef = celldef.trim(); - if (celldef.startsWith("<")) celldef = celldef.substring(1); + if (celldef.charAt(0) == '<') celldef = celldef.substring(1); if (celldef.endsWith(">")) celldef = celldef.substring(0, celldef.length() - 1); // parse type definition @@ -260,11 +260,11 @@ public final class Column { * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Column)) return false; - Column other = (Column) obj; + final Column other = (Column) obj; if (celltype != other.celltype) return false; if (cellwidth != other.cellwidth) return false; if (encoder != other.encoder) return false; diff --git a/source/net/yacy/kelondro/index/ConcurrentARC.java b/source/net/yacy/kelondro/index/ConcurrentARC.java index 7a23c214a..46a5b4b87 100644 --- a/source/net/yacy/kelondro/index/ConcurrentARC.java +++ b/source/net/yacy/kelondro/index/ConcurrentARC.java @@ -40,7 +40,7 @@ public final class ConcurrentARC implements ARC { private final ARC arc[]; @SuppressWarnings("unchecked") - public ConcurrentARC(final int cacheSize, int partitions) { + public ConcurrentARC(final int cacheSize, final int partitions) { this.mask = 1; while (this.mask < partitions) this.mask = this.mask * 2; this.arc = new SimpleARC[mask]; @@ -53,7 +53,7 @@ public final class ConcurrentARC implements ARC { * @param s * @param v */ - public final void put(K s, V v) { + public final void put(final K s, final V v) { this.arc[s.hashCode() & mask].put(s, v); } @@ -62,7 +62,7 @@ public final class ConcurrentARC implements ARC { * @param s * @return the value */ - public final V get(K s) { + public final V get(final K s) { return this.arc[s.hashCode() & mask].get(s); } @@ -71,7 +71,7 @@ public final class ConcurrentARC implements ARC { * @param s * @return */ - public final boolean containsKey(K s) { + public final boolean containsKey(final K s) { return this.arc[s.hashCode() & mask].containsKey(s); } @@ -80,7 +80,7 @@ public final class ConcurrentARC implements ARC { * @param s * @return the old value */ - public final V remove(K s) { + public final V remove(final K s) { return this.arc[s.hashCode() & mask].remove(s); } diff --git a/source/net/yacy/kelondro/index/HandleMap.java b/source/net/yacy/kelondro/index/HandleMap.java index 7d129fe5c..185b901f0 100644 --- a/source/net/yacy/kelondro/index/HandleMap.java +++ b/source/net/yacy/kelondro/index/HandleMap.java @@ -62,12 +62,12 @@ public final class HandleMap implements Iterable { * @param objectOrder * @param space */ - public HandleMap(final int keylength, final ByteOrder objectOrder, int idxbytes, final int expectedspace) { + public HandleMap(final int keylength, final ByteOrder objectOrder, final int idxbytes, final int expectedspace) { this.rowdef = new Row(new Column[]{new Column("key", Column.celltype_binary, Column.encoder_bytes, keylength, "key"), new Column("long c-" + idxbytes + " {b256}")}, objectOrder); this.index = new ObjectIndexCache(rowdef, expectedspace); } - public HandleMap(final int keylength, final ByteOrder objectOrder, int idxbytes, final int expectedspace, final int initialspace) throws RowSpaceExceededException { + public HandleMap(final int keylength, final ByteOrder objectOrder, final int idxbytes, final int expectedspace, final int initialspace) throws RowSpaceExceededException { this.rowdef = new Row(new Column[]{new Column("key", Column.celltype_binary, Column.encoder_bytes, keylength, "key"), new Column("long c-" + idxbytes + " {b256}")}, objectOrder); this.index = new ObjectIndexCache(rowdef, expectedspace, initialspace); } @@ -80,12 +80,12 @@ public final class HandleMap implements Iterable { * @throws IOException * @throws RowSpaceExceededException */ - public HandleMap(final int keylength, final ByteOrder objectOrder, int idxbytes, final File file, final int expectedspace) throws IOException, RowSpaceExceededException { + public HandleMap(final int keylength, final ByteOrder objectOrder, final int idxbytes, final File file, final int expectedspace) throws IOException, RowSpaceExceededException { this(keylength, objectOrder, idxbytes, expectedspace, (int) (file.length() / (keylength + idxbytes))); // read the index dump and fill the index InputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024); if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is); - byte[] a = new byte[keylength + idxbytes]; + final byte[] a = new byte[keylength + idxbytes]; int c; Row.Entry entry; while (true) { @@ -123,7 +123,7 @@ public final class HandleMap implements Iterable { return new int[]{keym, this.rowdef.width(1) - valm}; } - private final int eq(byte[] a, byte[] b) { + private final int eq(final byte[] a, final byte[] b) { for (int i = 0; i < a.length; i++) { if (a[i] != b[i]) return i; } @@ -137,12 +137,12 @@ public final class HandleMap implements Iterable { * @return the number of written entries * @throws IOException */ - public final int dump(File file) throws IOException { + public final int dump(final File file) throws IOException { // we must use an iterator from the combined index, because we need the entries sorted // otherwise we could just write the byte[] from the in kelondroRowSet which would make // everything much faster, but this is not an option here. - File tmp = new File(file.getParentFile(), file.getName() + ".prt"); - Iterator i = this.index.rows(true, null); + final File tmp = new File(file.getParentFile(), file.getName() + ".prt"); + final Iterator i = this.index.rows(true, null); OutputStream os = new BufferedOutputStream(new FileOutputStream(tmp), 4 * 1024 * 1024); if (file.getName().endsWith(".gz")) os = new GZIPOutputStream(os); int c = 0; @@ -206,7 +206,7 @@ public final class HandleMap implements Iterable { index.addUnique(newentry); } - public final synchronized long add(final byte[] key, long a) throws RowSpaceExceededException { + public final synchronized long add(final byte[] key, final long a) throws RowSpaceExceededException { assert key != null; assert a > 0; // it does not make sense to add 0. If this occurres, it is a performance issue @@ -218,7 +218,7 @@ public final class HandleMap implements Iterable { index.addUnique(newentry); return 1; } - long i = indexentry.getColLong(1) + a; + final long i = indexentry.getColLong(1) + a; indexentry.setCol(1, i); index.put(indexentry); return i; @@ -295,9 +295,9 @@ public final class HandleMap implements Iterable { * @param bufferSize * @return */ - public final static initDataConsumer asynchronusInitializer(final int keylength, final ByteOrder objectOrder, int idxbytes, final int expectedspace) { - initDataConsumer initializer = new initDataConsumer(new HandleMap(keylength, objectOrder, idxbytes, expectedspace)); - ExecutorService service = Executors.newSingleThreadExecutor(); + public final static initDataConsumer asynchronusInitializer(final int keylength, final ByteOrder objectOrder, final int idxbytes, final int expectedspace) { + final initDataConsumer initializer = new initDataConsumer(new HandleMap(keylength, objectOrder, idxbytes, expectedspace)); + final ExecutorService service = Executors.newSingleThreadExecutor(); initializer.setResult(service.submit(initializer)); service.shutdown(); return initializer; @@ -321,13 +321,13 @@ public final class HandleMap implements Iterable { private Future result; private boolean sortAtEnd; - public initDataConsumer(HandleMap map) { + public initDataConsumer(final HandleMap map) { this.map = map; cache = new LinkedBlockingQueue(); sortAtEnd = false; } - protected final void setResult(Future result) { + protected final void setResult(final Future result) { this.result = result; } @@ -348,7 +348,7 @@ public final class HandleMap implements Iterable { * to signal the initialization thread that no more entries will be submitted with consumer() * this method must be called. The process will not terminate if this is not called before. */ - public final void finish(boolean sortAtEnd) { + public final void finish(final boolean sortAtEnd) { this.sortAtEnd = sortAtEnd; try { cache.put(poisonEntry); diff --git a/source/net/yacy/kelondro/index/HandleSet.java b/source/net/yacy/kelondro/index/HandleSet.java index 51ade462a..321d37908 100644 --- a/source/net/yacy/kelondro/index/HandleSet.java +++ b/source/net/yacy/kelondro/index/HandleSet.java @@ -65,8 +65,8 @@ public final class HandleSet implements Iterable { public HandleSet(final int keylength, final ByteOrder objectOrder, final File file, final int expectedspace) throws IOException, RowSpaceExceededException { this(keylength, objectOrder, expectedspace, (int) (file.length() / (keylength + 8))); // read the index dump and fill the index - InputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024); - byte[] a = new byte[keylength]; + final InputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024); + final byte[] a = new byte[keylength]; int c; while (true) { c = is.read(a); @@ -84,12 +84,12 @@ public final class HandleSet implements Iterable { * @return the number of written entries * @throws IOException */ - public final int dump(File file) throws IOException { + public final int dump(final File file) throws IOException { // we must use an iterator from the combined index, because we need the entries sorted // otherwise we could just write the byte[] from the in kelondroRowSet which would make // everything much faster, but this is not an option here. - Iterator i = this.index.rows(true, null); - OutputStream os = new BufferedOutputStream(new FileOutputStream(file), 1024 * 1024); + final Iterator i = this.index.rows(true, null); + final OutputStream os = new BufferedOutputStream(new FileOutputStream(file), 1024 * 1024); int c = 0; while (i.hasNext()) { os.write(i.next().bytes()); diff --git a/source/net/yacy/kelondro/index/IndexTest.java b/source/net/yacy/kelondro/index/IndexTest.java index b96a08125..7fd651389 100644 --- a/source/net/yacy/kelondro/index/IndexTest.java +++ b/source/net/yacy/kelondro/index/IndexTest.java @@ -57,52 +57,52 @@ public class IndexTest { public static final long mb = 1024 * 1024; - public static void main(String[] args) { + public static void main(final String[] args) { // pre-generate test data so it will not influence test case time - int count = args.length == 0 ? 1000000 : Integer.parseInt(args[0]); + final int count = args.length == 0 ? 1000000 : Integer.parseInt(args[0]); byte[][] tests = new byte[count][]; - Random r = new Random(0); + final Random r = new Random(0); for (int i = 0; i < count; i++) tests[i] = randomHash(r); System.out.println("generated " + count + " test data entries \n"); // start System.out.println("\nSTANDARD JAVA CLASS MAPS \n"); - long t1 = System.currentTimeMillis(); + final long t1 = System.currentTimeMillis(); // test tree map System.out.println("sorted map"); Runtime.getRuntime().gc(); - long freeStartTree = MemoryControl.free(); + final long freeStartTree = MemoryControl.free(); TreeMap tm = new TreeMap(Base64Order.enhancedCoder); for (int i = 0; i < count; i++) tm.put(tests[i], 1); - long t2 = System.currentTimeMillis(); + final long t2 = System.currentTimeMillis(); System.out.println("time for TreeMap generation: " + (t2 - t1)); int bugs = 0; for (int i = 0; i < count; i++) if (tm.get(tests[i]) == null) bugs++; Runtime.getRuntime().gc(); - long freeEndTree = MemoryControl.available(); + final long freeEndTree = MemoryControl.available(); tm.clear(); tm = null; - long t3 = System.currentTimeMillis(); + final long t3 = System.currentTimeMillis(); System.out.println("time for TreeMap test: " + (t3 - t2) + ", " + bugs + " bugs"); System.out.println("memory for TreeMap: " + (freeStartTree - freeEndTree) / mb + " MB\n"); // test hash map System.out.println("unsorted map"); Runtime.getRuntime().gc(); - long freeStartHash = MemoryControl.available(); + final long freeStartHash = MemoryControl.available(); HashMap hm = new HashMap(); for (int i = 0; i < count; i++) hm.put(new String(tests[i]), 1); - long t4 = System.currentTimeMillis(); + final long t4 = System.currentTimeMillis(); System.out.println("time for HashMap generation: " + (t4 - t3)); bugs = 0; for (int i = 0; i < count; i++) if (hm.get(new String(tests[i])) == null) bugs++; Runtime.getRuntime().gc(); - long freeEndHash = MemoryControl.available(); + final long freeEndHash = MemoryControl.available(); hm.clear(); hm = null; - long t5 = System.currentTimeMillis(); + final long t5 = System.currentTimeMillis(); System.out.println("time for HashMap test: " + (t5 - t4) + ", " + bugs + " bugs"); System.out.println("memory for HashMap: " + (freeStartHash - freeEndHash) / mb + " MB\n"); @@ -111,7 +111,7 @@ public class IndexTest { // test kelondro index System.out.println("sorted map"); Runtime.getRuntime().gc(); - long freeStartKelondro = MemoryControl.available(); + final long freeStartKelondro = MemoryControl.available(); HandleMap ii = null; try { ii = new HandleMap(12, Base64Order.enhancedCoder, 4, count, count); @@ -125,33 +125,33 @@ public class IndexTest { e.printStackTrace(); } ii.get(randomHash(r)); // trigger sort - long t6 = System.currentTimeMillis(); + final long t6 = System.currentTimeMillis(); System.out.println("time for HandleMap generation: " + (t6 - t5)); bugs = 0; for (int i = 0; i < count; i++) if (ii.get(tests[i]) != 1) bugs++; Runtime.getRuntime().gc(); - long freeEndKelondro = MemoryControl.available(); + final long freeEndKelondro = MemoryControl.available(); ii.clear(); ii = null; - long t7 = System.currentTimeMillis(); + final long t7 = System.currentTimeMillis(); System.out.println("time for HandleMap test: " + (t7 - t6) + ", " + bugs + " bugs"); System.out.println("memory for HandleMap: " + (freeStartKelondro - freeEndKelondro) / mb + " MB\n"); // test ByteArray System.out.println("unsorted map"); Runtime.getRuntime().gc(); - long freeStartBA = MemoryControl.available(); + final long freeStartBA = MemoryControl.available(); HashMap bm = new HashMap(); for (int i = 0; i < count; i++) bm.put(new ByteArray(tests[i]), 1); - long t8 = System.currentTimeMillis(); + final long t8 = System.currentTimeMillis(); System.out.println("time for HashMap generation: " + (t8 - t7)); bugs = 0; for (int i = 0; i < count; i++) if (bm.get(new ByteArray(tests[i])) == null) bugs++; Runtime.getRuntime().gc(); - long freeEndBA = MemoryControl.available(); + final long freeEndBA = MemoryControl.available(); bm.clear(); bm = null; - long t9 = System.currentTimeMillis(); + final long t9 = System.currentTimeMillis(); System.out.println("time for HashMap test: " + (t9 - t8) + ", " + bugs + " bugs"); System.out.println("memory for HashMap: " + (freeStartBA - freeEndBA) / mb + " MB\n"); diff --git a/source/net/yacy/kelondro/index/ObjectIndexCache.java b/source/net/yacy/kelondro/index/ObjectIndexCache.java index 4a882a385..278125959 100644 --- a/source/net/yacy/kelondro/index/ObjectIndexCache.java +++ b/source/net/yacy/kelondro/index/ObjectIndexCache.java @@ -87,19 +87,19 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable } public final synchronized byte[] smallestKey() { - byte[] b0 = index0.smallestKey(); + final byte[] b0 = index0.smallestKey(); if (b0 == null) return null; if (index1 == null) return b0; - byte[] b1 = index0.smallestKey(); + final byte[] b1 = index0.smallestKey(); if (b1 == null || rowdef.objectOrder.compare(b1, b0) > 0) return b0; return b1; } public final synchronized byte[] largestKey() { - byte[] b0 = index0.largestKey(); + final byte[] b0 = index0.largestKey(); if (b0 == null) return null; if (index1 == null) return b0; - byte[] b1 = index0.largestKey(); + final byte[] b1 = index0.largestKey(); if (b1 == null || rowdef.objectOrder.compare(b0, b1) > 0) return b0; return b1; } @@ -126,7 +126,7 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable finishInitialization(); // if the new entry is within the initialization part, just overwrite it assert index0.isSorted(); - byte[] key = entry.getPrimaryKeyBytes(); + final byte[] key = entry.getPrimaryKeyBytes(); if (index0.has(key)) { // replace the entry return index0.replace(entry); @@ -141,7 +141,7 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable finishInitialization(); // if the new entry is within the initialization part, just overwrite it assert index0.isSorted(); - byte[] key = entry.getPrimaryKeyBytes(); + final byte[] key = entry.getPrimaryKeyBytes(); if (index0.has(key)) { // replace the entry index0.put(entry); @@ -167,11 +167,11 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable while (i.hasNext()) addUnique(i.next()); } - public final synchronized long inc(final byte[] key, int col, long add, Row.Entry initrow) throws RowSpaceExceededException { + public final synchronized long inc(final byte[] key, final int col, final long add, final Row.Entry initrow) throws RowSpaceExceededException { assert (key != null); finishInitialization(); assert index0.isSorted(); - long l = index0.inc(key, col, add, null); + final long l = index0.inc(key, col, add, null); if (l != Long.MIN_VALUE) return l; return index1.inc(key, col, add, initrow); } @@ -182,8 +182,8 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable if (index1 == null) { return index0.removeDoubles(); } - ArrayList d0 = index0.removeDoubles(); - ArrayList d1 = index1.removeDoubles(); + final ArrayList d0 = index0.removeDoubles(); + final ArrayList d1 = index1.removeDoubles(); d0.addAll(d1); return d0; } @@ -254,8 +254,8 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable // index0 should be sorted // sort index1 to enable working of the merge iterator //assert consistencyAnalysis0() : "consistency problem: " + consistencyAnalysis(); - CloneableIterator k0 = index0.keys(up, firstKey); - CloneableIterator k1 = index1.keys(up, firstKey); + final CloneableIterator k0 = index0.keys(up, firstKey); + final CloneableIterator k1 = index1.keys(up, firstKey); if (k0 == null) return k1; if (k1 == null) return k0; return new MergeIterator( @@ -284,8 +284,8 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable // sort index1 to enable working of the merge iterator //index1.sort(); //assert consistencyAnalysis0() : "consistency problem: " + consistencyAnalysis(); - CloneableIterator k0 = index0.rows(up, firstKey); - CloneableIterator k1 = index1.rows(up, firstKey); + final CloneableIterator k0 = index0.rows(up, firstKey); + final CloneableIterator k1 = index1.rows(up, firstKey); if (k0 == null) return k1; if (k1 == null) return k0; return new MergeIterator( diff --git a/source/net/yacy/kelondro/index/Row.java b/source/net/yacy/kelondro/index/Row.java index 29e09aae2..c01c13029 100644 --- a/source/net/yacy/kelondro/index/Row.java +++ b/source/net/yacy/kelondro/index/Row.java @@ -71,7 +71,7 @@ public final class Row { this.primaryKeyLength = row[0].cellwidth; } - public Row(String structure, final ByteOrder objectOrder) { + public Row(final String structure, final ByteOrder objectOrder) { assert (objectOrder != null); this.objectOrder = objectOrder; // define row with row syntax @@ -204,7 +204,7 @@ public final class Row { return a.compareTo(b); } - public boolean equal(Entry a, Entry b) { + public boolean equal(final Entry a, final Entry b) { return a.equals(b); } @@ -332,7 +332,7 @@ public final class Row { return objectOrder.compare(this.bytes(), 0, this.getPrimaryKeyLength(), o.bytes(), 0, o.getPrimaryKeyLength()); } - public int compare(Entry o1, Entry o2) { + public int compare(final Entry o1, final Entry o2) { return o1.compareTo(o2); } @@ -341,7 +341,7 @@ public final class Row { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Entry)) return false; - Entry other = (Entry) obj; + final Entry other = (Entry) obj; final byte[] t = this.bytes(); final byte[] o = other.bytes(); for (int i = 0; i < primaryKeyLength; i++) { @@ -351,8 +351,8 @@ public final class Row { } public int hashCode() { - byte[] b = this.getPrimaryKeyBytes(); - int len = b.length; + final byte[] b = this.getPrimaryKeyBytes(); + final int len = b.length; int h = 1; for (int i = 0; i < len; i++) { h = 31 * h + b[i]; @@ -484,10 +484,10 @@ public final class Row { } } - public final long incCol(final int column, long c) { - int encoder = row[column].encoder; - int colstrt = colstart[column]; - int cellwidth = row[column].cellwidth; + public final long incCol(final int column, final long c) { + final int encoder = row[column].encoder; + final int colstrt = colstart[column]; + final int cellwidth = row[column].cellwidth; long l; switch (encoder) { case Column.encoder_b64e: @@ -517,14 +517,14 @@ public final class Row { final Object[] ref = nickref.get(nickname); if (ref == null) return dflt; final Column col = (Column) ref[0]; - return getColString(col.encoder, ((Integer) ref[1]).intValue(), col.cellwidth, encoding); + return getColString(((Integer) ref[1]).intValue(), col.cellwidth, encoding); } public final String getColString(final int column, final String encoding) { - return getColString(row[column].encoder, colstart[column], row[column].cellwidth, encoding); + return getColString(colstart[column], row[column].cellwidth, encoding); } - private final String getColString(final int encoder, final int clstrt, int length, final String encoding) { + private final String getColString(final int clstrt, int length, final String encoding) { if (rowinstance[offset + clstrt] == 0) return null; if (length > rowinstance.length - offset - clstrt) length = rowinstance.length - offset - clstrt; while ((length > 0) && (rowinstance[offset + clstrt + length - 1] == 0)) length--; @@ -660,7 +660,7 @@ public final class Row { } } - public Queue newQueue(int maxsize) { + public Queue newQueue(final int maxsize) { return new Queue(maxsize); } @@ -668,11 +668,11 @@ public final class Row { private final ArrayBlockingQueue queue; - public Queue(int maxsize) { + public Queue(final int maxsize) { this.queue = new ArrayBlockingQueue(maxsize); } - public void put(Entry e) throws InterruptedException { + public void put(final Entry e) throws InterruptedException { this.queue.put(e); } @@ -680,7 +680,7 @@ public final class Row { return this.queue.take(); } - public Entry get(byte[] key) { + public Entry get(final byte[] key) { for (Entry e: this.queue) { if (objectOrder.compare(key, 0, key.length, e.bytes(), 0, e.getPrimaryKeyLength()) == 0) { return e; @@ -689,8 +689,8 @@ public final class Row { return null; } - public Entry delete(byte[] key) { - Iterator i = this.queue.iterator(); + public Entry delete(final byte[] key) { + final Iterator i = this.queue.iterator(); Entry e; while (i.hasNext()) { e = i.next(); @@ -734,7 +734,7 @@ public final class Row { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Row)) return false; - Row other = (Row) obj; + final Row other = (Row) obj; if (this.objectsize != other.objectsize) return false; if (this.columns() != other.columns()) return false; for (int i = 0; i < other.row.length; i++) { diff --git a/source/net/yacy/kelondro/index/RowCollection.java b/source/net/yacy/kelondro/index/RowCollection.java index 18767d4ce..318253c9b 100644 --- a/source/net/yacy/kelondro/index/RowCollection.java +++ b/source/net/yacy/kelondro/index/RowCollection.java @@ -208,7 +208,7 @@ public class RowCollection implements Iterable { return this.rowdef; } - protected final long neededSpaceForEnsuredSize(final int elements, boolean forcegc) { + protected final long neededSpaceForEnsuredSize(final int elements, final boolean forcegc) { assert elements > 0 : "elements = " + elements; final long needed = elements * rowdef.objectsize; if (chunkcache.length >= needed) return 0; @@ -224,12 +224,12 @@ public class RowCollection implements Iterable { protected final void ensureSize(final int elements) throws RowSpaceExceededException { if (elements == 0) return; - long allocram = neededSpaceForEnsuredSize(elements, true); + final long allocram = neededSpaceForEnsuredSize(elements, true); if (allocram == 0) return; assert allocram > chunkcache.length : "wrong alloc computation: allocram = " + allocram + ", chunkcache.length = " + chunkcache.length; if (!MemoryControl.request(allocram, true)) throw new RowSpaceExceededException(allocram, "RowCollection grow"); try { - byte[] newChunkcache = new byte[(int) allocram]; // increase space + final byte[] newChunkcache = new byte[(int) allocram]; // increase space System.arraycopy(chunkcache, 0, newChunkcache, 0, chunkcache.length); chunkcache = newChunkcache; } catch (OutOfMemoryError e) { @@ -258,7 +258,7 @@ public class RowCollection implements Iterable { return; // if the swap buffer is not available, we must give up. // This is not critical. Otherwise we provoke a serious // problem with OOM - byte[] newChunkcache = new byte[(int) needed]; + final byte[] newChunkcache = new byte[(int) needed]; System.arraycopy(chunkcache, 0, newChunkcache, 0, Math.min( chunkcache.length, newChunkcache.length)); chunkcache = newChunkcache; @@ -299,7 +299,7 @@ public class RowCollection implements Iterable { public synchronized final void set(final int index, final Row.Entry a) throws RowSpaceExceededException { assert (index >= 0) : "set: access with index " + index + " is below zero"; ensureSize(index + 1); - boolean sameKey = match(a.bytes(), 0, a.cellwidth(0), index); + final boolean sameKey = match(a.bytes(), 0, a.cellwidth(0), index); //if (sameKey) System.out.print("$"); a.writeToArray(chunkcache, index * rowdef.objectsize); if (index >= this.chunkcount) this.chunkcount = index + 1; @@ -439,7 +439,7 @@ public class RowCollection implements Iterable { if (chunkcount == 0) return null; this.sort(); final Row.Entry r = get(0, false); - byte[] b = r.getPrimaryKeyBytes(); + final byte[] b = r.getPrimaryKeyBytes(); return b; } @@ -447,7 +447,7 @@ public class RowCollection implements Iterable { if (chunkcount == 0) return null; this.sort(); final Row.Entry r = get(chunkcount - 1, false); - byte[] b = r.getPrimaryKeyBytes(); + final byte[] b = r.getPrimaryKeyBytes(); return b; } @@ -471,7 +471,7 @@ public class RowCollection implements Iterable { return this.sortBound; } - public synchronized Iterator keys(boolean keepOrderWhenRemoving) { + public synchronized Iterator keys(final boolean keepOrderWhenRemoving) { // iterates byte[] - type entries return new keyIterator(keepOrderWhenRemoving); } @@ -487,7 +487,7 @@ public class RowCollection implements Iterable { private int p; private boolean keepOrderWhenRemoving; - public keyIterator(boolean keepOrderWhenRemoving) { + public keyIterator(final boolean keepOrderWhenRemoving) { this.p = 0; this.keepOrderWhenRemoving = keepOrderWhenRemoving; } @@ -858,7 +858,6 @@ public class RowCollection implements Iterable { final ArrayList report = new ArrayList(); if (chunkcount < 2) return report; int i = chunkcount - 2; - int d = 0; boolean u = true; RowCollection collection = new RowCollection(this.rowdef, 2); try { @@ -866,13 +865,11 @@ public class RowCollection implements Iterable { if (match(i, i + 1)) { collection.addUnique(get(i + 1, false)); removeRow(i + 1, false); - d++; if (i + 1 < chunkcount - 1) u = false; } else if (!collection.isEmpty()) { // finish collection of double occurrences collection.addUnique(get(i + 1, false)); removeRow(i + 1, false); - d++; if (i + 1 < chunkcount - 1) u = false; collection.trim(false); report.add(collection); diff --git a/source/net/yacy/kelondro/index/RowSet.java b/source/net/yacy/kelondro/index/RowSet.java index 0a81fff93..f4958db14 100644 --- a/source/net/yacy/kelondro/index/RowSet.java +++ b/source/net/yacy/kelondro/index/RowSet.java @@ -67,7 +67,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable= exportOverheadSize : "b.length = " + b.length; if (b.length < exportOverheadSize) return new RowSet(rowdef); final int size = (int) NaturalOrder.decodeLong(b, 0, 4); @@ -105,11 +105,11 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable collectionReSortLimit) { sort(); } - int index = find(entry.bytes(), 0, super.rowdef.primaryKeyLength); + final int index = find(entry.bytes(), 0, super.rowdef.primaryKeyLength); if (index < 0) { super.addUnique(entry); } else { - int sb = this.sortBound; // save the sortBound, because it is not altered (we replace at the same place) + final int sb = this.sortBound; // save the sortBound, because it is not altered (we replace at the same place) set(index, entry); // this may alter the sortBound, which we will revert in the next step this.sortBound = sb; // revert a sortBound altering } @@ -129,19 +129,19 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable= 0) { // the entry existed before final Row.Entry entry = get(index, false); // no clone necessary - long l = entry.incCol(col, add); + final long l = entry.incCol(col, add); set(index, entry); return l; } else if (initrow != null) { @@ -378,7 +378,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable= c.size()) { @@ -407,9 +407,9 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable implements ARC { this.cacheSize = cacheSize / 2; this.levelA = new LinkedHashMap(cacheSize, 0.1f, accessOrder) { private static final long serialVersionUID = 1L; - @Override protected boolean removeEldestEntry(Map.Entry eldest) { + @Override protected boolean removeEldestEntry(final Map.Entry eldest) { return size() > SimpleARC.this.cacheSize; } }; this.levelB = new LinkedHashMap(cacheSize, 0.1f, accessOrder) { private static final long serialVersionUID = 1L; - @Override protected boolean removeEldestEntry(Map.Entry eldest) { + @Override protected boolean removeEldestEntry(final Map.Entry eldest) { return size() > SimpleARC.this.cacheSize; } }; @@ -65,7 +65,7 @@ public final class SimpleARC implements ARC { * @param s * @param v */ - public final synchronized void put(K s, V v) { + public final synchronized void put(final K s, final V v) { if (this.levelB.containsKey(s)) { this.levelB.put(s, v); assert (this.levelB.size() <= cacheSize); // the cache should shrink automatically @@ -80,7 +80,7 @@ public final class SimpleARC implements ARC { * @param s * @return the value */ - public final synchronized V get(K s) { + public final synchronized V get(final K s) { V v = this.levelB.get(s); if (v != null) return v; v = this.levelA.remove(s); @@ -97,7 +97,7 @@ public final class SimpleARC implements ARC { * @param s * @return */ - public final synchronized boolean containsKey(K s) { + public final synchronized boolean containsKey(final K s) { if (this.levelB.containsKey(s)) return true; return this.levelA.containsKey(s); } @@ -107,8 +107,8 @@ public final class SimpleARC implements ARC { * @param s * @return the old value */ - public final synchronized V remove(K s) { - V r = this.levelB.remove(s); + public final synchronized V remove(final K s) { + final V r = this.levelB.remove(s); if (r != null) return r; return this.levelA.remove(s); } diff --git a/source/net/yacy/kelondro/order/Digest.java b/source/net/yacy/kelondro/order/Digest.java index 364ca9ccc..1fd2d5e69 100644 --- a/source/net/yacy/kelondro/order/Digest.java +++ b/source/net/yacy/kelondro/order/Digest.java @@ -91,7 +91,7 @@ public class Digest { public static byte[] decodeHex(final String hex) { final byte[] result = new byte[hex.length() / 2]; for (int i = 0; i < result.length; i++) { - result[i] = (byte) (16 * Integer.parseInt(hex.charAt(i * 2) + "", 16) + Integer.parseInt(hex.charAt(i * 2 + 1) + "", 16)); + result[i] = (byte) (16 * Integer.parseInt(Character.toString(hex.charAt(i * 2)), 16) + Integer.parseInt(Character.toString(hex.charAt(i * 2 + 1)), 16)); } return result; } diff --git a/source/net/yacy/kelondro/rwi/AbstractIndex.java b/source/net/yacy/kelondro/rwi/AbstractIndex.java index 903b2c5a3..9fc87684e 100644 --- a/source/net/yacy/kelondro/rwi/AbstractIndex.java +++ b/source/net/yacy/kelondro/rwi/AbstractIndex.java @@ -60,7 +60,7 @@ public abstract class AbstractIndex implements // creates a set of indexContainers // this does not use the cache final Order> containerOrder = new ReferenceContainerOrder(factory, this.ordering().clone()); - ReferenceContainer emptyContainer = ReferenceContainer.emptyContainer(factory, startHash); + final ReferenceContainer emptyContainer = ReferenceContainer.emptyContainer(factory, startHash); containerOrder.rotate(emptyContainer); final TreeSet> containers = new TreeSet>(containerOrder); final Iterator> i = references(startHash, rot); @@ -103,7 +103,7 @@ public abstract class AbstractIndex implements final HashMap> containers = new HashMap>(wordHashes.size()); byte[] singleHash; ReferenceContainer singleContainer; - Iterator i = wordHashes.iterator(); + final Iterator i = wordHashes.iterator(); while (i.hasNext()) { // get next word hash: @@ -136,7 +136,7 @@ public abstract class AbstractIndex implements * @return ReferenceContainer the join result * @throws RowSpaceExceededException */ - public ReferenceContainer searchJoin(final TreeSet wordHashes, final Set urlselection, int maxDistance) throws RowSpaceExceededException { + public ReferenceContainer searchJoin(final TreeSet wordHashes, final Set urlselection, final int maxDistance) throws RowSpaceExceededException { // first check if there is any entry that has no match; // this uses only operations in ram for (byte[] wordHash: wordHashes) { @@ -171,8 +171,8 @@ public abstract class AbstractIndex implements final TreeSet queryHashes, final TreeSet excludeHashes, final Set urlselection, - ReferenceFactory termFactory, - int maxDistance) throws RowSpaceExceededException { + final ReferenceFactory termFactory, + final int maxDistance) throws RowSpaceExceededException { return new TermSearch(this, queryHashes, excludeHashes, urlselection, termFactory, maxDistance); } diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.java index 5eb05ce5b..7c9640658 100644 --- a/source/net/yacy/kelondro/util/FileUtils.java +++ b/source/net/yacy/kelondro/util/FileUtils.java @@ -555,14 +555,12 @@ public final class FileUtils { public static ArrayList getListArray(final File listFile){ String line; final ArrayList list = new ArrayList(); - int count = 0; BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(new FileInputStream(listFile),"UTF-8")); while((line = br.readLine()) != null){ list.add(line); - count++; } br.close(); } catch(final IOException e) {