Skip to content

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

fixed some newInstance() warnings .. by adding .getDeclaredConstructor()

Michael Peter Christen9ef45036725a
diff --git a/source/net/yacy/cora/order/Base64Order.java b/source/net/yacy/cora/order/Base64Order.java
index 64d3f9ef6..b51a36fbf 100644
--- a/source/net/yacy/cora/order/Base64Order.java
+++ b/source/net/yacy/cora/order/Base64Order.java
@@ -99,7 +99,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
@Override
public final boolean wellformed(final byte[] a) {
- return wellformed(a, 0, a.length);
+ return this.wellformed(a, 0, a.length);
}
@Override
@@ -192,7 +192,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
}
public final String encodeString(final String in) {
- return encode(UTF8.getBytes(in));
+ return this.encode(UTF8.getBytes(in));
}
/**
@@ -203,9 +203,9 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
public final String encode(final byte[] in) {
int rfc1521compliantLength = ((in.length + 2) / 3) * 4; // (bytes/bits/chars) = {(0/0/0), (1/8/4), (2/16/4), (3/24/4), (4/32/8), (5/40/8), (6/48/8), (7/56/12), (8/64/12), (9/72/12), ..}
if (!this.rfc1521compliant) rfc1521compliantLength -= in.length % 3 == 2 ? 1 : in.length % 3 == 1 ? 2 : 0; // non-compliant are shorter (!)
- return ASCII.String(encodeSubstring(in, rfc1521compliantLength));
+ return ASCII.String(this.encodeSubstring(in, rfc1521compliantLength));
}
-
+
public final byte[] encodeSubstring(final byte[] in, final int sublen) {
if (in.length == 0) return new byte[0];
assert sublen <= ((in.length + 2) / 3) * 4 : "sublen = " + sublen + ", expected: " + ((in.length + 2) / 3) * 4;
@@ -214,8 +214,8 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
int pos = 0;
long l;
while (in.length - pos >= 3 && writepos < sublen) {
- l = ((((0XffL & in[pos++]) << 8) | (0XffL & in[pos++])) << 8) | (0XffL & in[pos++]);
- encodeLong(l, out, writepos, 4);
+ l = ((((0XffL & in[pos++]) << 8) | (0XffL & in[pos++])) << 8) | (0XffL & in[pos++]);
+ this.encodeLong(l, out, writepos, 4);
writepos += 4;
}
// now there may be remaining bytes
@@ -237,9 +237,9 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
}
return out;
}
-
+
public final String decodeString(final String in) {
- return UTF8.String(decode(in));
+ return UTF8.String(this.decode(in));
}
final static Pattern cr = Pattern.compile("\n");
@@ -253,7 +253,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
final byte[] out = new byte[in.length() / 4 * 3 + (((in.length() % 4) == 0) ? 0 : in.length() % 4 - 1)];
long l;
while (posIn + 3 < in.length()) {
- l = decodeLong(in.substring(posIn, posIn + 4));
+ l = this.decodeLong(in.substring(posIn, posIn + 4));
out[posOut + 2] = (byte) (l % 256);
l = l / 256;
out[posOut + 1] = (byte) (l % 256);
@@ -265,14 +265,14 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
}
if (posIn < in.length()) {
if (in.length() - posIn == 3) {
- l = decodeLong(in.substring(posIn) + "A");
+ l = this.decodeLong(in.substring(posIn) + "A");
l = l / 256;
out[posOut + 1] = (byte) (l % 256);
l = l / 256;
out[posOut] = (byte) (l % 256);
l = l / 256;
} else {
- l = decodeLong(in.substring(posIn) + "AA");
+ l = this.decodeLong(in.substring(posIn) + "AA");
l = l / 256 / 256;
out[posOut] = (byte) (l % 256);
l = l / 256;
@@ -337,26 +337,26 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
@Override
public final long cardinal(final byte[] key) {
- if (this.zero == null) return cardinalI(key, 0, key.length);
- final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);
- final long keyCardinal = cardinalI(key, 0, key.length);
+ if (this.zero == null) return this.cardinalI(key, 0, key.length);
+ final long zeroCardinal = this.cardinalI(this.zero, 0, this.zero.length);
+ final long keyCardinal = this.cardinalI(key, 0, key.length);
if (keyCardinal > zeroCardinal) return keyCardinal - zeroCardinal;
return Long.MAX_VALUE - keyCardinal + zeroCardinal;
}
@Override
public final long cardinal(final byte[] key, final int off, final int len) {
- if (this.zero == null) return cardinalI(key, off, len);
- final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);
- final long keyCardinal = cardinalI(key, off, len);
+ if (this.zero == null) return this.cardinalI(key, off, len);
+ final long zeroCardinal = this.cardinalI(this.zero, 0, this.zero.length);
+ final long keyCardinal = this.cardinalI(key, off, len);
if (keyCardinal > zeroCardinal) return keyCardinal - zeroCardinal;
return Long.MAX_VALUE - keyCardinal + zeroCardinal;
}
public final long cardinal(final String key) {
- if (this.zero == null) return cardinalI(key);
- final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);
- final long keyCardinal = cardinalI(key);
+ if (this.zero == null) return this.cardinalI(key);
+ final long zeroCardinal = this.cardinalI(this.zero, 0, this.zero.length);
+ final long keyCardinal = this.cardinalI(key);
if (keyCardinal > zeroCardinal) return keyCardinal - zeroCardinal;
return Long.MAX_VALUE - keyCardinal + zeroCardinal;
}
@@ -393,9 +393,9 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
public final int compare(final byte[] a, final byte[] b) {
try {
return (this.asc) ?
- ((this.zero == null) ? compares(a, b) : compare0(a, b, a.length))
+ ((this.zero == null) ? this.compares(a, b) : this.compare0(a, b, a.length))
:
- ((this.zero == null) ? compares(b, a) : compare0(b, a, a.length));
+ ((this.zero == null) ? this.compares(b, a) : this.compare0(b, a, a.length));
} catch (final Throwable e) {
// if a or b is not well-formed, an ArrayIndexOutOfBoundsException may occur
// in that case we don't want that the exception makes databse functions
@@ -403,8 +403,8 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
// a different order on the objects and treat not well-formed objects
// as bigger as all others. If both object are not well-formed, they are
// compared with the natural order.
- final boolean wfa = wellformed(a);
- final boolean wfb = wellformed(b);
+ final boolean wfa = this.wellformed(a);
+ final boolean wfb = this.wellformed(b);
if (wfa && wfb) {
// uh strange. throw the exception
if (e instanceof ArrayIndexOutOfBoundsException) throw (ArrayIndexOutOfBoundsException) e;
@@ -420,13 +420,13 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
public final int compare(final byte[] a, final byte[] b, final int length) {
try {
return (this.asc) ?
- compare0(a, b, length)
+ this.compare0(a, b, length)
:
- compare0(b, a, length);
+ this.compare0(b, a, length);
} catch (final Throwable e) {
// same handling as in simple compare method above
- final boolean wfa = wellformed(a, 0, length);
- final boolean wfb = wellformed(b, 0, length);
+ final boolean wfa = this.wellformed(a, 0, length);
+ final boolean wfb = this.wellformed(b, 0, length);
if (wfa && wfb) {
// uh strange. throw the exception
if (e instanceof ArrayIndexOutOfBoundsException) throw (ArrayIndexOutOfBoundsException) e;
@@ -442,13 +442,13 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
public final int compare(final byte[] a, final int aoffset, final byte[] b, final int boffset, final int length) {
try {
return (this.asc) ?
- compare0(a, aoffset, b, boffset, length)
+ this.compare0(a, aoffset, b, boffset, length)
:
- compare0(b, boffset, a, aoffset, length);
+ this.compare0(b, boffset, a, aoffset, length);
} catch (final Throwable e) {
// same handling as in simple compare method above
- final boolean wfa = wellformed(a, aoffset, length);
- final boolean wfb = wellformed(b, boffset, length);
+ final boolean wfa = this.wellformed(a, aoffset, length);
+ final boolean wfb = this.wellformed(b, boffset, length);
if (wfa && wfb) {
// uh strange. throw the exception
if (e instanceof ArrayIndexOutOfBoundsException) throw (ArrayIndexOutOfBoundsException) e;
@@ -461,24 +461,24 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
}
private final int compare0(final byte[] a, final byte[] b, int length) {
- if (this.zero == null) return compares(a, b, length);
+ if (this.zero == null) return this.compares(a, b, length);
// we have an artificial start point. check all combinations
if (this.zero.length < length) length = this.zero.length;
- final int az = compares(a, this.zero, length); // -1 if a < z; 0 if a == z; 1 if a > z
- final int bz = compares(b, this.zero, length); // -1 if b < z; 0 if b == z; 1 if b > z
- if (az == bz) return compares(a, b, length);
+ final int az = this.compares(a, this.zero, length); // -1 if a < z; 0 if a == z; 1 if a > z
+ final int bz = this.compares(b, this.zero, length); // -1 if b < z; 0 if b == z; 1 if b > z
+ if (az == bz) return this.compares(a, b, length);
return sig(az - bz);
}
private final int compare0(final byte[] a, final int aoffset, final byte[] b, final int boffset, int length) {
- if (this.zero == null) return compares(a, aoffset, b, boffset, length);
+ if (this.zero == null) return this.compares(a, aoffset, b, boffset, length);
// we have an artificial start point. check all combinations
if (this.zero.length < length) length = this.zero.length;
- final int az = compares(a, aoffset, this.zero, 0, length); // -1 if a < z; 0 if a == z; 1 if a > z
- final int bz = compares(b, boffset, this.zero, 0, length); // -1 if b < z; 0 if b == z; 1 if b > z
- if (az == bz) return compares(a, aoffset, b, boffset, length);
+ final int az = this.compares(a, aoffset, this.zero, 0, length); // -1 if a < z; 0 if a == z; 1 if a > z
+ final int bz = this.compares(b, boffset, this.zero, 0, length); // -1 if b < z; 0 if b == z; 1 if b > z
+ if (az == bz) return this.compares(a, aoffset, b, boffset, length);
return sig(az - bz);
}
@@ -586,36 +586,36 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
if ("-test".equals(s[0])) {
System.out.println("Pid: " + ManagementFactory.getRuntimeMXBean().getName());
// do some checks
- Random r = new Random(0); // not real random to be able to reproduce the test
+ final Random r = new Random(0); // not real random to be able to reproduce the test
- try {
+ try {
// use the class loader to call sun.misc.BASE64Encoder, the sun base64 encoder
// we do not instantiate that class here directly since that provokes a
// "warning: sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release"
- Class<?> rfc1521Decoder_class = Class.forName("sun.misc.BASE64Decoder");
- Object rfc1521Decoder = rfc1521Decoder_class.newInstance();
- Method rfc1521Decoder_decodeBuffer = rfc1521Decoder_class.getMethod("decodeBuffer", String.class);
- Class<?> rfc1521Encoder_class = Class.forName("sun.misc.BASE64Encoder");
- Object rfc1521Encoder = rfc1521Encoder_class.newInstance();
- Method rfc1521Encoder_encode = rfc1521Encoder_class.getMethod("encode", byte[].class);
+ final Class<?> rfc1521Decoder_class = Class.forName("sun.misc.BASE64Decoder");
+ final Object rfc1521Decoder = rfc1521Decoder_class.getDeclaredConstructor().newInstance();
+ final Method rfc1521Decoder_decodeBuffer = rfc1521Decoder_class.getMethod("decodeBuffer", String.class);
+ final Class<?> rfc1521Encoder_class = Class.forName("sun.misc.BASE64Encoder");
+ final Object rfc1521Encoder = rfc1521Encoder_class.getDeclaredConstructor().newInstance();
+ final Method rfc1521Encoder_encode = rfc1521Encoder_class.getMethod("encode", byte[].class);
System.out.println("preparing tests..");
// prepare challenges and results with rfc1521Encoder
- int count = 100000;
- String[] challenges = new String[count];
- String[] rfc1521Encoded = new String[count];
+ final int count = 100000;
+ final String[] challenges = new String[count];
+ final String[] rfc1521Encoded = new String[count];
for (int i = 0; i < count; i++) {
- int len = r.nextInt(10000);
- StringBuilder challenge = new StringBuilder(len);
+ final int len = r.nextInt(10000);
+ final StringBuilder challenge = new StringBuilder(len);
for (int j = 0; j < len; j++) challenge.append((char) (32 + r.nextInt(64)));
challenges[i] = challenge.toString();
rfc1521Encoded[i] = (String) rfc1521Encoder_encode.invoke(rfc1521Encoder, UTF8.getBytes(challenges[i]));
}
// starting tests
- long start = System.currentTimeMillis();
- for (boolean rfc1521Compliant: new boolean[]{false, true}) {
+ final long start = System.currentTimeMillis();
+ for (final boolean rfc1521Compliant: new boolean[]{false, true}) {
System.out.println("starting tests, rfc1521Compliant = " + rfc1521Compliant + " ...");
String eb64, rfc1521;
// encode with enhancedCoder, decode with standard RFC 1521 base64
@@ -628,33 +628,33 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
while (rfc1521.length() % 4 != 0) rfc1521 += "=";
rfc1521 = rfc1521.replace('-', '+').replace('_', '/');
}
- String rfc1521Decoded = UTF8.String((byte[]) rfc1521Decoder_decodeBuffer.invoke(rfc1521Decoder, rfc1521));
+ final String rfc1521Decoded = UTF8.String((byte[]) rfc1521Decoder_decodeBuffer.invoke(rfc1521Decoder, rfc1521));
if (!rfc1521Decoded.equals(challenges[i])) System.out.println("Encode enhancedB64 + Decode RFC1521: Fail for " + challenges[i]);
}
-
+
// encode with enhancedCoder, decode with standard RFC 1521 base64
// sun.misc.BASE64Encoder rfc1521Encoder = new sun.misc.BASE64Encoder();
for (int i = 0; i < count; i++) {
// encode with enhancedCoder, decode with standard RFC 1521 base64
rfc1521 = new String(rfc1521Encoded[i]);
if (rfc1521Compliant) {
- String standardCoderDecoded = UTF8.String(Base64Order.standardCoder.decode(rfc1521));
+ final String standardCoderDecoded = UTF8.String(Base64Order.standardCoder.decode(rfc1521));
if (!standardCoderDecoded.equals(challenges[i])) System.out.println("Encode RFC1521 + Decode enhancedB64: Fail for " + rfc1521);
} else {
eb64 = new String(rfc1521);
while (eb64.endsWith("=")) eb64 = eb64.substring(0, eb64.length() - 1);
eb64 = eb64.replace('+', '-').replace('/', '_');
- String enhancedCoderDecoded = UTF8.String(Base64Order.enhancedCoder.decode(eb64));
+ final String enhancedCoderDecoded = UTF8.String(Base64Order.enhancedCoder.decode(eb64));
if (!enhancedCoderDecoded.equals(challenges[i])) System.out.println("Encode RFC1521 + Decode enhancedB64: Fail for " + eb64);
}
}
}
- long time = System.currentTimeMillis() - start;
+ final long time = System.currentTimeMillis() - start;
System.out.println("time: " + (time / 1000) + " seconds, " + (1000 * time / count) + " ms / 1000 steps");
- } catch (Throwable e) {
+ } catch (final Throwable e) {
e.printStackTrace();
}
-
+
}
}
}
diff --git a/source/net/yacy/document/content/dao/DatabaseConnection.java b/source/net/yacy/document/content/dao/DatabaseConnection.java
index acf957570..93640c9d9 100644
--- a/source/net/yacy/document/content/dao/DatabaseConnection.java
+++ b/source/net/yacy/document/content/dao/DatabaseConnection.java
@@ -7,7 +7,7 @@
// $LastChangedBy$
//
// LICENSE
-//
+//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
@@ -35,9 +35,9 @@ import net.yacy.cora.util.ConcurrentLog;
public class DatabaseConnection {
private Connection connection;
-
+
public DatabaseConnection(final String dbType, String host, int port, String dbname, String user, String pw) throws SQLException {
- String dbDriverStr = null, dbConnStr = null;
+ String dbDriverStr = null, dbConnStr = null;
if (dbType.equalsIgnoreCase("mysql")) {
dbDriverStr = "com.mysql.jdbc.Driver";
dbConnStr = "jdbc:mysql://" + host + ":" + port + "/" + dbname;
@@ -45,20 +45,20 @@ public class DatabaseConnection {
dbDriverStr = "org.postgresql.Driver";
dbConnStr = "jdbc:postgresql://" + host + ":" + port + "/" + dbname;
} else throw new IllegalArgumentException();
-
- try {
- Class.forName(dbDriverStr).newInstance();
+
+ try {
+ Class.forName(dbDriverStr).getDeclaredConstructor().newInstance();
} catch (final Exception e) {
throw new SQLException("Unable to load the jdbc driver: " + e.getMessage());
}
-
+
try {
this.connection = DriverManager.getConnection(dbConnStr, user, pw);
} catch (final Exception e) {
throw new SQLException("Unable to establish a database connection: " + e.getMessage());
}
}
-
+
public void setAutoCommit(boolean b) {
try {
this.connection.setAutoCommit(b);
@@ -66,7 +66,7 @@ public class DatabaseConnection {
ConcurrentLog.logException(e);
}
}
-
+
public int count(String tablename) throws SQLException {
Statement stmt = null;
ResultSet rs = null;
@@ -84,17 +84,17 @@ public class DatabaseConnection {
if (stmt != null) try {stmt.close();} catch (final SQLException e) {}
}
}
-
+
public synchronized void close() {
- if (connection != null) {
+ if (this.connection != null) {
try {
- connection.close();
- connection = null;
+ this.connection.close();
+ this.connection = null;
} catch (final SQLException e) {
}
}
}
-
+
public Statement statement() throws SQLException {
return this.connection.createStatement();
}
diff --git a/source/net/yacy/kelondro/logging/ConsoleOutErrHandler.java b/source/net/yacy/kelondro/logging/ConsoleOutErrHandler.java
index 0d11cd577..030fc791c 100644
--- a/source/net/yacy/kelondro/logging/ConsoleOutErrHandler.java
+++ b/source/net/yacy/kelondro/logging/ConsoleOutErrHandler.java
@@ -51,7 +51,7 @@ public final class ConsoleOutErrHandler extends Handler {
this.stdErrHandler = new ConsoleHandler();
this.stdOutHandler.setLevel(Level.FINEST);
this.stdErrHandler.setLevel(Level.WARNING);
- configure();
+ this.configure();
}
/**
@@ -59,21 +59,21 @@ public final class ConsoleOutErrHandler extends Handler {
*/
private void configure() {
final LogManager manager = LogManager.getLogManager();
- final String className = getClass().getName();
+ final String className = this.getClass().getName();
final String level = manager.getProperty(className + ".level");
- setLevel((level == null) ? Level.INFO : Level.parse(level));
+ this.setLevel((level == null) ? Level.INFO : Level.parse(level));
- final Level levelStdOut = parseLevel(manager.getProperty(className + ".levelStdOut"));
- final Level levelSplit = parseLevel(manager.getProperty(className + ".levelSplit"));
- final Level levelStdErr = parseLevel(manager.getProperty(className + ".levelStdErr"));
- setLevels(levelStdOut,levelSplit,levelStdErr);
+ final Level levelStdOut = this.parseLevel(manager.getProperty(className + ".levelStdOut"));
+ final Level levelSplit = this.parseLevel(manager.getProperty(className + ".levelSplit"));
+ final Level levelStdErr = this.parseLevel(manager.getProperty(className + ".levelStdErr"));
+ this.setLevels(levelStdOut,levelSplit,levelStdErr);
final String filter = manager.getProperty(className + ".filter");
- setFilter(makeFilter(filter));
+ this.setFilter(this.makeFilter(filter));
final String formatter = manager.getProperty(className + ".formatter");
- setFormatter(makeFormatter(formatter));
+ this.setFormatter(this.makeFormatter(formatter));
final String encoding = manager.getProperty(className + ".encoding");
try {
@@ -102,7 +102,7 @@ public final class ConsoleOutErrHandler extends Handler {
Filter f = null;
try {
final Class<?> c = Class.forName(name);
- f = (Filter)c.newInstance();
+ f = (Filter)c.getDeclaredConstructor().newInstance();
} catch (final Exception e) {
if (name != null) {
System.err.println("Unable to load filter: " + name);
@@ -117,7 +117,7 @@ public final class ConsoleOutErrHandler extends Handler {
Formatter f = null;
try {
final Class<?> c = Class.forName(name);
- f = (Formatter)c.newInstance();
+ f = (Formatter)c.getDeclaredConstructor().newInstance();
} catch (final Exception e) {
f = new SimpleFormatter();
}
@@ -127,7 +127,7 @@ public final class ConsoleOutErrHandler extends Handler {
@Override
public final void publish(final LogRecord record) {
- if (!isLoggable(record)) return;
+ if (!this.isLoggable(record)) return;
if (this.ignoreCtrlChr) {
String msg = record.getMessage();
@@ -175,8 +175,8 @@ public final class ConsoleOutErrHandler extends Handler {
super.setFormatter(newFormatter);
if (newFormatter == null) return;
try {
- this.stdOutHandler.setFormatter(newFormatter.getClass().newInstance());
- this.stdErrHandler.setFormatter(newFormatter.getClass().newInstance());
+ this.stdOutHandler.setFormatter(newFormatter.getClass().getDeclaredConstructor().newInstance());
+ this.stdErrHandler.setFormatter(newFormatter.getClass().getDeclaredConstructor().newInstance());
} catch (final Exception e) {
throw new SecurityException(e.getMessage());
}
@@ -187,8 +187,8 @@ public final class ConsoleOutErrHandler extends Handler {
super.setFilter(newFilter);
if (newFilter == null) return;
try {
- this.stdOutHandler.setFilter(newFilter.getClass().newInstance());
- this.stdErrHandler.setFilter(newFilter.getClass().newInstance());
+ this.stdOutHandler.setFilter(newFilter.getClass().getDeclaredConstructor().newInstance());
+ this.stdErrHandler.setFilter(newFilter.getClass().getDeclaredConstructor().newInstance());
} catch (final Exception e) {
throw new SecurityException(e.getMessage());
}
diff --git a/source/net/yacy/kelondro/logging/GuiHandler.java b/source/net/yacy/kelondro/logging/GuiHandler.java
index 8a7faf102..51d9153ed 100644
--- a/source/net/yacy/kelondro/logging/GuiHandler.java
+++ b/source/net/yacy/kelondro/logging/GuiHandler.java
@@ -28,6 +28,7 @@
package net.yacy.kelondro.logging;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.logging.ErrorManager;
import java.util.logging.Filter;
@@ -50,11 +51,11 @@ public class GuiHandler extends Handler {
public GuiHandler() {
super();
final LogManager manager = LogManager.getLogManager();
- final String className = getClass().getName();
+ final String className = this.getClass().getName();
final String level = manager.getProperty(className + ".level");
- setLevel((level == null) ? Level.INFO : Level.parse(level));
- setFilter(makeFilter(manager.getProperty(className + ".filter")));
- setFormatter(makeFormatter(manager.getProperty(className + ".formatter")));
+ this.setLevel((level == null) ? Level.INFO : Level.parse(level));
+ this.setFilter(makeFilter(manager.getProperty(className + ".filter")));
+ this.setFormatter(makeFormatter(manager.getProperty(className + ".formatter")));
try {
GuiHandler.size = Integer.parseInt(manager.getProperty(className + ".size"));
} catch (final NumberFormatException e) {
@@ -68,7 +69,7 @@ public class GuiHandler extends Handler {
private static Filter makeFilter(final String name) {
if (name == null) return null;
try {
- return (Filter) Class.forName(name).newInstance();
+ return (Filter) Class.forName(name).getDeclaredConstructor().newInstance();
} catch (final Exception e) {
System.err.println("Unable to load filter: " + name);
}
@@ -78,7 +79,7 @@ public class GuiHandler extends Handler {
private static Formatter makeFormatter(final String name) {
if (name == null) return null;
try {
- return (Formatter) Class.forName(name).newInstance();
+ return (Formatter) Class.forName(name).getDeclaredConstructor().newInstance();
} catch (final Exception e) {
return new SimpleFormatter();
}
@@ -90,21 +91,21 @@ public class GuiHandler extends Handler {
@Override
public final void publish(final LogRecord record) {
- if (!isLoggable(record)) return;
+ if (!this.isLoggable(record)) return;
final int ix = (GuiHandler.start + GuiHandler.count) % GuiHandler.buffer.length;
- GuiHandler.buffer[ix] = getFormatter().format(record);
+ GuiHandler.buffer[ix] = this.getFormatter().format(record);
if (GuiHandler.count < GuiHandler.buffer.length) {
GuiHandler.count++;
} else {
GuiHandler.start++;
}
- flush();
+ this.flush();
if (MemoryControl.shortStatus()) clear();
}
public final synchronized String[] getLogLines(final boolean reversed, int lineCount) {
if (lineCount > GuiHandler.count || lineCount < 0) lineCount = GuiHandler.count;
- final List<String> logMessages = new ArrayList<String>(GuiHandler.count);
+ final List<String> logMessages = new ArrayList<>(GuiHandler.count);
try {
final int theStart = (reversed) ? GuiHandler.start + GuiHandler.count - 1 : GuiHandler.start + GuiHandler.count - lineCount;
String record = null;
@@ -115,7 +116,7 @@ public class GuiHandler extends Handler {
}
return logMessages.toArray(new String[logMessages.size()]);
} catch (final Exception ex) {
- reportError(null, ex, ErrorManager.FORMAT_FAILURE);
+ this.reportError(null, ex, ErrorManager.FORMAT_FAILURE);
return new String[]{"Error while formatting the logging message"};
}
}
@@ -123,9 +124,9 @@ public class GuiHandler extends Handler {
@Override
public void flush() {
}
-
+
public static void clear() {
- for (int i = 0; i < GuiHandler.buffer.length; i++) GuiHandler.buffer[i] = null;
+ Arrays.fill(GuiHandler.buffer, null);
GuiHandler.start = 0;
GuiHandler.count = 0;
}
diff --git a/source/net/yacy/kelondro/table/SQLTable.java b/source/net/yacy/kelondro/table/SQLTable.java
index 5705225d2..294e55f5f 100644
--- a/source/net/yacy/kelondro/table/SQLTable.java
+++ b/source/net/yacy/kelondro/table/SQLTable.java
@@ -76,7 +76,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
public SQLTable(final String dbType, final Row rowdef) throws Exception {
this.rowdef = rowdef;
- openDatabaseConnection(dbType);
+ this.openDatabaseConnection(dbType);
}
private void openDatabaseConnection(final String dbType) throws Exception{
@@ -92,7 +92,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
dbConnStr = db_conn_str_pgsql;
}
try {
- Class.forName(dbDriverStr).newInstance();
+ Class.forName(dbDriverStr).getDeclaredConstructor().newInstance();
} catch (final Exception e) {
throw new Exception ("Unable to load the jdbc driver: " + e.getMessage(),e);
}
@@ -103,7 +103,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
}
}
-
+
@Override
public void optimize() {
}
@@ -163,7 +163,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
@Override
public boolean isEmpty() {
- return size() == 0;
+ return this.size() == 0;
}
@Override
@@ -174,7 +174,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
@Override
public boolean has(final byte[] key) {
try {
- return (get(key, false) != null);
+ return (this.get(key, false) != null);
} catch (final IOException e) {
return false;
}
@@ -182,7 +182,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
@Override
public ArrayList<RowCollection> removeDoubles() {
- return new ArrayList<RowCollection>();
+ return new ArrayList<>();
}
@Override
@@ -212,10 +212,10 @@ 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 {
- final Map<byte[], Row.Entry> map = new TreeMap<byte[], Row.Entry>(row().objectOrder);
+ 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;
@@ -224,7 +224,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
@Override
public Row.Entry replace(final Row.Entry row) throws IOException {
try {
- final Row.Entry oldEntry = remove(row.getPrimaryKeyBytes());
+ final Row.Entry oldEntry = this.remove(row.getPrimaryKeyBytes());
final String sqlQuery = "INSERT INTO test (" +
"hash, " +
"value) " +
@@ -302,7 +302,7 @@ public class SQLTable implements Index, Iterable<Row.Entry> {
@Override
public boolean delete(final byte[] key) throws IOException {
- return remove(key) != null;
+ return this.remove(key) != null;
}
@Override
@@ -329,7 +329,7 @@ public class SQLTable 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/peers/Network.java b/source/net/yacy/peers/Network.java
index 1a1bbb669..181bb9c30 100644
--- a/source/net/yacy/peers/Network.java
+++ b/source/net/yacy/peers/Network.java
@@ -70,12 +70,12 @@ public class Network
// statics
public static final ThreadGroup publishThreadGroup = new ThreadGroup("publishThreadGroup");
- public static final HashMap<String, String> seedUploadMethods = new HashMap<String, String>();
+ public static final HashMap<String, String> seedUploadMethods = new HashMap<>();
public static final ConcurrentLog log = new ConcurrentLog("YACY");
/** pseudo-random key derived from a time-interval while YaCy startup */
public static long speedKey = 0;
public static long magic = System.currentTimeMillis();
- public static final Map<String, Accessible> amIAccessibleDB = new ConcurrentHashMap<String, Accessible>(); // Holds PeerHash / yacyAccessible Relations
+ public static final Map<String, Accessible> amIAccessibleDB = new ConcurrentHashMap<>(); // Holds PeerHash / yacyAccessible Relations
// constants for PeerPing behavior
private static final int PING_INITIAL = 20;
private static final int PING_MAX_RUNNING = 3;
@@ -185,7 +185,7 @@ public class Network
+ this.sb.peers.sizeConnected()
+ " new peer(s)");
}
- publishMySeed();
+ this.publishMySeed();
}
protected class publishThread extends Thread
@@ -316,7 +316,7 @@ public class Network
if ( ch != null ) {
String hash;
Seed seed;
- for (byte[] hashb: ch) {
+ for (final byte[] hashb: ch) {
hash = ASCII.String(hashb);
seed = seeds.get(hash);
if (seed == null) {
@@ -363,7 +363,7 @@ public class Network
//if (seeds.length > 1) {
// holding a reference to all started threads
final List<publishThread> syncList = Collections.synchronizedList(new LinkedList<publishThread>()); // memory for threads
-
+
// go through the peer list and starting a new publisher thread for each peer
int i = 0;
while ( si.hasNext() ) {
@@ -378,7 +378,7 @@ public class Network
/* This should not happen : seeds db maintains only seeds with at least one IP */
log.warn("Peer " + seed.getName() + "has no known IP address");
} else {
- String ip = ips.iterator().next();
+ final String ip = ips.iterator().next();
final String address = seed.getPublicAddress(ip);
if ( log.isFine() ) log.fine("HELLO #" + i + " to peer '" + seed.getName() + "' at " + address); // debug
final String seederror = seed.isProper(false);
@@ -387,7 +387,7 @@ public class Network
this.sb.peers.peerActions.interfaceDeparture(seed, ip);
} else {
// starting a new publisher thread
- publishThread t = new publishThread(Network.publishThreadGroup, seed);
+ final publishThread t = new publishThread(Network.publishThreadGroup, seed);
t.start();
syncList.add(t);
}
@@ -395,7 +395,7 @@ public class Network
}
// receiving the result of all started publisher threads
- for (publishThread t: syncList) {
+ for (final publishThread t: syncList) {
// waiting for the next thread to finish
t.join();
}
@@ -543,7 +543,7 @@ public class Network
}
try {
final Class<?> uploaderClass = Class.forName(className);
- final Object uploader = uploaderClass.newInstance();
+ final Object uploader = uploaderClass.getDeclaredConstructor().newInstance();
return (yacySeedUploader) uploader;
} catch (final Exception e ) {
return null;
@@ -705,7 +705,7 @@ public class Network
sb.peers.lastSeedUpload_timeStamp = System.currentTimeMillis();
final Set<String> myIPs = sb.peers.myIPs();
if(!myIPs.isEmpty()) {
- sb.peers.lastSeedUpload_myIP = myIPs.iterator().next();
+ sb.peers.lastSeedUpload_myIP = myIPs.iterator().next();
}
}
}