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