提交 dd3ee7e8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Make method static where possible and other cleanup.

上级 8c55bcf6
......@@ -77,7 +77,7 @@ public class PageBtreeIndex extends PageIndex {
memoryPerPage = (Constants.MEMORY_PAGE_BTREE + store.getPageSize()) >> 2;
}
private void checkIndexColumnTypes(IndexColumn[] columns) {
private static void checkIndexColumnTypes(IndexColumn[] columns) {
for (IndexColumn c : columns) {
int type = c.column.getType();
if (type == Value.CLOB || type == Value.BLOB) {
......
......@@ -2918,7 +2918,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
}
private void mapColumn(HashMap<String, Integer> map, String label, int index) {
private static void mapColumn(HashMap<String, Integer> map, String label, int index) {
// put the index (usually that's the only operation)
Integer old = map.put(label, index);
if (old != null) {
......
......@@ -1257,7 +1257,7 @@ public class Recover extends Tool implements DataHandler {
}
}
private boolean isSchemaObjectTypeDelayed(MetaRecord m) {
private static boolean isSchemaObjectTypeDelayed(MetaRecord m) {
switch (m.getObjectType()) {
case DbObject.INDEX:
case DbObject.CONSTRAINT:
......
......@@ -34,7 +34,7 @@ public class CaseInsensitiveMap<V> extends HashMap<String, V> {
return super.remove(toUpper(key));
}
private String toUpper(Object key) {
private static String toUpper(Object key) {
return key == null ? null : StringUtils.toUpperEnglish(key.toString());
}
......
......@@ -19,7 +19,6 @@ import java.util.StringTokenizer;
import java.util.UUID;
import org.h2.fulltext.FullText;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
import org.h2.util.Task;
......@@ -76,7 +75,7 @@ public class TestFullText extends TestBase {
deleteDb("fullTextReopen");
}
private void close(Collection<Connection> conns) throws SQLException {
private static void close(Collection<Connection> conns) throws SQLException {
for (Connection conn : conns) {
conn.close();
}
......
......@@ -33,7 +33,6 @@ public class ProductAnnotationOnly {
@JQColumn(name = "name")
private String productName;
@SuppressWarnings("unused")
@JQColumn
private Double unitPrice;
......
......@@ -17,11 +17,9 @@ import org.h2.jaqu.Table.JQTable;
@JQTable(createIfRequired = false)
public class ProductNoCreateTable {
@SuppressWarnings("unused")
@JQColumn(name = "id")
private Integer productId;
@SuppressWarnings("unused")
@JQColumn(name = "name")
private String productName;
......
......@@ -91,7 +91,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
}
private void testChangeType(Connection conn) throws SQLException {
private static void testChangeType(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("select (? || ? || ?) from dual");
prep.setString(1, "a");
prep.setString(2, "b");
......@@ -192,7 +192,7 @@ public class TestPreparedStatement extends TestBase {
stat.execute("drop table d");
}
private void testCallTablePrepared(Connection conn) throws SQLException {
private static void testCallTablePrepared(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("call table(x int = (1))");
prep.executeQuery();
prep.executeQuery();
......
......@@ -64,7 +64,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
deleteDb("autoReconnect");
Server tcp = Server.createTcpServer().start();
try {
Connection conn = getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;AUTO_SERVER=TRUE");
conn = getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;AUTO_SERVER=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;OPEN_NEW=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
......
......@@ -55,7 +55,8 @@ public class TestClassLoaderLeak extends TestBase {
// using -XX:+HeapDumpOnOutOfMemoryError
// which can be analyzed using EclipseMAT
// (check incoming references to TestClassLoader)
if (false) {
boolean fillMemory = false;
if (fillMemory) {
ArrayList<byte[]> memory = New.arrayList();
for (int i = 0; i < Integer.MAX_VALUE; i++) {
memory.add(new byte[1024]);
......
......@@ -100,12 +100,12 @@ public class TestCompress extends TestBase {
Task t = new Task() {
public void call() {
CompressTool tool = CompressTool.getInstance();
byte[] buff = new byte[1024];
byte[] b = new byte[1024];
Random r = new Random();
while (!stop) {
r.nextBytes(buff);
byte[] test = tool.expand(tool.compress(buff, "LZF"));
assertEquals(buff, test);
r.nextBytes(b);
byte[] test = tool.expand(tool.compress(b, "LZF"));
assertEquals(b, test);
}
}
};
......@@ -120,17 +120,17 @@ public class TestCompress extends TestBase {
private void testVariableEnd() throws Exception {
CompressTool utils = CompressTool.getInstance();
StringBuilder buff = new StringBuilder();
StringBuilder b = new StringBuilder();
for (int i = 0; i < 90; i++) {
buff.append('0');
b.append('0');
}
String prefix = buff.toString();
String prefix = b.toString();
for (int i = 0; i < 100; i++) {
buff = new StringBuilder(prefix);
b = new StringBuilder(prefix);
for (int j = 0; j < i; j++) {
buff.append((char) ('1' + j));
b.append((char) ('1' + j));
}
String test = buff.toString();
String test = b.toString();
byte[] in = test.getBytes();
assertEquals(in, utils.expand(utils.compress(in, "LZF")));
}
......@@ -152,19 +152,19 @@ public class TestCompress extends TestBase {
conn.close();
Compressor compress = new CompressLZF();
int pageSize = Constants.DEFAULT_PAGE_SIZE;
byte[] buff = new byte[pageSize];
byte[] buff2 = new byte[pageSize];
byte[] test = new byte[2 * pageSize];
compress.compress(buff, pageSize, test, 0);
compress.compress(buff2, pageSize, test, 0);
for (int j = 0; j < 4; j++) {
long time = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
InputStream in = FileUtils.newInputStream("memFS:compress.h2.db");
while (true) {
int len = in.read(buff);
int len = in.read(buff2);
if (len < 0) {
break;
}
compress.compress(buff, pageSize, test, 0);
compress.compress(buff2, pageSize, test, 0);
}
in.close();
}
......@@ -175,11 +175,11 @@ public class TestCompress extends TestBase {
ArrayList<byte[]> comp = New.arrayList();
InputStream in = FileUtils.newInputStream("memFS:compress.h2.db");
while (true) {
int len = in.read(buff);
int len = in.read(buff2);
if (len < 0) {
break;
}
int b = compress.compress(buff, pageSize, test, 0);
int b = compress.compress(buff2, pageSize, test, 0);
byte[] data = new byte[b];
System.arraycopy(test, 0, data, 0, b);
comp.add(data);
......@@ -200,24 +200,24 @@ public class TestCompress extends TestBase {
private void test(int len) throws IOException {
Random r = new Random(len);
for (int pattern = 0; pattern < 4; pattern++) {
byte[] buff = new byte[len];
byte[] b = new byte[len];
switch (pattern) {
case 0:
// leave empty
break;
case 1: {
r.nextBytes(buff);
r.nextBytes(b);
break;
}
case 2: {
for (int x = 0; x < len; x++) {
buff[x] = (byte) (x & 10);
b[x] = (byte) (x & 10);
}
break;
}
case 3: {
for (int x = 0; x < len; x++) {
buff[x] = (byte) (x / 10);
b[x] = (byte) (x / 10);
}
break;
}
......@@ -226,7 +226,7 @@ public class TestCompress extends TestBase {
if (r.nextInt(2) < 1) {
for (int x = 0; x < len; x++) {
if (r.nextInt(20) < 1) {
buff[x] = (byte) (r.nextInt(255));
b[x] = (byte) (r.nextInt(255));
}
}
}
......@@ -234,27 +234,27 @@ public class TestCompress extends TestBase {
// level 9 is highest, strategy 2 is huffman only
for (String a : new String[] { "LZF", "No", "Deflate", "Deflate level 9 strategy 2" }) {
long time = System.currentTimeMillis();
byte[] out = utils.compress(buff, a);
byte[] out = utils.compress(b, a);
byte[] test = utils.expand(out);
if (testPerformance) {
System.out.println("p:" + pattern + " len: " + out.length + " time: " + (System.currentTimeMillis() - time) + " " + a);
}
assertEquals(buff.length, test.length);
assertEquals(buff, test);
assertEquals(b.length, test.length);
assertEquals(b, test);
Arrays.fill(test, (byte) 0);
CompressTool.expand(out, test, 0);
assertEquals(buff, test);
assertEquals(b, test);
}
for (String a : new String[] { null, "LZF", "DEFLATE", "ZIP", "GZIP" }) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream out2 = CompressTool.wrapOutputStream(out, a, "test");
IOUtils.copy(new ByteArrayInputStream(buff), out2);
IOUtils.copy(new ByteArrayInputStream(b), out2);
out2.close();
InputStream in = new ByteArrayInputStream(out.toByteArray());
in = CompressTool.wrapInputStream(in, a, "test");
out.reset();
IOUtils.copy(in, out);
assertEquals(buff, out.toByteArray());
assertEquals(b, out.toByteArray());
}
}
}
......
......@@ -351,7 +351,7 @@ public class TestDate extends TestBase {
}
}
private void testCalculateLocalMillis() {
private static void testCalculateLocalMillis() {
TimeZone defaultTimeZone = TimeZone.getDefault();
try {
for (TimeZone tz : TestDate.getDistinctTimeZones()) {
......
......@@ -32,11 +32,10 @@ public class TestFileLockProcess extends TestBase {
return;
}
String url = args[0];
TestFileLockProcess app = new TestFileLockProcess();
app.execute(url);
execute(url);
}
private void execute(String url) {
private static void execute(String url) {
org.h2.Driver.load();
try {
Class.forName("org.h2.Driver");
......
......@@ -283,7 +283,7 @@ public class TestFileSystem extends TestBase {
}
}
private void testDirectories(String fsBase) {
private static void testDirectories(String fsBase) {
final String fileName = fsBase + "/testFile";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
......@@ -299,7 +299,7 @@ public class TestFileSystem extends TestBase {
}
}
private void testMoveTo(String fsBase) {
private static void testMoveTo(String fsBase) {
final String fileName = fsBase + "/testFile";
final String fileName2 = fsBase + "/testFile2";
if (FileUtils.exists(fileName)) {
......@@ -319,7 +319,7 @@ public class TestFileSystem extends TestBase {
}
}
private void testUnsupportedFeatures(String fsBase) throws IOException {
private static void testUnsupportedFeatures(String fsBase) throws IOException {
final String fileName = fsBase + "/testFile";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
......
......@@ -34,7 +34,6 @@ public class TestJmx extends TestBase {
TestBase.createCaller().init().test();
}
@SuppressWarnings("unchecked")
public void test() throws Exception {
HashMap<String, MBeanAttributeInfo> attrMap;
HashMap<String, MBeanOperationInfo> opMap;
......@@ -104,6 +103,7 @@ public class TestJmx extends TestBase {
conn = getConnection("jmx;jmx=true");
name = new ObjectName("org.h2:name=JMX,*");
@SuppressWarnings("rawtypes")
Set set = mbeanServer.queryNames(name, null);
name = (ObjectName) set.iterator().next();
......
......@@ -52,8 +52,8 @@ public class TestSort extends TestBase {
test(Arrays.class);
}
private void test(Class<?> clazz) throws Exception {
this.clazz = clazz;
private void test(Class<?> c) throws Exception {
this.clazz = c;
ordered(array);
shuffle(array);
stabilize(array);
......
......@@ -93,8 +93,8 @@ public class TestUtils extends TestBase {
String pathSeparator = (String) Utils.getStaticField("java.io.File.pathSeparator");
assertEquals(File.pathSeparator, pathSeparator);
// Instance fields
String testField = (String) Utils.getField(this, "testField");
assertEquals(this.testField, testField);
String test = (String) Utils.getField(this, "testField");
assertEquals(this.testField, test);
// Class present?
assertFalse(Utils.isClassPresent("abc"));
assertTrue(Utils.isClassPresent(getClass().getName()));
......
......@@ -142,7 +142,7 @@ public class ProxyCodeGenerator {
methods.put(getMethodName(m), m);
}
private String getMethodName(Method m) {
private static String getMethodName(Method m) {
StringBuilder buff = new StringBuilder();
buff.append(m.getReturnType()).append(' ');
buff.append(m.getName());
......
......@@ -86,7 +86,7 @@ public class RailroadImages {
savePng(flipHorizontal(img), "div-ke.png");
}
private void setStroke(Graphics2D g, int i) {
private static void setStroke(Graphics2D g, int i) {
if (i == 0) {
g.setColor(Color.WHITE);
g.setStroke(new BasicStroke(STROKE * 2));
......
......@@ -207,11 +207,11 @@ public class FilePathZip2 extends FilePath {
if (entry == null) {
break;
}
String name = entry.getName();
if (name.startsWith(dirName) && name.length() > dirName.length()) {
int idx = name.indexOf('/', dirName.length());
if (idx < 0 || idx >= name.length() - 1) {
list.add(getPath(prefix + name));
String entryName = entry.getName();
if (entryName.startsWith(dirName) && entryName.length() > dirName.length()) {
int idx = entryName.indexOf('/', dirName.length());
if (idx < 0 || idx >= entryName.length() - 1) {
list.add(getPath(prefix + entryName));
}
}
file.closeEntry();
......
......@@ -285,7 +285,7 @@ public class FileShell extends Tool {
return true;
}
private void end(String[] list, int index) throws IOException {
private static void end(String[] list, int index) throws IOException {
if (list.length != index) {
throw new IOException("End of command expected, got: " + list[index]);
}
......@@ -298,14 +298,14 @@ public class FileShell extends Tool {
if (FileUtils.isDirectory(fileName)) {
print("Is a directory: " + fileName);
}
InputStream in = null;
InputStream inFile = null;
try {
in = FileUtils.newInputStream(fileName);
IOUtils.copy(in, out, length);
inFile = FileUtils.newInputStream(fileName);
IOUtils.copy(inFile, out, length);
} catch (IOException e) {
error(e);
} finally {
IOUtils.closeSilently(in);
IOUtils.closeSilently(inFile);
}
println("");
}
......@@ -333,7 +333,7 @@ public class FileShell extends Tool {
}
}
private void zip(String zipFileName, String base, ArrayList<String> source) {
private static void zip(String zipFileName, String base, ArrayList<String> source) {
FileUtils.delete(zipFileName);
OutputStream fileOut = null;
try {
......@@ -376,10 +376,10 @@ public class FileShell extends Tool {
}
private void unzip(String zipFileName, String targetDir) {
InputStream in = null;
InputStream inFile = null;
try {
in = FileUtils.newInputStream(zipFileName);
ZipInputStream zipIn = new ZipInputStream(in);
inFile = FileUtils.newInputStream(zipFileName);
ZipInputStream zipIn = new ZipInputStream(inFile);
while (true) {
ZipEntry entry = zipIn.getNextEntry();
if (entry == null) {
......@@ -407,7 +407,7 @@ public class FileShell extends Tool {
} catch (IOException e) {
error(e);
} finally {
IOUtils.closeSilently(in);
IOUtils.closeSilently(inFile);
}
}
......
......@@ -56,18 +56,18 @@ public class InPlaceStableMergeSort<T> {
/**
* Sort an array using the given comparator.
*
* @param data the data array to sort
* @param comp the comparator
* @param d the data array to sort
* @param c the comparator
*/
public void sortArray(T[] data, Comparator<T> comp) {
this.data = data;
this.comp = comp;
int len = Math.max((int) (100 * Math.log(data.length)), TEMP_SIZE);
len = Math.min(data.length, len);
public void sortArray(T[] d, Comparator<T> c) {
this.data = d;
this.comp = c;
int len = Math.max((int) (100 * Math.log(d.length)), TEMP_SIZE);
len = Math.min(d.length, len);
@SuppressWarnings("unchecked")
T[] t = (T[]) new Object[len];
this.temp = t;
mergeSort(0, data.length - 1);
mergeSort(0, d.length - 1);
}
/**
......@@ -309,14 +309,14 @@ public class InPlaceStableMergeSort<T> {
/**
* Swap two elements in the array.
*
* @param data the array
* @param d the array
* @param a the index of the first element
* @param b the index of the second element
*/
private void swap(T[] data, int a, int b) {
T temp = data[a];
data[a] = data[b];
data[b] = temp;
private void swap(T[] d, int a, int b) {
T t = d[a];
d[a] = d[b];
d[b] = t;
}
}
\ No newline at end of file
......@@ -56,18 +56,18 @@ public class InPlaceStableQuicksort<T> {
/**
* Sort an array using the given comparator.
*
* @param data the data array to sort
* @param comp the comparator
* @param d the data array to sort
* @param c the comparator
*/
public void sortArray(T[] data, Comparator<T> comp) {
this.data = data;
this.comp = comp;
int len = Math.max((int) (100 * Math.log(data.length)), TEMP_SIZE);
len = Math.min(data.length, len);
public void sortArray(T[] d, Comparator<T> c) {
this.data = d;
this.comp = c;
int len = Math.max((int) (100 * Math.log(d.length)), TEMP_SIZE);
len = Math.min(d.length, len);
@SuppressWarnings("unchecked")
T[] t = (T[]) new Object[len];
this.temp = t;
quicksort(0, data.length - 1);
quicksort(0, d.length - 1);
}
/**
......@@ -250,19 +250,19 @@ public class InPlaceStableQuicksort<T> {
/**
* Select the specified element.
*
* @param data the array
* @param d the array
* @param from the index of the first element
* @param to the index of the last element
* @param k which element to return (1 means the lowest)
* @return the specified element
*/
private T select(T[] data, int from, int to, int k) {
private T select(T[] d, int from, int to, int k) {
while (true) {
int pivotIndex = (to + from) >>> 1;
int pivotNewIndex = selectPartition(data, from, to, pivotIndex);
int pivotNewIndex = selectPartition(d, from, to, pivotIndex);
int pivotDist = pivotNewIndex - from + 1;
if (pivotDist == k) {
return data[pivotNewIndex];
return d[pivotNewIndex];
} else if (k < pivotDist) {
to = pivotNewIndex - 1;
} else {
......@@ -275,37 +275,37 @@ public class InPlaceStableQuicksort<T> {
/**
* Partition the elements to select an element.
*
* @param data the array
* @param d the array
* @param from the index of the first element
* @param to the index of the last element
* @param pivotIndex the index of the pivot
* @return the new index
*/
private int selectPartition(T[] data, int from, int to, int pivotIndex) {
T pivotValue = data[pivotIndex];
swap(data, pivotIndex, to);
private int selectPartition(T[] d, int from, int to, int pivotIndex) {
T pivotValue = d[pivotIndex];
swap(d, pivotIndex, to);
int storeIndex = from;
for (int i = from; i <= to; i++) {
if (comp.compare(data[i], pivotValue) < 0) {
swap(data, storeIndex, i);
if (comp.compare(d[i], pivotValue) < 0) {
swap(d, storeIndex, i);
storeIndex++;
}
}
swap(data, to, storeIndex);
swap(d, to, storeIndex);
return storeIndex;
}
/**
* Swap two elements in the array.
*
* @param data the array
* @param d the array
* @param a the index of the first element
* @param b the index of the second element
*/
private void swap(T[] data, int a, int b) {
T temp = data[a];
data[a] = data[b];
data[b] = temp;
private void swap(T[] d, int a, int b) {
T t = d[a];
d[a] = d[b];
d[b] = t;
}
}
......@@ -238,7 +238,7 @@ public class BtreeMapStore {
return pos;
}
private long getId(int blockId, int offset) {
private static long getId(int blockId, int offset) {
return ((long) blockId << 32) | offset;
}
......@@ -597,7 +597,7 @@ public class BtreeMapStore {
}
}
private int getBlockId(long pageId) {
private static int getBlockId(long pageId) {
return (int) (pageId >>> 32);
}
......
......@@ -291,39 +291,39 @@ class Node {
/**
* Compare the key with the key of this node.
*
* @param key the key
* @param k the key
* @return -1 if the key is smaller than this nodes key, 1 if bigger, and 0
* if equal
*/
int compare(Object key) {
return map.compare(key, this.key);
int compare(Object k) {
return map.compare(k, this.key);
}
private Node remove(Object key) {
private Node remove(Object k) {
Node n = copyOnWrite();
if (map.compare(key, n.key) < 0) {
if (map.compare(k, n.key) < 0) {
if (!isRed(n.getLeft()) && !isRed(n.getLeft().getLeft())) {
n = n.moveRedLeft();
}
n.setLeft(n.getLeft().remove(key));
n.setLeft(n.getLeft().remove(k));
} else {
if (isRed(n.getLeft())) {
n = n.rotateRight();
}
if (n.compare(key) == 0 && n.getRight() == null) {
if (n.compare(k) == 0 && n.getRight() == null) {
map.removeNode(id);
return null;
}
if (!isRed(n.getRight()) && !isRed(n.getRight().getLeft())) {
n = n.moveRedRight();
}
if (n.compare(key) == 0) {
if (n.compare(k) == 0) {
Node min = n.getRight().getMin();
n.key = min.key;
n.data = min.data;
n.setRight(n.getRight().removeMin());
} else {
n.setRight(n.getRight().remove(key));
n.setRight(n.getRight().remove(k));
}
}
return n.fixUp();
......@@ -390,7 +390,7 @@ class Node {
return n;
}
private boolean isRed(Node n) {
private static boolean isRed(Node n) {
return n != null && (n.flags & FLAG_BLACK) == 0;
}
......
......@@ -304,7 +304,7 @@ public class TreeMapStore {
return pos;
}
private long getId(int blockId, int offset) {
private static long getId(int blockId, int offset) {
return ((long) blockId << 32) | offset;
}
......@@ -632,7 +632,7 @@ public class TreeMapStore {
}
}
private int getBlockId(long nodeId) {
private static int getBlockId(long nodeId) {
return (int) (nodeId >>> 32);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论