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

Make methods static if possible.

上级 8f75466e
......@@ -125,7 +125,7 @@ public class Build extends BuildBase {
switchSource(true);
}
private void switchSource(boolean enableCheck) {
private static void switchSource(boolean enableCheck) {
try {
String version = System.getProperty("version");
String check = enableCheck ? "+CHECK" : "-CHECK";
......@@ -190,7 +190,7 @@ public class Build extends BuildBase {
resources(clientOnly, basicResourcesOnly);
}
private void filter(String source, String target, String old, String replacement) {
private static void filter(String source, String target, String old, String replacement) {
String text = new String(readFile(new File(source)));
text = replaceAll(text, old, replacement);
writeFile(new File(target), text.getBytes());
......@@ -263,15 +263,15 @@ public class Build extends BuildBase {
"4da67bb4a6eea5dc273f99c50ad2333eadb46f86");
}
private String getVersion() {
private static String getVersion() {
return getStaticValue("org.h2.engine.Constants", "getVersion");
}
private String getLuceneJar() {
private static String getLuceneJar() {
return "lucene-core-" + (getLuceneVersion() == 2 ? "2.2.0" : "3.0.2") + ".jar";
}
private int getLuceneVersion() {
private static int getLuceneVersion() {
// use Lucene 2 for H2 1.2.x, and Lucene 3 for H2 1.3.x.
String s = new String(readFile(new File("src/main/org/h2/engine/Constants.java")));
int idx = s.indexOf("VERSION_MINOR") + "VERSION_MINOR".length() + 3;
......@@ -279,7 +279,7 @@ public class Build extends BuildBase {
return Integer.parseInt(System.getProperty("lucene", "" + version));
}
private String getJarSuffix() {
private static String getJarSuffix() {
return "-" + getVersion() + ".jar";
}
......@@ -318,7 +318,7 @@ public class Build extends BuildBase {
updateChecksum("../h2web/html/download.html", sha1Zip, sha1Exe);
}
private void updateChecksum(String fileName, String sha1Zip, String sha1Exe) {
private static void updateChecksum(String fileName, String sha1Zip, String sha1Exe) {
String checksums = new String(readFile(new File(fileName)));
checksums = replaceAll(checksums, "<!-- sha1Zip -->",
"(SHA1 checksum: " + sha1Zip + ")");
......@@ -468,7 +468,7 @@ public class Build extends BuildBase {
copy("docs/javadocImpl", files("src/docsrc/javadoc"), "src/docsrc/javadoc");
}
private void manifest(String title, String mainClassName) {
private static void manifest(String title, String mainClassName) {
String manifest = new String(readFile(new File("src/main/META-INF/MANIFEST.MF")));
manifest = replaceAll(manifest, "${title}", title);
manifest = replaceAll(manifest, "${version}", getVersion());
......
......@@ -236,7 +236,7 @@ public class BuildBase {
}
}
private Object invoke(Method m, Object instance, Object[] args) {
private static Object invoke(Method m, Object instance, Object[] args) {
try {
try {
return m.invoke(instance, args);
......@@ -290,7 +290,7 @@ public class BuildBase {
sysOut.println();
}
private boolean isWindows() {
private static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0;
}
......@@ -340,7 +340,7 @@ public class BuildBase {
}
}
private void copyInThread(final InputStream in, final OutputStream out) {
private static void copyInThread(final InputStream in, final OutputStream out) {
new Thread() {
public void run() {
try {
......@@ -367,7 +367,7 @@ public class BuildBase {
* @param fieldName the field name
* @return the value as a string
*/
protected String getStaticField(String className, String fieldName) {
protected static String getStaticField(String className, String fieldName) {
try {
Class<?> clazz = Class.forName(className);
Field field = clazz.getField(fieldName);
......@@ -384,7 +384,7 @@ public class BuildBase {
* @param methodName the field name
* @return the value as a string
*/
protected String getStaticValue(String className, String methodName) {
protected static String getStaticValue(String className, String methodName) {
try {
Class<?> clazz = Class.forName(className);
Method method = clazz.getMethod(methodName);
......@@ -485,7 +485,7 @@ public class BuildBase {
}
}
private String convertBytesToString(byte[] value) {
private static String convertBytesToString(byte[] value) {
StringBuilder buff = new StringBuilder(value.length * 2);
for (byte c : value) {
int x = c & 0xff;
......@@ -501,7 +501,7 @@ public class BuildBase {
* @param data the byte array
* @return the SHA1 checksum
*/
protected String getSHA1(byte[] data) {
protected static String getSHA1(byte[] data) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
......@@ -580,7 +580,7 @@ public class BuildBase {
* @param args the arguments
* @return the string list
*/
protected StringList args(String...args) {
protected static StringList args(String...args) {
return new StringList(args);
}
......@@ -597,7 +597,7 @@ public class BuildBase {
}
}
private String removeBase(String basePath, String path) {
private static String removeBase(String basePath, String path) {
if (path.startsWith(basePath)) {
path = path.substring(basePath.length());
}
......@@ -653,7 +653,7 @@ public class BuildBase {
* @param fileName the file name
* @return the suffix or an empty string if there is none
*/
String getSuffix(String fileName) {
static String getSuffix(String fileName) {
int idx = fileName.lastIndexOf('.');
return idx < 0 ? "" : fileName.substring(idx);
}
......@@ -686,7 +686,7 @@ public class BuildBase {
println("Zip " + destFile + " (" + kb + " KB)");
}
private long zipOrJar(String destFile, FileList files, String basePath, boolean storeOnly, boolean sortBySuffix, boolean jar) {
private static long zipOrJar(String destFile, FileList files, String basePath, boolean storeOnly, boolean sortBySuffix, boolean jar) {
if (sortBySuffix) {
// for better compressibility, sort by suffix, then name
Collections.sort(files, new Comparator<File>() {
......@@ -742,11 +742,11 @@ public class BuildBase {
*
* @return the java specification version
*/
protected String getJavaSpecVersion() {
protected static String getJavaSpecVersion() {
return System.getProperty("java.specification.version");
}
private List<String> getPaths(FileList files) {
private static List<String> getPaths(FileList files) {
StringList list = new StringList();
for (File f : files) {
list.add(f.getPath());
......@@ -811,7 +811,7 @@ public class BuildBase {
*
* @param dir the directory to create
*/
protected void mkdir(String dir) {
protected static void mkdir(String dir) {
File f = new File(dir);
if (f.exists()) {
if (f.isFile()) {
......@@ -822,7 +822,7 @@ public class BuildBase {
}
}
private void mkdirs(File f) {
private static void mkdirs(File f) {
if (!f.exists()) {
if (!f.mkdirs()) {
throw new RuntimeException("Can not create directory " + f.getAbsolutePath());
......
......@@ -31,7 +31,7 @@ public class BnfSyntax implements BnfVisitor {
*/
public String getHtml(Bnf bnf, String syntaxLines) {
syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", "\n");
StringTokenizer tokenizer = bnf.getTokenizer(syntaxLines);
StringTokenizer tokenizer = Bnf.getTokenizer(syntaxLines);
StringBuilder buff = new StringBuilder();
while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken();
......
......@@ -176,7 +176,7 @@ public class GenerateDoc {
}
}
private String addCode(String text) {
private static String addCode(String text) {
text = StringUtils.replaceAll(text, "&quot;", "\"");
StringBuilder buff = new StringBuilder(text.length());
int len = text.length();
......
......@@ -26,10 +26,6 @@ public class GenerateHelp {
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
new GenerateHelp().run();
}
private void run() throws Exception {
String in = "src/docsrc/help/help.csv";
String out = "src/main/org/h2/res/help.csv";
Csv csv = Csv.getInstance();
......
......@@ -219,7 +219,7 @@ public class LinkChecker {
}
}
private void error(String fileName, String string) {
private static void error(String fileName, String string) {
System.out.println("ERROR with " + fileName + ": " + string);
}
......
......@@ -60,7 +60,7 @@ public class MergeDocs {
writer.close();
}
private String disableRailroads(String text) {
private static String disableRailroads(String text) {
text = StringUtils.replaceAll(text, "<!-- railroad-start -->", "<!-- railroad-start ");
text = StringUtils.replaceAll(text, "<!-- railroad-end -->", " railroad-end -->");
text = StringUtils.replaceAll(text, "<!-- syntax-start", "<!-- syntax-start -->");
......@@ -68,7 +68,7 @@ public class MergeDocs {
return text;
}
private String removeHeaderFooter(String fileName, String text) {
private static String removeHeaderFooter(String fileName, String text) {
// String start = "<body";
// String end = "</body>";
......
......@@ -98,7 +98,7 @@ public class RailroadImages {
}
}
private BufferedImage flipHorizontal(BufferedImage img) {
private static BufferedImage flipHorizontal(BufferedImage img) {
int w = img.getWidth(), h = img.getHeight();
BufferedImage copy = new BufferedImage(w, h, img.getType());
Graphics2D g = copy.createGraphics();
......
......@@ -53,7 +53,7 @@ public class XMLChecker {
}
}
private void processFile(String fileName) throws Exception {
private static void processFile(String fileName) throws Exception {
int idx = fileName.lastIndexOf('.');
if (idx < 0) {
return;
......
......@@ -427,7 +427,7 @@ public class Doclet {
return false;
}
private Type getReturnType(ExecutableMemberDoc method) {
private static Type getReturnType(ExecutableMemberDoc method) {
if (method instanceof MethodDoc) {
MethodDoc m = (MethodDoc) method;
return m.returnType();
......
......@@ -43,10 +43,6 @@ public class PrepareTranslation {
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
new PrepareTranslation().run();
}
private void run() throws Exception {
String baseDir = "src/docsrc/textbase";
prepare(baseDir, "src/main/org/h2/res", true);
prepare(baseDir, "src/main/org/h2/server/web/res", true);
......@@ -391,7 +387,7 @@ public class PrepareTranslation {
prop.setProperty(document, s);
}
private void prepare(String baseDir, String path, boolean utf8) throws IOException {
private static void prepare(String baseDir, String path, boolean utf8) throws IOException {
String suffix = utf8 ? ".prop" : ".properties";
File dir = new File(path);
File main = null;
......@@ -435,7 +431,7 @@ public class PrepareTranslation {
}
}
private void prepare(Properties main, Properties base, File trans, boolean utf8) throws IOException {
private static void prepare(Properties main, Properties base, File trans, boolean utf8) throws IOException {
SortedProperties p = load(trans.getAbsolutePath(), utf8);
Properties oldTranslations = new Properties();
for (Object k : base.keySet()) {
......
......@@ -354,7 +354,7 @@ public class Indexer {
}
}
private String convertUTF(String s) {
private static String convertUTF(String s) {
s = StringUtils.quoteJavaString(s);
s = s.substring(1, s.length() - 1);
return s;
......
......@@ -214,7 +214,7 @@ public class FtpControl extends Thread {
if ("PWD".equals(command)) {
reply(257, StringUtils.quoteIdentifier(currentDir) + " directory");
} else if ("PASV".equals(command)) {
ServerSocket dataSocket = server.createDataSocket();
ServerSocket dataSocket = FtpServer.createDataSocket();
data = new FtpData(server, control.getInetAddress(), dataSocket);
data.start();
int port = dataSocket.getLocalPort();
......
......@@ -215,7 +215,7 @@ public class FtpServer extends Tool implements Service {
*
* @return the server socket
*/
ServerSocket createDataSocket() {
static ServerSocket createDataSocket() {
return NetUtils.createServerSocket(0, false);
}
......
......@@ -537,7 +537,7 @@ public class PgTcpRedirect {
* @param buffer the byte array
* @param len the length
*/
synchronized void printData(byte[] buffer, int len) {
synchronized static void printData(byte[] buffer, int len) {
if (DEBUG) {
System.out.print(" ");
for (int i = 0; i < len; i++) {
......
......@@ -22,7 +22,7 @@ public class ArrayUtils {
* @param right the index of the rightmost element
* @param comp the comparison class
*/
public <T> void binaryInsertionSort(T[] d, int left, int right, Comparator<T> comp) {
public static <T> void binaryInsertionSort(T[] d, int left, int right, Comparator<T> comp) {
for (int i = left + 1; i <= right; i++) {
T t = d[i];
int l = left;
......@@ -50,7 +50,7 @@ public class ArrayUtils {
* @param right the index of the rightmost element
* @param comp the comparison class
*/
public <T> void insertionSort(T[] d, int left, int right, Comparator<T> comp) {
public static <T> void insertionSort(T[] d, int left, int right, Comparator<T> comp) {
for (int i = left + 1, j; i <= right; i++) {
T t = d[i];
for (j = i - 1; j >= left && comp.compare(d[j], t) > 0; j--) {
......
......@@ -86,7 +86,7 @@ public class FileViewer extends Tool {
}
}
private void process(String fileName, String find, boolean head, boolean tail, long start, int lines, boolean quiet) throws IOException {
private static void process(String fileName, String find, boolean head, boolean tail, long start, int lines, boolean quiet) throws IOException {
RandomAccessFile file = new RandomAccessFile(fileName, "r");
long length = file.length();
if (head) {
......@@ -121,7 +121,7 @@ public class FileViewer extends Tool {
}
}
private long find(RandomAccessFile file, byte[] find, boolean quiet) throws IOException {
private static long find(RandomAccessFile file, byte[] find, boolean quiet) throws IOException {
long pos = file.getFilePointer();
long length = file.length();
int bufferSize = 4 * 1024;
......@@ -150,7 +150,7 @@ public class FileViewer extends Tool {
return -1;
}
private int find(byte[] data, byte[] find, int max) {
private static int find(byte[] data, byte[] find, int max) {
outer:
for (int i = 0; i < max; i++) {
for (int j = 0; j < find.length; j++) {
......@@ -163,7 +163,7 @@ public class FileViewer extends Tool {
return -1;
}
private void list(long pos, String header, ArrayList<String> list) {
private static void list(long pos, String header, ArrayList<String> list) {
System.out.println("-----------------------------------------------");
System.out.println("[" + pos + "]: " + header);
System.out.println("-----------------------------------------------");
......@@ -173,7 +173,7 @@ public class FileViewer extends Tool {
System.out.println("-----------------------------------------------");
}
private ArrayList<String> readLines(RandomAccessFile file, int maxLines) throws IOException {
private static ArrayList<String> readLines(RandomAccessFile file, int maxLines) throws IOException {
ArrayList<String> lines = new ArrayList<String>();
ByteArrayOutputStream buff = new ByteArrayOutputStream(100);
boolean lastNewline = false;
......
......@@ -93,7 +93,7 @@ public class Migrate {
new File(TEMP_SCRIPT).delete();
}
private String getJavaExecutablePath() {
private static String getJavaExecutablePath() {
String pathToJava;
if (File.separator.equals("\\")) {
pathToJava = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe";
......@@ -149,7 +149,7 @@ public class Migrate {
writeFile(targetFile, data);
}
private void mkdirs(File f) {
private static void mkdirs(File f) {
if (!f.exists()) {
if (!f.mkdirs()) {
throw new RuntimeException("Can not create directory " + f.getAbsolutePath());
......@@ -169,7 +169,7 @@ public class Migrate {
}
}
private String getSHA1(byte[] data) {
private static String getSHA1(byte[] data) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
......@@ -179,7 +179,7 @@ public class Migrate {
}
}
private String convertBytesToString(byte[] value) {
private static String convertBytesToString(byte[] value) {
StringBuilder buff = new StringBuilder(value.length * 2);
for (byte c : value) {
int x = c & 0xff;
......@@ -216,7 +216,7 @@ public class Migrate {
}
}
private void copyInThread(final InputStream in, final OutputStream out) {
private static void copyInThread(final InputStream in, final OutputStream out) {
new Thread() {
public void run() {
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论