Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

refactoring + distinguish getMap from getList in table operations

Michael Peter Christene1390bef6913
diff --git a/source/net/yacy/kelondro/index/BufferedObjectIndex.java b/source/net/yacy/kelondro/index/BufferedObjectIndex.java
index 9a526d5e1..4a7656729 100644
--- a/source/net/yacy/kelondro/index/BufferedObjectIndex.java
+++ b/source/net/yacy/kelondro/index/BufferedObjectIndex.java
@@ -107,13 +107,13 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
* @throws IOException
*/
private final void checkBuffer() throws IOException, SpaceExceededException {
- if (this.buffer.size() >= this.buffersize) flushBuffer();
+ if (this.buffer.size() >= this.buffersize) this.flushBuffer();
}
@Override
public void addUnique(final Entry row) throws SpaceExceededException, IOException {
synchronized (this.backend) {
- checkBuffer();
+ this.checkBuffer();
this.buffer.put(row);
}
}
@@ -130,7 +130,7 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
public synchronized void close() {
synchronized (this.backend) {
try {
- flushBuffer();
+ this.flushBuffer();
} catch (final IOException e) {
ConcurrentLog.logException(e);
} catch (final SpaceExceededException e) {
@@ -167,16 +167,27 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public boolean has(final byte[] key) {
synchronized (this.backend) {
@@ -201,7 +212,7 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
@Override
public boolean put(final Entry row) throws IOException, SpaceExceededException {
synchronized (this.backend) {
- checkBuffer();
+ this.checkBuffer();
return this.buffer.put(row);
}
}
@@ -227,14 +238,14 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
@Override
public List<RowCollection> removeDoubles() throws IOException, SpaceExceededException {
synchronized (this.backend) {
- flushBuffer();
+ this.flushBuffer();
return this.backend.removeDoubles();
}
}
@Override
public List<Row.Entry> top(final int count) throws IOException {
- final List<Row.Entry> list = new ArrayList<Row.Entry>();
+ final List<Row.Entry> list = new ArrayList<>();
synchronized (this.backend) {
List<Row.Entry> list0 = this.buffer.top(count);
list.addAll(list0);
@@ -252,9 +263,9 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
list1 = this.backend.random(count - list0.size());
}
// multiplex the lists
- final List<Row.Entry> list = new ArrayList<Row.Entry>();
- Iterator<Row.Entry> i0 = list0.iterator();
- Iterator<Row.Entry> i1 = list1.iterator();
+ final List<Row.Entry> list = new ArrayList<>();
+ final Iterator<Row.Entry> i0 = list0.iterator();
+ final Iterator<Row.Entry> i1 = list1.iterator();
while (i0.hasNext() || i1.hasNext()) {
if (i0.hasNext()) list.add(i0.next());
if (i1.hasNext()) list.add(i1.next());
@@ -290,11 +301,11 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
@Override
public CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
synchronized (this.backend) {
- CloneableIterator<byte[]> a = this.buffer.keys(up, firstKey);
- CloneableIterator<byte[]> b = this.backend.keys(up, firstKey);
+ final CloneableIterator<byte[]> a = this.buffer.keys(up, firstKey);
+ final CloneableIterator<byte[]> b = this.backend.keys(up, firstKey);
if (b == null) return a;
if (a == null) return b;
- return new MergeIterator<byte[]>(a, b, this.buffer.rowdef.getOrdering(), MergeIterator.simpleMerge, up);
+ return new MergeIterator<>(a, b, this.buffer.rowdef.getOrdering(), MergeIterator.simpleMerge, up);
}
}
@@ -311,7 +322,7 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
@Override
public CloneableIterator<Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
synchronized (this.backend) {
- return new MergeIterator<Entry>(
+ return new MergeIterator<>(
this.buffer.rows(up, firstKey),
this.backend.rows(up, firstKey),
this.entryComparator,
@@ -323,7 +334,7 @@ public class BufferedObjectIndex implements Index, Iterable<Row.Entry> {
@Override
public CloneableIterator<Entry> rows() throws IOException {
synchronized (this.backend) {
- return new MergeIterator<Entry>(
+ return new MergeIterator<>(
this.buffer.rows(),
this.backend.rows(),
this.entryComparator,
diff --git a/source/net/yacy/kelondro/index/Cache.java b/source/net/yacy/kelondro/index/Cache.java
index bbd634f8b..5f81d3a44 100644
--- a/source/net/yacy/kelondro/index/Cache.java
+++ b/source/net/yacy/kelondro/index/Cache.java
@@ -25,6 +25,7 @@
package net.yacy.kelondro.index;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -50,7 +51,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
// furthermore, if we access a kelondroFlexTable, we can use the ram index of the underlying index
// static object tracker; stores information about object cache usage
- private static final TreeMap<String, Cache> objectTracker = new TreeMap<String, Cache>();
+ private static final TreeMap<String, Cache> objectTracker = new TreeMap<>();
private static final long memStopGrow = 40 * 1024 * 1024; // a limit for the node cache to stop growing if less than this memory amount is available
private static final long memStartShrink = 20 * 1024 * 1024; // a limit for the node cache to start with shrinking if less than this memory amount is available
@@ -74,7 +75,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
this.index = backupIndex;
this.hitLimit = hitLimit;
this.missLimit = missLimit;
- init();
+ this.init();
objectTracker.put(backupIndex.filename(), this);
}
@@ -174,7 +175,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
private final Map<StatKeys, String> memoryStats() {
// returns statistical data about this object
- final HashMap<StatKeys, String> map = new HashMap<StatKeys, String>(20);
+ final HashMap<StatKeys, String> map = new HashMap<>(20);
map.put(StatKeys.objectHitChunkSize, (this.readHitCache == null) ? "0" : Integer.toString(this.readHitCache.rowdef.objectsize));
map.put(StatKeys.objectHitCacheCount, (this.readHitCache == null) ? "0" : Integer.toString(this.readHitCache.size()));
map.put(StatKeys.objectHitMem, (this.readHitCache == null) ? "0" : Long.toString(this.readHitCache.rowdef.objectsize * this.readHitCache.size()));
@@ -303,43 +304,54 @@ public final class Cache implements Index, Iterable<Row.Entry> {
entry = this.index.get(key, cachecopy);
// learn from result
if (entry == null) {
- if (checkMissSpace()) try {
+ if (this.checkMissSpace()) try {
final Row.Entry dummy = this.readMissCache.replace(this.readMissCache.row().newEntry(key));
if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
return null;
}
- if (checkHitSpace()) try {
+ if (this.checkHitSpace()) try {
final Row.Entry dummy = this.readHitCache.replace(entry);
if (dummy == null) this.writeUnique++; else this.writeDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
return entry;
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public final synchronized boolean put(final Row.Entry row) throws IOException, SpaceExceededException {
assert (row != null);
- assert (row.columns() == row().columns());
+ assert (row.columns() == this.row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
final byte[] key = row.getPrimaryKeyBytes();
- checkHitSpace();
+ this.checkHitSpace();
// remove entry from miss- and hit-cache
if (this.readMissCache != null) {
@@ -354,14 +366,14 @@ public final class Cache implements Index, Iterable<Row.Entry> {
c = this.index.put(row);
} catch (final SpaceExceededException e1) {
// flush all caches to get more memory
- clearCache();
+ this.clearCache();
c = this.index.put(row); // try again
}
- if (checkHitSpace()) try {
+ if (this.checkHitSpace()) try {
final Row.Entry dummy = this.readHitCache.replace(row); // overwrite old entry
if (dummy == null) this.writeUnique++; else this.writeDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
return c;
}
@@ -369,11 +381,11 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final synchronized Row.Entry replace(final Row.Entry row) throws IOException, SpaceExceededException {
assert (row != null);
- assert (row.columns() == row().columns());
+ assert (row.columns() == this.row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
final byte[] key = row.getPrimaryKeyBytes();
- checkHitSpace();
+ this.checkHitSpace();
// remove entry from miss- and hit-cache
if (this.readMissCache != null) {
@@ -384,15 +396,15 @@ public final class Cache implements Index, Iterable<Row.Entry> {
this.index.put(row);
} catch (final SpaceExceededException e1) {
// flush all caches to get more memory
- clearCache();
+ this.clearCache();
this.index.put(row); // try again
}
// write to backend
- if (checkHitSpace()) try {
+ if (this.checkHitSpace()) try {
final Row.Entry dummy = this.readHitCache.replace(row); // learn that entry
if (dummy == null) this.writeUnique++; else this.writeDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
return null;
}
@@ -404,14 +416,14 @@ public final class Cache implements Index, Iterable<Row.Entry> {
entry = this.index.replace(row);
} catch (final SpaceExceededException e1) {
// flush all caches to get more memory
- clearCache();
+ this.clearCache();
this.index.replace(row); // try again
}
- if (checkHitSpace()) try {
+ if (this.checkHitSpace()) try {
final Row.Entry dummy = this.readHitCache.replace(row); // learn that entry
if (dummy == null) this.writeUnique++; else this.writeDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
return entry;
}
@@ -419,11 +431,11 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final synchronized void addUnique(final Row.Entry row) throws IOException, SpaceExceededException {
assert (row != null);
- assert (row.columns() == row().columns());
+ assert (row.columns() == this.row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
final byte[] key = row.getPrimaryKeyBytes();
- checkHitSpace();
+ this.checkHitSpace();
// remove entry from miss- and hit-cache
if (this.readMissCache != null) {
@@ -437,28 +449,28 @@ public final class Cache implements Index, Iterable<Row.Entry> {
this.index.addUnique(row);
} catch (final SpaceExceededException e1) {
// flush all caches to get more memory
- clearCache();
+ this.clearCache();
this.index.addUnique(row); // try again
}
- if (checkHitSpace()) try {
+ if (this.checkHitSpace()) try {
final Row.Entry dummy = this.readHitCache.replace(row); // learn that entry
if (dummy == null) this.writeUnique++; else this.writeDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
}
public final synchronized void addUnique(final Row.Entry row, final Date entryDate) throws IOException, SpaceExceededException {
if (entryDate == null) {
- addUnique(row);
+ this.addUnique(row);
return;
}
assert (row != null);
- assert (row.columns() == row().columns());
+ assert (row.columns() == this.row().columns());
final byte[] key = row.getPrimaryKeyBytes();
- checkHitSpace();
+ this.checkHitSpace();
// remove entry from miss- and hit-cache
if (this.readMissCache != null) {
@@ -471,14 +483,14 @@ public final class Cache implements Index, Iterable<Row.Entry> {
this.index.addUnique(row);
} catch (final SpaceExceededException e1) {
// flush all caches to get more memory
- clearCache();
+ this.clearCache();
this.index.addUnique(row); // try again
}
- if (checkHitSpace()) try {
+ if (this.checkHitSpace()) try {
final Row.Entry dummy = this.readHitCache.replace(row); // learn that entry
if (dummy == null) this.writeUnique++; else this.writeDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
}
@@ -488,11 +500,11 @@ public final class Cache implements Index, Iterable<Row.Entry> {
while (i.hasNext()) {
r = i.next();
try {
- addUnique(r);
+ this.addUnique(r);
} catch (final SpaceExceededException e) {
// flush all caches to get more memory
- clearCache();
- addUnique(r); // try again
+ this.clearCache();
+ this.addUnique(r); // try again
}
}
}
@@ -505,10 +517,10 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final synchronized boolean delete(final byte[] key) throws IOException {
- checkMissSpace();
+ this.checkMissSpace();
// add entry to miss-cache
- if (checkMissSpace()) try {
+ if (this.checkMissSpace()) try {
// set the miss cache; if there was already an entry we know that the return value must be null
final Row.Entry dummy = this.readMissCache.replace(this.readMissCache.row().newEntry(key));
if (dummy == null) {
@@ -518,7 +530,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
this.hasnotDouble++;
}
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
// remove entry from hit-cache
@@ -537,10 +549,10 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final synchronized Row.Entry remove(final byte[] key) throws IOException {
- checkMissSpace();
+ this.checkMissSpace();
// add entry to miss-cache
- if (checkMissSpace()) try {
+ if (this.checkMissSpace()) try {
// set the miss cache; if there was already an entry we know that the return value must be null
final Row.Entry dummy = this.readMissCache.replace(this.readMissCache.row().newEntry(key));
if (dummy == null) {
@@ -550,7 +562,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
this.hasnotDouble++;
}
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
// remove entry from hit-cache
@@ -570,16 +582,16 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final synchronized Row.Entry removeOne() throws IOException {
- checkMissSpace();
+ this.checkMissSpace();
final Row.Entry entry = this.index.removeOne();
if (entry == null) return null;
final byte[] key = entry.getPrimaryKeyBytes();
- if (checkMissSpace()) try {
+ if (this.checkMissSpace()) try {
final Row.Entry dummy = this.readMissCache.replace(this.readMissCache.row().newEntry(key));
if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++;
} catch (final SpaceExceededException e) {
- clearCache();
+ this.clearCache();
}
if (this.readHitCache != null) {
if (this.readHitCache.delete(key)) this.cacheDelete++;
@@ -615,7 +627,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final Iterator<Entry> iterator() {
try {
- return rows();
+ return this.rows();
} catch (final IOException e) {
return null;
}
@@ -644,7 +656,7 @@ public final class Cache implements Index, Iterable<Row.Entry> {
@Override
public final void clear() throws IOException {
this.index.clear();
- init();
+ this.init();
}
@Override
diff --git a/source/net/yacy/kelondro/index/Index.java b/source/net/yacy/kelondro/index/Index.java
index bc83c9695..d2845ee9d 100644
--- a/source/net/yacy/kelondro/index/Index.java
+++ b/source/net/yacy/kelondro/index/Index.java
@@ -45,7 +45,8 @@ public interface Index extends Iterable<Row.Entry> {
public byte[] smallestKey();
public byte[] largestKey();
public boolean has(byte[] key); // use this only if there is no get in case that has returns true
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, boolean forcecopy) throws IOException, InterruptedException;
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, boolean forcecopy) throws IOException, InterruptedException;
+ public List<Row.Entry> getList(final Collection<byte[]> keys, boolean forcecopy) throws IOException, InterruptedException;
public Row.Entry get(byte[] key, boolean forcecopy) throws IOException;
public Row.Entry replace(Row.Entry row) throws SpaceExceededException, IOException;
diff --git a/source/net/yacy/kelondro/index/OnDemandOpenFileIndex.java b/source/net/yacy/kelondro/index/OnDemandOpenFileIndex.java
index 2317787f3..9ea6b1abd 100644
--- a/source/net/yacy/kelondro/index/OnDemandOpenFileIndex.java
+++ b/source/net/yacy/kelondro/index/OnDemandOpenFileIndex.java
@@ -59,10 +59,10 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
private Index getIndex() {
try {
return new Table(this.file, this.rowdef, 1000, 0, false, this.exceed134217727, false);
- } catch (kelondroException e) {
+ } catch (final kelondroException e) {
ConcurrentLog.logException(e);
return null;
- } catch (SpaceExceededException e) {
+ } catch (final SpaceExceededException e) {
ConcurrentLog.logException(e);
return null;
}
@@ -70,25 +70,25 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized byte[] smallestKey() {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
- byte[] b = index.smallestKey();
+ final byte[] b = index.smallestKey();
index.close();
return b;
}
@Override
public synchronized byte[] largestKey() {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
- byte[] b = index.largestKey();
+ final byte[] b = index.largestKey();
index.close();
return b;
}
@Override
public synchronized void optimize() {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return;
index.optimize();
index.close();
@@ -96,21 +96,21 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized long mem() {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return 0;
- long l = index.mem();
+ final long l = index.mem();
index.close();
return l;
}
@Override
public synchronized void addUnique(final Entry row) throws SpaceExceededException, IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return;
try {
index.addUnique(row);
if (this.sizecache >= 0) this.sizecache++;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -119,12 +119,12 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized void clear() throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return;
try {
index.clear();
this.sizecache = 0;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -138,7 +138,7 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized void deleteOnExit() {
- Index index = getIndex();
+ final Index index = this.getIndex();
index.deleteOnExit();
index.close();
}
@@ -151,9 +151,9 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized int size() {
if (this.sizecache >= 0) return this.sizecache;
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return 0;
- int i = index.size();
+ final int i = index.size();
index.close();
this.sizecache = i;
return i;
@@ -162,11 +162,11 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized Entry get(final byte[] key, final boolean forcecopy) throws IOException {
if (this.sizecache == 0) return null;
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
return index.get(key, forcecopy);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -174,23 +174,35 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
}
@Override
- public synchronized Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public synchronized Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
if (this.sizecache == 0) return map;
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public synchronized List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ if (this.sizecache == 0) return list;
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public synchronized boolean has(final byte[] key) {
if (this.sizecache == 0) return false;
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return false;
- boolean b = index.has(key);
+ final boolean b = index.has(key);
index.close();
return b;
}
@@ -198,9 +210,9 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized boolean isEmpty() {
if (this.sizecache == 0) return true;
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return true;
- boolean b = index.isEmpty();
+ final boolean b = index.isEmpty();
if (b) this.sizecache = 0;
index.close();
return b;
@@ -215,13 +227,13 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
*/
@Override
public synchronized boolean put(final Entry row) throws IOException, SpaceExceededException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return false;
try {
- boolean b = index.put(row);
+ final boolean b = index.put(row);
if (this.sizecache >= 0 && b) this.sizecache++;
return b;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -238,15 +250,15 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
* @throws SpaceExceededException
*/
public synchronized void put(final RowSet rowset) throws IOException, SpaceExceededException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return;
try {
for (final Row.Entry row: rowset) {
- boolean b = index.put(row);
+ final boolean b = index.put(row);
if (this.sizecache >= 0 && b) this.sizecache++;
}
return;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -255,13 +267,13 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized Entry remove(final byte[] key) throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
- Entry e = index.remove(key);
+ final Entry e = index.remove(key);
if (this.sizecache >= 0 && e != null) this.sizecache--;
return e;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -270,13 +282,13 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized boolean delete(final byte[] key) throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return false;
try {
- boolean b = index.delete(key);
+ final boolean b = index.delete(key);
if (this.sizecache >= 0 && b) this.sizecache--;
return b;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -285,13 +297,13 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized List<RowCollection> removeDoubles() throws IOException, SpaceExceededException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
- List<RowCollection> l = index.removeDoubles();
+ final List<RowCollection> l = index.removeDoubles();
this.sizecache = index.size();
return l;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -300,11 +312,11 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized List<Row.Entry> top(final int count) throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
return index.top(count);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -313,11 +325,11 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized List<Row.Entry> random(final int count) throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
return index.random(count);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -326,13 +338,13 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized Entry removeOne() throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
- Entry e = index.removeOne();
+ final Entry e = index.removeOne();
if (this.sizecache >= 0 && e != null) this.sizecache--;
return e;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -341,13 +353,13 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized Entry replace(final Entry row) throws SpaceExceededException, IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
- Entry e = index.replace(row);
+ final Entry e = index.replace(row);
if (this.sizecache >= 0 && e == null) this.sizecache++;
return e;
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -361,11 +373,11 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
try {
return index.keys(up, firstKey);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw e;
} finally {
index.close();
@@ -374,10 +386,10 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized Iterator<Entry> iterator() {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
- List<Entry> list = new ArrayList<Entry>();
- Iterator<Entry> i = index.iterator();
+ final List<Entry> list = new ArrayList<>();
+ final Iterator<Entry> i = index.iterator();
while (i.hasNext()) list.add(i.next());
index.close();
return list.iterator();
@@ -385,14 +397,14 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized CloneableIterator<Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
- final List<Entry> list = new ArrayList<Entry>();
+ final List<Entry> list = new ArrayList<>();
final Iterator<Entry> i = index.rows(up, firstKey);
while (i.hasNext()) list.add(i.next());
index.close();
final Iterator<Entry> li = list.iterator();
- return new CloneableIterator<Entry>(){
+ return new CloneableIterator<>(){
@Override
public boolean hasNext() {
return li.hasNext();
@@ -417,14 +429,14 @@ public class OnDemandOpenFileIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized CloneableIterator<Entry> rows() throws IOException {
- Index index = getIndex();
+ final Index index = this.getIndex();
if (index == null) return null;
- final List<Entry> list = new ArrayList<Entry>();
+ final List<Entry> list = new ArrayList<>();
final Iterator<Entry> i = index.rows();
while (i.hasNext()) list.add(i.next());
index.close();
final Iterator<Entry> li = list.iterator();
- return new CloneableIterator<Entry>(){
+ return new CloneableIterator<>(){
@Override
public boolean hasNext() {
return li.hasNext();
diff --git a/source/net/yacy/kelondro/index/RAMIndex.java b/source/net/yacy/kelondro/index/RAMIndex.java
index 5548e1e08..0913d87e1 100644
--- a/source/net/yacy/kelondro/index/RAMIndex.java
+++ b/source/net/yacy/kelondro/index/RAMIndex.java
@@ -55,7 +55,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
this.name = name;
this.rowdef = rowdef;
this.entryComparator = new Row.EntryComparator(rowdef.objectOrder);
- reset();
+ this.reset();
objectTracker.put(name, this);
}
@@ -79,7 +79,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
@Override
public void clear() {
- reset();
+ this.reset();
}
@Override
@@ -138,7 +138,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
@Override
public final synchronized Row.Entry get(final byte[] key, final boolean forceclone) {
assert (key != null);
- finishInitialization();
+ this.finishInitialization();
assert this.index0.isSorted();
final Row.Entry indexentry = this.index0.get(key, forceclone);
if (indexentry != null) return indexentry;
@@ -146,29 +146,40 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public final synchronized boolean has(final byte[] key) {
- assert (key != null);
- finishInitialization();
+ assert (key != null);
+ this.finishInitialization();
assert this.index0.isSorted();
if (this.index0.has(key)) return true;
return this.index1.has(key);
- }
+ }
- @Override
+ @Override
public final synchronized Row.Entry replace(final Row.Entry entry) throws SpaceExceededException {
assert (entry != null);
- finishInitialization();
+ this.finishInitialization();
// if the new entry is within the initialization part, just overwrite it
assert this.index0.isSorted();
final byte[] key = entry.getPrimaryKeyBytes();
@@ -192,7 +203,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
assert (entry != null);
if (entry == null) return true;
synchronized (this) {
- finishInitialization();
+ this.finishInitialization();
// if the new entry is within the initialization part, just overwrite it
assert this.index0.isSorted();
final byte[] key = entry.getPrimaryKeyBytes();
@@ -223,12 +234,12 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
public final void addUnique(final List<Entry> rows) throws SpaceExceededException {
final Iterator<Entry> i = rows.iterator();
- while (i.hasNext()) addUnique(i.next());
+ while (i.hasNext()) this.addUnique(i.next());
}
public final synchronized long inc(final byte[] key, final int col, final long add, final Row.Entry initrow) throws SpaceExceededException {
assert (key != null);
- finishInitialization();
+ this.finishInitialization();
assert this.index0.isSorted();
final long l = this.index0.inc(key, col, add, null);
if (l != Long.MIN_VALUE) return l;
@@ -250,7 +261,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
@Override
public final synchronized boolean delete(final byte[] key) {
- finishInitialization();
+ this.finishInitialization();
// if the new entry is within the initialization part, just delete it
boolean b = this.index0.delete(key);
if (b) {
@@ -265,7 +276,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
@Override
public final synchronized Row.Entry remove(final byte[] key) {
- finishInitialization();
+ this.finishInitialization();
// if the new entry is within the initialization part, just delete it
int s = this.index0.size();
final Row.Entry indexentry = this.index0.remove(key);
@@ -295,17 +306,17 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
@Override
public synchronized List<Row.Entry> top(final int count) throws IOException {
- final List<Row.Entry> list = new ArrayList<Row.Entry>();
+ final List<Row.Entry> list = new ArrayList<>();
List<Row.Entry> list0 = this.index1.top(count);
list.addAll(list0);
list0 = this.index0.top(count - list.size());
list.addAll(list0);
return list;
}
-
+
@Override
public synchronized List<Row.Entry> random(final int count) throws IOException {
- final List<Row.Entry> list = new ArrayList<Row.Entry>();
+ final List<Row.Entry> list = new ArrayList<>();
List<Row.Entry> list0 = this.index1.random(count);
list.addAll(list0);
list0 = this.index0.random(count - list.size());
@@ -374,7 +385,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
final CloneableIterator<byte[]> k1 = this.index1.keys(up, firstKey);
if (k0 == null) return k1;
if (k1 == null) return k0;
- return new MergeIterator<byte[]>(
+ return new MergeIterator<>(
k0,
k1,
this.rowdef.objectOrder,
@@ -405,7 +416,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
final CloneableIterator<Row.Entry> k1 = this.index1.rows(up, firstKey);
if (k0 == null) return k1;
if (k1 == null) return k0;
- return new MergeIterator<Row.Entry>(
+ return new MergeIterator<>(
k0,
k1,
this.entryComparator,
@@ -415,7 +426,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
@Override
public final Iterator<Entry> iterator() {
- return rows();
+ return this.rows();
}
@Override
@@ -437,7 +448,7 @@ public final class RAMIndex implements Index, Iterable<Row.Entry> {
// sort index1 to enable working of the merge iterator
//index1.sort();
//assert consistencyAnalysis0() : "consistency problem: " + consistencyAnalysis();
- return new StackIterator<Row.Entry>(this.index0.rows(), this.index1.rows(), null, true);
+ return new StackIterator<>(this.index0.rows(), this.index1.rows(), null, true);
}
@Override
diff --git a/source/net/yacy/kelondro/index/RAMIndexCluster.java b/source/net/yacy/kelondro/index/RAMIndexCluster.java
index 993ecfa1f..d2886f741 100644
--- a/source/net/yacy/kelondro/index/RAMIndexCluster.java
+++ b/source/net/yacy/kelondro/index/RAMIndexCluster.java
@@ -27,6 +27,7 @@ package net.yacy.kelondro.index;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
@@ -54,9 +55,7 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
this.name = name;
this.cluster = new RAMIndex[clusterSize];
this.rowdef = rowdef;
- for (int i = 0; i < this.cluster.length; i++) {
- this.cluster[i] = null; // lazy initialization, the actual initialization is at accessArray()
- }
+ Arrays.fill(this.cluster, null);
}
private RAMIndexCluster(final String name, final Row rowdef, final RAMIndex[] array) {
@@ -127,14 +126,14 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@Override
public final void addUnique(final Entry row) throws SpaceExceededException {
- final int i = indexFor(row);
+ final int i = this.indexFor(row);
assert i >= 0 : "i = " + i;
if (i < 0) return;
- accessArray(i).addUnique(row);
+ this.accessArray(i).addUnique(row);
}
public final void addUnique(final List<Entry> rows) throws SpaceExceededException {
- for (final Entry row: rows) addUnique(row);
+ for (final Entry row: rows) this.addUnique(row);
}
@Override
@@ -169,7 +168,7 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@Override
public final Entry get(final byte[] key, final boolean forcecopy) {
- final int i = indexFor(key);
+ final int i = this.indexFor(key);
if (i < 0) return null;
final RAMIndex r = this.cluster[i];
if (r == null) return null;
@@ -177,20 +176,32 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public final boolean has(final byte[] key) {
- final int i = indexFor(key);
+ final int i = this.indexFor(key);
if (i < 0) return false;
final RAMIndex r = this.cluster[i];
if (r == null) return false;
@@ -200,7 +211,7 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@Override
public final CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
synchronized (this.cluster) {
- final Collection<CloneableIterator<byte[]>> col = new ArrayList<CloneableIterator<byte[]>>();
+ final Collection<CloneableIterator<byte[]>> col = new ArrayList<>();
for (final RAMIndex element : this.cluster) {
if (element != null) {
col.add(element.keys(up, firstKey));
@@ -219,29 +230,29 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
*/
@Override
public final boolean put(final Entry row) throws SpaceExceededException {
- final int i = indexFor(row);
+ final int i = this.indexFor(row);
assert i >= 0 : "i = " + i;
if (i < 0) return true;
- return accessArray(i).put(row);
+ return this.accessArray(i).put(row);
}
@Override
public final boolean delete(final byte[] key) {
- final int i = indexFor(key);
+ final int i = this.indexFor(key);
if (i < 0) return false;
- return accessArray(i).delete(key);
+ return this.accessArray(i).delete(key);
}
@Override
public final Entry remove(final byte[] key) {
- final int i = indexFor(key);
+ final int i = this.indexFor(key);
if (i < 0) return null;
- return accessArray(i).remove(key);
+ return this.accessArray(i).remove(key);
}
@Override
public final ArrayList<RowCollection> removeDoubles() throws SpaceExceededException {
- final ArrayList<RowCollection> col = new ArrayList<RowCollection>();
+ final ArrayList<RowCollection> col = new ArrayList<>();
synchronized (this.cluster) {
for (int i = 0; i < this.cluster.length; i++) {
if (this.cluster[i] != null) {
@@ -269,7 +280,7 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@Override
public List<Row.Entry> top(final int count) {
- final List<Row.Entry> list = new ArrayList<Row.Entry>();
+ final List<Row.Entry> list = new ArrayList<>();
synchronized (this.cluster) {
for (final RAMIndex element : this.cluster) {
if (element != null) {
@@ -288,7 +299,7 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@Override
public List<Row.Entry> random(final int count) {
- final List<Row.Entry> list = new ArrayList<Row.Entry>();
+ final List<Row.Entry> list = new ArrayList<>();
synchronized (this.cluster) {
for (final RAMIndex element : this.cluster) {
if (element != null) {
@@ -307,10 +318,10 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@Override
public final Entry replace(final Entry row) throws SpaceExceededException {
- final int i = indexFor(row);
+ final int i = this.indexFor(row);
assert i >= 0 : "i = " + i;
if (i < 0) return null;
- return accessArray(i).replace(row);
+ return this.accessArray(i).replace(row);
}
@Override
@@ -322,28 +333,23 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
@SuppressWarnings("unchecked")
public final CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) {
synchronized (this.cluster) {
- final List<CloneableIterator<Row.Entry>> col = new ArrayList<CloneableIterator<Row.Entry>>(this.cluster.length);
- for (RAMIndex element : this.cluster) {
+ final List<CloneableIterator<Row.Entry>> col = new ArrayList<>(this.cluster.length);
+ for (final RAMIndex element : this.cluster) {
if (element != null) {
col.add(element.rows(up, firstKey));
}
}
- return StackIterator.stack(col.toArray((CloneableIterator<Row.Entry>[]) Array.newInstance(CloneableIterator.class, col.size())), getEntryComparator(), up);
+ return StackIterator.stack(col.toArray((CloneableIterator<Row.Entry>[]) Array.newInstance(CloneableIterator.class, col.size())), this.getEntryComparator(), up);
}
}
-
+
private Comparator<Row.Entry> getEntryComparator() {
- return new Comparator<Row.Entry>() {
- @Override
- public int compare(Row.Entry o1, Row.Entry o2) {
- return RAMIndexCluster.this.rowdef.objectOrder.compare(o1.getPrimaryKeyBytes(), o2.getPrimaryKeyBytes());
- }
- };
+ return (o1, o2) -> RAMIndexCluster.this.rowdef.objectOrder.compare(o1.getPrimaryKeyBytes(), o2.getPrimaryKeyBytes());
}
@Override
public final CloneableIterator<Row.Entry> rows() {
- return rows(true, null);
+ return this.rows(true, null);
}
@Override
@@ -372,8 +378,8 @@ public final class RAMIndexCluster implements Index, Iterable<Row.Entry>, Clonea
}
public final long inc(final byte[] key, final int col, final long add, final Entry initrow) throws SpaceExceededException {
- final int i = indexFor(key);
+ final int i = this.indexFor(key);
if (i < 0) return -1;
- return accessArray(i).inc(key, col, add, initrow);
+ return this.accessArray(i).inc(key, col, add, initrow);
}
}
diff --git a/source/net/yacy/kelondro/index/RowSet.java b/source/net/yacy/kelondro/index/RowSet.java
index bab44d758..6fc745c54 100644
--- a/source/net/yacy/kelondro/index/RowSet.java
+++ b/source/net/yacy/kelondro/index/RowSet.java
@@ -26,6 +26,7 @@ package net.yacy.kelondro.index;
import java.io.IOException;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
@@ -132,29 +133,40 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
@Override
public final synchronized boolean has(final byte[] key) {
assert key.length == this.rowdef.primaryKeyLength;
- final int index = find(key, 0);
+ final int index = this.find(key, 0);
return index >= 0;
}
@Override
public final synchronized Row.Entry get(final byte[] key, final boolean forcecopy) {
assert key.length == this.rowdef.primaryKeyLength;
- final int index = find(key, 0);
+ final int index = this.find(key, 0);
if (index < 0) return null;
- return get(index, forcecopy);
+ return this.get(index, forcecopy);
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
/**
* Adds the row to the index. The row is identified by the primary key of the row.
* @param entry a index row
@@ -170,13 +182,13 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
final byte[] entrybytes = entry.bytes();
assert entrybytes.length >= this.rowdef.primaryKeyLength;
synchronized (this) {
- final int index = find(key, 0);
+ final int index = this.find(key, 0);
if (index < 0) {
super.addUnique(entry);
return true;
}
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.set(index, entry); // this may alter the sortBound, which we will revert in the next step
this.sortBound = sb; // revert a sortBound altering
return false;
}
@@ -185,7 +197,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
private final int collectionReSortLimit() {
return Math.min(3000, Math.max(100, this.chunkcount / 3));
}
-
+
@Override
public final Row.Entry replace(final Row.Entry entry) throws SpaceExceededException {
assert (entry != null);
@@ -197,16 +209,16 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
int index = -1;
Row.Entry oldentry = null;
// when reaching a specific amount of un-sorted entries, re-sort all
- if ((this.chunkcount - this.sortBound) > collectionReSortLimit()) {
- sort();
+ if ((this.chunkcount - this.sortBound) > this.collectionReSortLimit()) {
+ this.sort();
}
- index = find(key, 0);
+ index = this.find(key, 0);
if (index < 0) {
super.addUnique(entry);
} else {
- oldentry = get(index, true);
+ oldentry = this.get(index, true);
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.set(index, entry); // this may alter the sortBound, which we will revert in the next step
this.sortBound = sb; // revert a sortBound altering
}
return oldentry;
@@ -215,12 +227,12 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
public final synchronized long inc(final byte[] key, final int col, final long add, final Row.Entry initrow) throws SpaceExceededException {
assert key.length == this.rowdef.primaryKeyLength;
- final int index = find(key, 0);
+ final int index = this.find(key, 0);
if (index >= 0) {
// the entry existed before
- final Row.Entry entry = get(index, false); // no clone necessary
+ final Row.Entry entry = this.get(index, false); // no clone necessary
final long l = entry.incCol(col, add);
- set(index, entry);
+ this.set(index, entry);
return l;
} else if (initrow != null) {
// create new entry
@@ -244,7 +256,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
int index;
assert a.length == this.rowdef.primaryKeyLength;
while (true) {
- index = find(a, 0);
+ index = this.find(a, 0);
if (index < 0) {
return exists;
}
@@ -257,7 +269,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
public final synchronized void delete(final List<byte[]> keys) {
final int[] indexes = new int[keys.size()];
for (int i = 0; i < keys.size(); i++) {
- indexes[i] = find(keys.get(i), 0);
+ indexes[i] = this.find(keys.get(i), 0);
}
// we will delete the entries in backward order
// That means it is necessary that the order below the indexes is stable
@@ -275,7 +287,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
int index;
assert a.length == this.rowdef.primaryKeyLength;
while (true) {
- index = find(a, 0);
+ index = this.find(a, 0);
if (index < 0) {
return entry;
}
@@ -287,10 +299,10 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
private final int find(final byte[] a, final int astart) {
// returns the chunknumber; -1 if not found
- if (this.rowdef.objectOrder == null) return iterativeSearch(a, astart, 0, this.chunkcount);
+ if (this.rowdef.objectOrder == null) return this.iterativeSearch(a, astart, 0, this.chunkcount);
- if ((this.chunkcount - this.sortBound) > collectionReSortLimit()) {
- sort();
+ if ((this.chunkcount - this.sortBound) > this.collectionReSortLimit()) {
+ this.sort();
}
if (this.rowdef.objectOrder != null && this.rowdef.objectOrder instanceof Base64Order) {
@@ -299,18 +311,18 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
}
// first try to find in sorted area
- final int p = binarySearch(a, astart);
+ final int p = this.binarySearch(a, astart);
if (p >= 0) return p;
// then find in unsorted area
- return iterativeSearch(a, astart, this.sortBound, this.chunkcount);
+ return this.iterativeSearch(a, astart, this.sortBound, this.chunkcount);
}
private final int iterativeSearch(final byte[] key, final int astart, final int leftBorder, final int rightBound) {
// returns the chunknumber
for (int i = leftBorder; i < rightBound; i++) {
assert key.length - astart >= this.rowdef.primaryKeyLength;
- if (match(key, astart, i)) return i;
+ if (this.match(key, astart, i)) return i;
}
return -1;
}
@@ -326,7 +338,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
while (l < rbound) {
p = (l + rbound) >> 1;
assert key.length - astart >= this.rowdef.primaryKeyLength;
- d = compare(key, astart, p);
+ d = this.compare(key, astart, p);
if (d == 0) return p;
if (d < 0) rbound = p; else l = p + 1;
}
@@ -345,7 +357,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
while (l < rbound) {
p = (l + rbound) >> 1;
assert key.length - astart >= this.rowdef.primaryKeyLength;
- d = compare(key, astart, p);
+ d = this.compare(key, astart, p);
if (d == 0) return p;
if (d < 0) rbound = p; else l = p + 1;
}
@@ -353,7 +365,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
}
public final synchronized Iterator<byte[]> keys() {
- sort();
+ this.sort();
return super.keys(true);
}
@@ -372,7 +384,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
public keyIterator(final boolean up, byte[] firstKey) {
// see that all elements are sorted
- sort();
+ RowSet.this.sort();
this.up = up;
if (firstKey != null && firstKey.length == 0) firstKey = null;
this.first = firstKey;
@@ -381,7 +393,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
this.p = up ? 0 : this.bound - 1;
} else {
assert this.first.length == RowSet.this.rowdef.primaryKeyLength : "first.length = " + this.first.length + ", rowdef.primaryKeyLength = " + RowSet.this.rowdef.primaryKeyLength;
- this.p = up ? binaryPosition(this.first, 0) : this.bound - 1; // check this to find bug in DHT selection enumeration
+ this.p = up ? RowSet.this.binaryPosition(this.first, 0) : this.bound - 1; // check this to find bug in DHT selection enumeration
}
}
@@ -393,13 +405,13 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
@Override
public final boolean hasNext() {
if (this.p < 0) return false;
- if (this.p >= size()) return false;
+ if (this.p >= RowSet.this.size()) return false;
return (this.up) ? this.p < this.bound : this.p >= 0;
}
@Override
public final byte[] next() {
- final byte[] key = getKey(this.p);
+ final byte[] key = RowSet.this.getKey(this.p);
if (this.up) this.p++; else this.p--;
return key;
}
@@ -417,7 +429,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
@Override
public final synchronized Iterator<Row.Entry> iterator() {
// iterates kelondroRow.Entry - type entries
- sort();
+ this.sort();
return super.iterator();
}
@@ -440,7 +452,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
public rowIterator(final boolean up, final byte[] firstKey) {
// see that all elements are sorted
- sort();
+ RowSet.this.sort();
this.up = up;
this.first = firstKey;
this.bound = RowSet.this.sortBound;
@@ -448,7 +460,7 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
this.p = 0;
} else {
assert this.first.length == RowSet.this.rowdef.primaryKeyLength;
- this.p = binaryPosition(this.first, 0); // check this to find bug in DHT selection enumeration
+ this.p = RowSet.this.binaryPosition(this.first, 0); // check this to find bug in DHT selection enumeration
}
}
@@ -460,13 +472,13 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>,
@Override
public final boolean hasNext() {
if (this.p < 0) return false;
- if (this.p >= size()) return false;
+ if (this.p >= RowSet.this.size()) return false;
return (this.up) ? this.p < this.bound : this.p >= 0;
}
@Override
public final Row.Entry next() {
- final Row.Entry entry = get(this.p, true);
+ final Row.Entry entry = RowSet.this.get(this.p, true);
if (this.up) this.p++; else this.p--;
return entry;
}
diff --git a/source/net/yacy/kelondro/table/SQLTable.java b/source/net/yacy/kelondro/table/SQLTable.java
index 294e55f5f..ec2c567b5 100644
--- a/source/net/yacy/kelondro/table/SQLTable.java
+++ b/source/net/yacy/kelondro/table/SQLTable.java
@@ -211,7 +211,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
@@ -221,6 +221,17 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public Row.Entry replace(final Row.Entry row) throws IOException {
try {
diff --git a/source/net/yacy/kelondro/table/SplitTable.java b/source/net/yacy/kelondro/table/SplitTable.java
index 6f6ec1a07..20b20a943 100644
--- a/source/net/yacy/kelondro/table/SplitTable.java
+++ b/source/net/yacy/kelondro/table/SplitTable.java
@@ -105,14 +105,14 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
this.useTailCache = useTailCache;
this.exceed134217727 = exceed134217727;
this.entryOrder = new Row.EntryComparator(rowdef.objectOrder);
- init();
+ this.init();
}
@Override
public void optimize() {
- for (Index table: tables.values()) table.optimize();
+ for (final Index table: this.tables.values()) table.optimize();
}
-
+
@Override
public long mem() {
long m = 0;
@@ -150,7 +150,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
this.current = null;
// initialized tables map
- this.tables = new HashMap<String, Index>();
+ this.tables = new HashMap<>();
if (!(this.path.exists())) this.path.mkdirs();
String[] tablefile = this.path.list();
@@ -170,7 +170,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
tablefile = this.path.list();
// first pass: find tables
- final HashMap<String, Long> t = new HashMap<String, Long>();
+ final HashMap<String, Long> t = new HashMap<>();
long ram, time, maxtime = 0;
Date d;
for (final String element : tablefile) {
@@ -200,7 +200,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
Map.Entry<String, Long> entry;
String maxf;
long maxram;
- final List<Thread> warmingUp = new ArrayList<Thread>(); // for concurrent warming up
+ final List<Thread> warmingUp = new ArrayList<>(); // for concurrent warming up
maxfind: while (!t.isEmpty()) {
// find maximum table
maxram = 0;
@@ -258,7 +258,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public void clear() throws IOException {
- close();
+ this.close();
final String[] l = this.path.list();
for (final String element : l) {
if (element.startsWith(this.prefix)) {
@@ -266,7 +266,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
if (f.isDirectory()) delete(this.path, element); else FileUtils.deletedelete(f);
}
}
- init();
+ this.init();
}
public static void delete(final File path, final String tablename) {
@@ -321,12 +321,12 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public boolean has(final byte[] key) {
- return keeperOf(key) != null;
+ return this.keeperOf(key) != null;
}
@Override
public Row.Entry get(final byte[] key, final boolean forcecopy) throws IOException {
- final Index keeper = keeperOf(key);
+ final Index keeper = this.keeperOf(key);
if (keeper == null) return null;
synchronized (this) { // avoid concurrent IO from different methods
return keeper.get(key, forcecopy);
@@ -334,18 +334,29 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
}
@Override
- public Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
private Index newTable() {
- this.current = newFilename();
+ this.current = this.newFilename();
final File f = new File(this.path, this.current);
Table table = null;
try {
@@ -366,7 +377,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
// check size and age of given table; in case it is too large or too old
// create a new table
assert table != null;
- long t = System.currentTimeMillis();
+ final long t = System.currentTimeMillis();
if (((t / 1000) % 10) != 0) return table; // we check only every 10 seconds because all these file and parser operations are very expensive
final String name = new File(table.filename()).getName();
long d;
@@ -377,7 +388,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
d = 0;
}
if (d + this.fileAgeLimit < t || new File(this.path, name).length() >= this.fileSizeLimit) {
- return newTable();
+ return this.newTable();
}
return table;
}
@@ -385,13 +396,13 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public Row.Entry replace(final Row.Entry row) throws IOException, SpaceExceededException {
assert row.objectsize() <= this.rowdef.objectsize;
- Index keeper = keeperOf(row.getPrimaryKeyBytes());
+ Index keeper = this.keeperOf(row.getPrimaryKeyBytes());
if (keeper != null) synchronized (this) { // avoid concurrent IO from different methods
return keeper.replace(row);
}
synchronized (this) {
assert this.current == null || this.tables.get(this.current) != null : "this.current = " + this.current;
- keeper = (this.current == null) ? newTable() : checkTable(this.tables.get(this.current));
+ keeper = (this.current == null) ? this.newTable() : this.checkTable(this.tables.get(this.current));
}
keeper.put(row);
return null;
@@ -409,15 +420,15 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
assert row.objectsize() <= this.rowdef.objectsize;
final byte[] key = row.getPrimaryKeyBytes();
if (this.tables == null) return true;
- Index keeper = keeperOf(key);
+ Index keeper = this.keeperOf(key);
if (keeper != null) synchronized (this) { // avoid concurrent IO from different methods
return keeper.put(row);
}
synchronized (this) {
- keeper = keeperOf(key); // we must check that again because it could have changed in between
+ keeper = this.keeperOf(key); // we must check that again because it could have changed in between
if (keeper != null) return keeper.put(row);
assert this.current == null || this.tables.get(this.current) != null : "this.current = " + this.current;
- keeper = (this.current == null) ? newTable() : checkTable(this.tables.get(this.current));
+ keeper = (this.current == null) ? this.newTable() : this.checkTable(this.tables.get(this.current));
final boolean b = keeper.put(row);
assert b;
return b;
@@ -439,7 +450,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
Index keeper = (this.current == null) ? null : this.tables.get(this.current);
synchronized (this) {
assert this.current == null || this.tables.get(this.current) != null : "this.current = " + this.current;
- if (keeper == null) keeper = newTable(); else keeper = checkTable(keeper);
+ if (keeper == null) keeper = this.newTable(); else keeper = this.checkTable(keeper);
}
keeper.addUnique(row);
}
@@ -447,7 +458,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public List<RowCollection> removeDoubles() throws IOException, SpaceExceededException {
final Iterator<Index> i = this.tables.values().iterator();
- final List<RowCollection> report = new ArrayList<RowCollection>();
+ final List<RowCollection> report = new ArrayList<>();
while (i.hasNext()) {
report.addAll(i.next().removeDoubles());
}
@@ -456,7 +467,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public boolean delete(final byte[] key) throws IOException {
- final Index table = keeperOf(key);
+ final Index table = this.keeperOf(key);
if (table == null) return false;
synchronized (this) { // avoid concurrent IO from different methods
return table.delete(key);
@@ -465,7 +476,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public Row.Entry remove(final byte[] key) throws IOException {
- final Index table = keeperOf(key);
+ final Index table = this.keeperOf(key);
if (table == null) return null;
synchronized (this) { // avoid concurrent IO from different methods
return table.remove(key);
@@ -534,7 +545,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
- final List<CloneableIterator<byte[]>> c = new ArrayList<CloneableIterator<byte[]>>(this.tables.size());
+ final List<CloneableIterator<byte[]>> c = new ArrayList<>(this.tables.size());
final Iterator<Index> i = this.tables.values().iterator();
CloneableIterator<byte[]> k;
while (i.hasNext()) {
@@ -546,7 +557,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
- final List<CloneableIterator<Row.Entry>> c = new ArrayList<CloneableIterator<Row.Entry>>(this.tables.size());
+ final List<CloneableIterator<Row.Entry>> c = new ArrayList<>(this.tables.size());
final Iterator<Index> i = this.tables.values().iterator();
while (i.hasNext()) {
c.add(i.next().rows(up, firstKey));
@@ -557,7 +568,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
@Override
public Iterator<Entry> iterator() {
try {
- return rows();
+ return this.rows();
} catch (final IOException e) {
return null;
}
diff --git a/source/net/yacy/kelondro/table/Table.java b/source/net/yacy/kelondro/table/Table.java
index f4061e4f5..45d23bb30 100644
--- a/source/net/yacy/kelondro/table/Table.java
+++ b/source/net/yacy/kelondro/table/Table.java
@@ -74,7 +74,7 @@ public class Table implements Index, Iterable<Row.Entry> {
private final static ConcurrentLog log = new ConcurrentLog("KELONDRO TABLE");
/** Map all active table instances by file name */
- private final static Map<String, Table> tableTracker = new ConcurrentSkipListMap<String, Table>();
+ private final static Map<String, Table> tableTracker = new ConcurrentSkipListMap<>();
private final static long maxarraylength = 134217727L; // (2^27-1) that may be the maximum size of array length in some JVMs
private final long minmemremaining; // if less than this memory is remaininig, the memory copy of a table is abandoned
@@ -183,7 +183,7 @@ public class Table implements Index, Iterable<Row.Entry> {
if(ki.hasNext()) {
try {
ki.close();
- } catch(IOException ioe) {
+ } catch(final IOException ioe) {
/* Do not block if closing is not possible but anyway keep a trace in log */
log.warn("Could not close input stream on the file " + tablefile);
}
@@ -228,14 +228,14 @@ public class Table implements Index, Iterable<Row.Entry> {
if(ri.hasNext()) {
try {
ri.close();
- } catch(IOException ioe) {
+ } catch(final IOException ioe) {
/* Do not block if closing is not possible but anyway keep a trace in log */
log.warn("Could not close input stream on the file " + tablefile);
}
}
}
Runtime.getRuntime().gc();
- if (abandonTable()) {
+ if (this.abandonTable()) {
this.table = null;
}
}
@@ -243,7 +243,7 @@ public class Table implements Index, Iterable<Row.Entry> {
// open the file
this.file = new BufferedRecords(new Records(tablefile, rowdef.objectsize), this.buffersize);
- assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size() + ", file = " + filename();
+ assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size() + ", file = " + this.filename();
// clean up the file by cleaning badly formed entries
final int errorc = errors.size();
@@ -251,16 +251,16 @@ public class Table implements Index, Iterable<Row.Entry> {
int idx;
for (final Map.Entry<byte[], Long> entry: errors) {
idx = (int) entry.getValue().longValue();
- removeInFile(idx);
+ this.removeInFile(idx);
key = entry.getKey();
if (key == null) continue;
log.warn("removing not well-formed entry " + idx + " with key: " + NaturalOrder.arrayList(key, 0, key.length) + ", " + errorcc++ + "/" + errorc);
}
errors.close();
- assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size() + ", file = " + filename();
+ assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size() + ", file = " + this.filename();
// warm up
- if (!freshFile && warmUp) {warmUp0();}
+ if (!freshFile && warmUp) {this.warmUp0();}
} catch (final FileNotFoundException e) {
// should never happen
log.severe("", e);
@@ -275,7 +275,7 @@ public class Table implements Index, Iterable<Row.Entry> {
}
public synchronized void warmUp() {
- warmUp0();
+ this.warmUp0();
}
private final void warmUp0() {
@@ -285,7 +285,7 @@ public class Table implements Index, Iterable<Row.Entry> {
//assert index.size() + doubles.size() == i;
//System.out.println(" -removed " + doubles.size() + " doubles- done.");
if (doubles.isEmpty()) return;
- log.info(filename() + ": WARNING - TABLE " + filename() + " has " + doubles.size() + " doubles");
+ log.info(this.filename() + ": WARNING - TABLE " + this.filename() + " has " + doubles.size() + " doubles");
// from all the doubles take one, put it back to the index and remove the others from the file
// first put back one element each
final byte[] record = new byte[this.rowdef.objectsize];
@@ -297,7 +297,7 @@ public class Table implements Index, Iterable<Row.Entry> {
}
// then remove the other doubles by removing them from the table, but do a re-indexing while doing that
// first aggregate all the delete positions because the elements from the top positions must be removed first
- final TreeSet<Long> delpos = new TreeSet<Long>();
+ final TreeSet<Long> delpos = new TreeSet<>();
for (final long[] ds: doubles) {
for (int j = 1; j < ds.length; j++) delpos.add(ds[j]);
}
@@ -306,14 +306,14 @@ public class Table implements Index, Iterable<Row.Entry> {
while (!delpos.isEmpty()) {
top = delpos.last();
delpos.remove(top);
- removeInFile(top.intValue());
+ this.removeInFile(top.intValue());
}
} catch (final SpaceExceededException e) {
log.severe("", e);
} catch (final IOException e) {
log.severe("", e);
}
- optimize();
+ this.optimize();
}
@Override
@@ -445,7 +445,7 @@ public class Table implements Index, Iterable<Row.Entry> {
synchronized (this) {
assert this.table == null || this.table.size() == this.index.size() : "table.size() = " + this.table.size() + ", index.size() = " + this.index.size();
}
- TableStatistics stats = new TableStatistics();
+ final TableStatistics stats = new TableStatistics();
if (this.index == null) return stats; // possibly closed or being closed
stats.tableSize = this.index.size();
if(this.index instanceof RowHandleMap) {
@@ -498,7 +498,7 @@ public class Table implements Index, Iterable<Row.Entry> {
} catch (final SpaceExceededException e) {
this.table = null;
}
- if (abandonTable()) this.table = null;
+ if (this.abandonTable()) this.table = null;
}
this.file.add(rowbytes, 0);
assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size();
@@ -508,11 +508,11 @@ public class Table implements Index, Iterable<Row.Entry> {
assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size();
for (final Entry entry: rows) {
try {
- addUnique(entry);
+ this.addUnique(entry);
} catch (final SpaceExceededException e) {
if (this.table == null) throw e;
this.table = null;
- addUnique(entry);
+ this.addUnique(entry);
}
}
assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size();
@@ -528,9 +528,9 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public synchronized List<RowCollection> removeDoubles() throws IOException, SpaceExceededException {
assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size();
- final List<RowCollection> report = new ArrayList<RowCollection>();
+ final List<RowCollection> report = new ArrayList<>();
RowSet rows;
- final TreeSet<Long> d = new TreeSet<Long>();
+ final TreeSet<Long> d = new TreeSet<>();
final byte[] b = new byte[this.rowdef.objectsize];
Row.Entry inconsistentEntry;
// iterate over all entries that have inconsistent index references
@@ -568,9 +568,9 @@ public class Table implements Index, Iterable<Row.Entry> {
while (!d.isEmpty()) {
s = d.last();
d.remove(s);
- removeInFile(s.intValue());
+ this.removeInFile(s.intValue());
if (System.currentTimeMillis() - lastlog > 30000) {
- log.info("removing " + d.size() + " entries in " + filename());
+ log.info("removing " + d.size() + " entries in " + this.filename());
lastlog = System.currentTimeMillis();
}
}
@@ -601,12 +601,12 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public Entry get(final byte[] key, final boolean _forcecopy) throws IOException {
if (this.file == null || this.index == null) return null;
- Entry e = get0(key);
+ Entry e = this.get0(key);
if (e != null && this.rowdef.objectOrder.equal(key, e.getPrimaryKeyBytes())) return e;
synchronized (this) {
//assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size() + ", file = " + filename();
- assert this.table == null || this.table.size() == this.index.size() : "table.size() = " + this.table.size() + ", index.size() = " + this.index.size() + ", file = " + filename();
- e = get0(key);
+ assert this.table == null || this.table.size() == this.index.size() : "table.size() = " + this.table.size() + ", index.size() = " + this.index.size() + ", file = " + this.filename();
+ e = this.get0(key);
assert e == null || this.rowdef.objectOrder.equal(key, e.getPrimaryKeyBytes()) : "key = " + ASCII.String(key) + ", e.k = " + ASCII.String(e.getPrimaryKeyBytes());
return e;
}
@@ -639,16 +639,27 @@ public class Table implements Index, Iterable<Row.Entry> {
}
@Override
- public final Map<byte[], Row.Entry> get(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ public final Map<byte[], Row.Entry> getMap(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final Map<byte[], Row.Entry> map = new TreeMap<>(this.row().objectOrder);
Row.Entry entry;
for (final byte[] key: keys) {
- entry = get(key, forcecopy);
+ entry = this.get(key, forcecopy);
if (entry != null) map.put(key, entry);
}
return map;
}
+ @Override
+ public final List<Row.Entry> getList(final Collection<byte[]> keys, final boolean forcecopy) throws IOException, InterruptedException {
+ final List<Row.Entry> list = new ArrayList<>(keys.size());
+ Row.Entry entry;
+ for (final byte[] key: keys) {
+ entry = this.get(key, forcecopy);
+ if (entry != null) list.add(entry);
+ }
+ return list;
+ }
+
@Override
public final boolean has(final byte[] key) {
if (this.index == null) return false;
@@ -674,11 +685,11 @@ public class Table implements Index, Iterable<Row.Entry> {
final int i = (int) this.index.get(key);
if (i == -1) {
try {
- addUnique(row);
+ this.addUnique(row);
} catch (final SpaceExceededException e) {
if (this.table == null) throw e;
this.table = null;
- addUnique(row);
+ this.addUnique(row);
}
return null;
}
@@ -701,7 +712,7 @@ public class Table implements Index, Iterable<Row.Entry> {
} catch (final SpaceExceededException e) {
this.table = null;
}
- if (abandonTable()) this.table = null;
+ if (this.abandonTable()) this.table = null;
this.file.put(i, rowb, 0);
}
assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size();
@@ -732,11 +743,11 @@ public class Table implements Index, Iterable<Row.Entry> {
final int i = (int) this.index.get(key);
if (i == -1) {
try {
- addUnique(row);
+ this.addUnique(row);
} catch (final SpaceExceededException e) {
if (this.table == null) throw e;
this.table = null;
- addUnique(row);
+ this.addUnique(row);
}
return true;
}
@@ -747,7 +758,7 @@ public class Table implements Index, Iterable<Row.Entry> {
} else {
// write new value
this.file.put(i, rowb, 0);
- if (abandonTable()) this.table = null; else try {
+ if (this.abandonTable()) this.table = null; else try {
this.table.set(i, this.taildef.newEntry(rowb, this.rowdef.primaryKeyLength, true));
} catch (final SpaceExceededException e) {
this.table = null;
@@ -781,7 +792,7 @@ public class Table implements Index, Iterable<Row.Entry> {
this.file.put(i, p, 0);
final byte[] k = new byte[this.rowdef.primaryKeyLength];
System.arraycopy(p, 0, k, 0, this.rowdef.primaryKeyLength);
- this.index.put(k, i);
+ this.index.putUnique(k, i);
break;
}
}
@@ -810,13 +821,13 @@ public class Table implements Index, Iterable<Row.Entry> {
continue;
}
this.file.put(i, p, 0);
- byte[] pk = lr.getPrimaryKeyBytes();
+ final byte[] pk = lr.getPrimaryKeyBytes();
if (pk == null) {
// Table file might be corrupt
log.warn("Possible corruption found in table " + this.filename() + " detected. i=" + i + ",p=" + p);
continue;
}
- this.index.put(pk, i);
+ this.index.putUnique(pk, i);
break;
}
}
@@ -825,7 +836,7 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public final boolean delete(final byte[] key) throws IOException {
- return remove(key) != null;
+ return this.remove(key) != null;
}
@Override
@@ -953,7 +964,7 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public final List<Row.Entry> top(int count) throws IOException {
if (count > this.size()) count = this.size();
- final ArrayList<Row.Entry> list = new ArrayList<Row.Entry>();
+ final ArrayList<Row.Entry> list = new ArrayList<>();
if (this.file == null || this.index == null || this.size() == 0 || count == 0) return list;
long i = this.file.size() - 1;
while (count > 0 && i >= 0) {
@@ -969,10 +980,10 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public final List<Row.Entry> random(int count) throws IOException {
if (count > this.size()) count = this.size();
- final ArrayList<Row.Entry> list = new ArrayList<Row.Entry>();
+ final ArrayList<Row.Entry> list = new ArrayList<>();
if (this.file == null || this.index == null || this.size() == 0 || count == 0) return list;
long cursor = 0;
- int stepsize = this.size() / count;
+ final int stepsize = this.size() / count;
while (count > 0 && cursor < this.size()) {
final byte[] b = new byte[this.rowdef.objectsize];
this.file.get(cursor, b, 0);
@@ -1010,7 +1021,7 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public final Iterator<Entry> iterator() {
try {
- return rows();
+ return this.rows();
} catch (final IOException e) {
return null;
}
@@ -1051,7 +1062,7 @@ public class Table implements Index, Iterable<Row.Entry> {
if (this.key == null) return null;
this.idx = entry.getValue().longValue();
try {
- return get(this.key, false);
+ return Table.this.get(this.key, false);
} catch (final IOException e) {
return null;
}
@@ -1061,7 +1072,7 @@ public class Table implements Index, Iterable<Row.Entry> {
public final void remove() {
if (this.key != null) {
try {
- removeInFile((int) this.idx);
+ Table.this.removeInFile((int) this.idx);
} catch (final IOException e) {
} catch (final SpaceExceededException e) {
}
@@ -1147,9 +1158,9 @@ public class Table implements Index, Iterable<Row.Entry> {
}
private static String[] permutations(final int letters) {
- String p = "";
- for (int i = 0; i < letters; i++) p = p + ((char) (('A') + i));
- return permutations(p);
+ final StringBuilder p = new StringBuilder();
+ for (int i = 0; i < letters; i++) p.append((char) (('A') + i));
+ return permutations(p.toString());
}
private static String[] permutations(final String source) {
@@ -1231,14 +1242,14 @@ public class Table implements Index, Iterable<Row.Entry> {
}
public void print() throws IOException {
- System.out.println("PRINTOUT of table, length=" + size());
+ System.out.println("PRINTOUT of table, length=" + this.size());
Entry row;
byte[] key;
- final CloneableIterator<byte[]> i = keys(true, null);
+ final CloneableIterator<byte[]> i = this.keys(true, null);
while (i.hasNext()) {
System.out.print("row " + i + ": ");
key = i.next();
- row = get(key, false);
+ row = this.get(key, false);
System.out.println(row.toString());
}
System.out.println("EndOfTable");