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

Require Java 1.5 compiler

上级 24c3b0e8
......@@ -46,7 +46,7 @@ public class BuildBase {
/**
* A list of strings.
*/
public static class StringList extends ArrayList<String> implements List<String> {
public static class StringList extends ArrayList<String> {
private static final long serialVersionUID = 1L;
......@@ -86,7 +86,7 @@ public class BuildBase {
/**
* A list of files.
*/
public static class FileList extends ArrayList<File> implements List<File> {
public static class FileList extends ArrayList<File> {
private static final long serialVersionUID = 1L;
......@@ -276,12 +276,12 @@ public class BuildBase {
protected int exec(String command, StringList args) {
try {
print(command);
for (String a : args) {
print(" " + a);
}
StringList cmd = new StringList();
cmd = cmd.plus(command);
if (args != null) {
for (String a : args) {
print(" " + a);
}
cmd.addAll(args);
}
println("");
......@@ -324,7 +324,7 @@ public class BuildBase {
*/
protected String getStaticField(String className, String fieldName) {
try {
Class clazz = Class.forName(className);
Class< ? > clazz = Class.forName(className);
Field field = clazz.getField(fieldName);
return field.get(null).toString();
} catch (Exception e) {
......
......@@ -38,11 +38,10 @@ public class MergeDocs {
"performance.html", "advanced.html", "grammar.html", "functions.html", "datatypes.html", "build.html",
"history.html", "faq.html" };
StringBuffer buff = new StringBuffer();
for (int i = 0; i < pages.length; i++) {
String fileName = pages[i];
for (String fileName : pages) {
String text = getContent(fileName);
for (int j = 0; j < pages.length; j++) {
text = StringUtils.replaceAll(text, pages[j] + "#", "#");
for (String page : pages) {
text = StringUtils.replaceAll(text, page + "#", "#");
}
text = removeHeaderFooter(fileName, text);
buff.append(text);
......
......@@ -11,7 +11,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.h2.build.BuildBase;
......@@ -32,9 +31,9 @@ public class SpellChecker {
private static final String PREFIX_IGNORE = "abc";
private static final String IGNORE_FILE = "mainWeb.html";
private HashSet dictionary = new HashSet();
private HashSet used = new HashSet();
private HashMap unknown = new HashMap();
private HashSet<String> dictionary = new HashSet<String>();
private HashSet<String> used = new HashSet<String>();
private HashMap<String, Integer> unknown = new HashMap<String, Integer>();
private boolean debug;
private boolean printDictionary;
private boolean addToDictionary;
......@@ -61,8 +60,7 @@ public class SpellChecker {
used.toArray(list);
Arrays.sort(list);
StringBuffer buff = new StringBuffer();
for (int i = 0; i < list.length; i++) {
String s = list[i];
for (String s : list) {
if (buff.length() > 0) {
if (buff.length() + s.length() > 80) {
System.out.println(buff.toString());
......@@ -78,9 +76,8 @@ public class SpellChecker {
if (unknown.size() > 0) {
System.out.println();
System.out.println("UNKNOWN WORDS");
for (Iterator it = unknown.keySet().iterator(); it.hasNext();) {
String s = (String) it.next();
// int count = ((Integer) unknown.get(s)).intValue();
for (String s : unknown.keySet()) {
// int count = unknown.get(s);
System.out.print(s + " ");
errorCount++;
}
......@@ -101,9 +98,8 @@ public class SpellChecker {
return;
}
if (file.isDirectory()) {
File[] list = file.listFiles();
for (int i = 0; i < list.length; i++) {
process(list[i]);
for (File f : file.listFiles()) {
process(f);
}
} else {
String fileName = file.getAbsolutePath();
......@@ -115,8 +111,8 @@ public class SpellChecker {
suffix = fileName.substring(idx + 1);
}
boolean ignore = false;
for (int i = 0; i < IGNORE.length; i++) {
if (IGNORE[i].equals(suffix)) {
for (String s : IGNORE) {
if (s.equals(suffix)) {
ignore = true;
break;
}
......@@ -128,8 +124,8 @@ public class SpellChecker {
return;
}
boolean ok = false;
for (int i = 0; i < SUFFIX.length; i++) {
if (SUFFIX[i].equals(suffix)) {
for (String s : SUFFIX) {
if (s.equals(suffix)) {
ok = true;
break;
}
......@@ -148,7 +144,7 @@ public class SpellChecker {
}
private void scan(String fileName, String text) {
HashSet notFound = new HashSet();
HashSet<String> notFound = new HashSet<String>();
text = removeLinks(fileName, text);
StringTokenizer tokenizer = new StringTokenizer(text, DELIMITERS);
while (tokenizer.hasMoreTokens()) {
......@@ -170,8 +166,7 @@ public class SpellChecker {
}
if (notFound.size() > 0) {
System.out.println("file: " + fileName);
for (Iterator it = notFound.iterator(); it.hasNext();) {
String s = (String) it.next();
for (String s : notFound) {
System.out.print(s + " ");
}
System.out.println();
......@@ -208,7 +203,7 @@ public class SpellChecker {
return changed;
}
private void scanCombinedToken(HashSet notFound, String token) {
private void scanCombinedToken(HashSet<String> notFound, String token) {
for (int i = 1; i < token.length(); i++) {
char charLeft = token.charAt(i - 1);
char charRight = token.charAt(i);
......@@ -225,7 +220,7 @@ public class SpellChecker {
scanToken(notFound, token);
}
private void scanToken(HashSet notFound, String token) {
private void scanToken(HashSet<String> notFound, String token) {
if (token.length() < 3) {
return;
}
......@@ -267,9 +262,9 @@ public class SpellChecker {
}
}
private void increment(HashMap map, String key) {
Integer value = (Integer) map.get(key);
value = new Integer(value == null ? 0 : value.intValue() + 1);
private void increment(HashMap<String, Integer> map, String key) {
Integer value = map.get(key);
value = new Integer(value == null ? 0 : value + 1);
map.put(key, value);
contextCount = 10;
}
......
......@@ -139,9 +139,8 @@ public class UploadBuild {
private static void addFiles(File base, File file, ZipOutputStream out) throws IOException {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
addFiles(base, files[i], out);
for (File f : file.listFiles()) {
addFiles(base, f, out);
}
} else {
String path = file.getAbsolutePath().substring(base.getAbsolutePath().length());
......
......@@ -31,7 +31,7 @@ public class WebSite {
private String sourceDir = "docs";
private String webDir = "../h2web";
private HashMap fragments = new HashMap();
private HashMap<String, String> fragments = new HashMap<String, String>();
/**
* This method is called when executing this application from the command
......@@ -56,9 +56,7 @@ public class WebSite {
private void loadFragments() throws IOException {
File dir = new File(sourceDir, "html");
File[] list = dir.listFiles();
for (int i = 0; i < list.length; i++) {
File f = list[i];
for (File f : dir.listFiles()) {
if (f.getName().startsWith("fragments")) {
FileInputStream in = new FileInputStream(f);
byte[] bytes = IOUtils.readBytesAndClose(in, 0);
......@@ -78,7 +76,7 @@ public class WebSite {
int end = fileName.indexOf('.');
language = fileName.substring(index, end);
}
String fragment = (String) fragments.get("fragments" + language + ".html");
String fragment = fragments.get("fragments" + language + ".html");
int start = 0;
while (true) {
start = fragment.indexOf("<!-- [", start);
......@@ -106,9 +104,8 @@ public class WebSite {
private void deleteRecursive(File dir) {
if (dir.isDirectory()) {
File[] list = dir.listFiles();
for (int i = 0; i < list.length; i++) {
deleteRecursive(list[i]);
for (File f : dir.listFiles()) {
deleteRecursive(f);
}
}
dir.delete();
......@@ -117,9 +114,8 @@ public class WebSite {
private void copy(File source, File target, boolean replaceFragments, boolean web) throws IOException {
if (source.isDirectory()) {
target.mkdirs();
File[] list = source.listFiles();
for (int i = 0; i < list.length; i++) {
copy(list[i], new File(target, list[i].getName()), replaceFragments, web);
for (File f : source.listFiles()) {
copy(f, new File(target, f.getName()), replaceFragments, web);
}
} else {
String name = source.getName();
......
......@@ -45,9 +45,8 @@ public class XMLChecker {
}
File file = new File(path);
if (file.isDirectory()) {
String[] list = file.list();
for (int i = 0; i < list.length; i++) {
process(path + "/" + list[i]);
for (String name : file.list()) {
process(path + "/" + name);
}
} else {
processFile(path);
......@@ -84,7 +83,7 @@ public class XMLChecker {
// use this for html file, for example if <li> is not closed
String[] noClose = new String[] {};
XMLParser parser = new XMLParser(xml);
Stack stack = new Stack();
Stack<Object[]> stack = new Stack<Object[]>();
boolean rootElement = false;
while (true) {
int event = parser.next();
......@@ -98,29 +97,33 @@ public class XMLChecker {
rootElement = true;
}
String name = parser.getName();
for (int i = 0; html && i < noClose.length; i++) {
if (name.equals(noClose[i])) {
name = null;
break;
if (html) {
for (String n : noClose) {
if (name.equals(n)) {
name = null;
break;
}
}
}
if (name != null) {
stack.add(new Object[] { name, new Integer(parser.getPos()) });
stack.add(new Object[] { name, parser.getPos() });
}
} else if (event == XMLParser.END_ELEMENT) {
String name = parser.getName();
for (int i = 0; html && i < noClose.length; i++) {
if (name.equals(noClose[i])) {
throw new Exception("Unnecessary closing element " + name + " at " + parser.getRemaining());
if (html) {
for (String n : noClose) {
if (name.equals(n)) {
throw new Exception("Unnecessary closing element " + name + " at " + parser.getRemaining());
}
}
}
while (true) {
Object[] pop = (Object[]) stack.pop();
Object[] pop = stack.pop();
String p = (String) pop[0];
if (p.equals(name)) {
break;
}
String remaining = xml.substring(((Integer) pop[1]).intValue());
String remaining = xml.substring((Integer) pop[1]);
if (remaining.length() > 100) {
remaining = remaining.substring(0, 100);
}
......
......@@ -35,7 +35,7 @@ public class Doclet {
private static final boolean INTERFACES_ONLY = Boolean.getBoolean("h2.interfacesOnly");
private String destDir = System.getProperty("h2.destDir", "docs/javadoc");
private int errorCount;
private HashSet errors = new HashSet();
private HashSet<String> errors = new HashSet<String>();
/**
* This method is called by the javadoc framework and is required for all
......@@ -51,13 +51,12 @@ public class Doclet {
private boolean startDoc(RootDoc root) throws IOException {
ClassDoc[] classes = root.classes();
String[][] options = root.options();
for (int i = 0; i < options.length; i++) {
if (options[i][0].equals("destdir")) {
destDir = options[i][1];
for (String[] op : options) {
if (op[0].equals("destdir")) {
destDir = op[1];
}
}
for (int i = 0; i < classes.length; ++i) {
ClassDoc clazz = classes[i];
for (ClassDoc clazz : classes) {
processClass(clazz);
}
if (errorCount > 0) {
......@@ -98,12 +97,12 @@ public class Doclet {
// methods
MethodDoc[] methods = clazz.methods();
Arrays.sort(methods, new Comparator() {
public int compare(Object a, Object b) {
return ((MethodDoc) a).name().compareTo(((MethodDoc) b).name());
Arrays.sort(methods, new Comparator<MethodDoc>() {
public int compare(MethodDoc a, MethodDoc b) {
return a.name().compareTo(b.name());
}
});
ArrayList signatures = new ArrayList();
ArrayList<String> signatures = new ArrayList<String>();
boolean hasMethods = false;
int id = 0;
for (int i = 0; i < methods.length; i++) {
......@@ -166,14 +165,13 @@ public class Doclet {
if (clazz.interfaces().length > 0) {
fields = clazz.interfaces()[0].fields();
}
Arrays.sort(fields, new Comparator() {
public int compare(Object a, Object b) {
return ((FieldDoc) a).name().compareTo(((FieldDoc) b).name());
Arrays.sort(fields, new Comparator<FieldDoc>() {
public int compare(FieldDoc a, FieldDoc b) {
return a.name().compareTo(b.name());
}
});
int fieldId = 0;
for (int i = 0; i < fields.length; i++) {
FieldDoc field = fields[i];
for (FieldDoc field : fields) {
if (skipField(clazz, field)) {
continue;
}
......@@ -208,20 +206,17 @@ public class Doclet {
}
// field details
Arrays.sort(fields, new Comparator() {
public int compare(Object a, Object b) {
FieldDoc fa = (FieldDoc) a;
FieldDoc fb = (FieldDoc) b;
String ca = fa.constantValueExpression();
String cb = fb.constantValueExpression();
Arrays.sort(fields, new Comparator<FieldDoc>() {
public int compare(FieldDoc a, FieldDoc b) {
String ca = a.constantValueExpression();
String cb = b.constantValueExpression();
if (ca != null && cb != null) {
return ca.compareTo(cb);
}
return fa.name().compareTo(fb.name());
return a.name().compareTo(b.name());
}
});
for (int i = 0; i < fields.length; i++) {
FieldDoc field = fields[i];
for (FieldDoc field : fields) {
writeFieldDetails(writer, clazz, field);
}
......@@ -329,9 +324,9 @@ public class Doclet {
}
if (hasThrowsTag) {
writer.println("<div class=\"itemTitle\">Throws:</div>");
for (int j = 0; j < throwsTags.length; j++) {
String p = throwsTags[j].exceptionName();
String c = throwsTags[j].exceptionComment();
for (ThrowsTag tag : throwsTags) {
String p = tag.exceptionName();
String c = tag.exceptionComment();
if (c.length() > 0) {
p += " - " + c;
}
......@@ -420,17 +415,14 @@ public class Doclet {
private boolean foundMethod(ClassDoc clazz, boolean include, String methodName, int parameterCount) {
if (include) {
MethodDoc[] ms = clazz.methods();
for (int j = 0; j < ms.length; j++) {
MethodDoc m = ms[j];
for (MethodDoc m : clazz.methods()) {
if (m.name().equals(methodName) && m.parameters().length == parameterCount) {
return true;
}
}
}
ClassDoc[] ifs = clazz.interfaces();
for (int i = 0; i < ifs.length; i++) {
if (foundMethod(ifs[i], true, methodName, parameterCount)) {
for (ClassDoc doc : clazz.interfaces()) {
if (foundMethod(doc, true, methodName, parameterCount)) {
return true;
}
}
......
......@@ -41,27 +41,24 @@ public class ResourceDoclet {
private boolean startDoc(RootDoc root) throws IOException {
ClassDoc[] classes = root.classes();
String[][] options = root.options();
for (int i = 0; i < options.length; i++) {
if (options[i][0].equals("dest")) {
destFile = options[i][1];
for (String[] op : options) {
if (op[0].equals("dest")) {
destFile = op[1];
}
}
for (int i = 0; i < classes.length; ++i) {
ClassDoc clazz = classes[i];
for (ClassDoc clazz : classes) {
processClass(clazz);
}
resources.store(destFile);
return true;
}
private void processClass(ClassDoc clazz) throws IOException {
private void processClass(ClassDoc clazz) {
String packageName = clazz.containingPackage().name();
String className = clazz.name();
addResource(packageName + "." + className, clazz);
MethodDoc[] methods = clazz.methods();
for (int i = 0; i < methods.length; i++) {
MethodDoc method = methods[i];
for (MethodDoc method : clazz.methods()) {
String name = method.name();
addResource(packageName + "." + className + "." + name, method);
}
......@@ -124,9 +121,7 @@ public class ResourceDoclet {
}
private static boolean isResource(Doc doc) {
Tag[] tags = doc.tags();
for (int j = 0; j < tags.length; j++) {
Tag t = tags[j];
for (Tag t : doc.tags()) {
if (t.kind().equals("@h2.resource")) {
return true;
}
......
......@@ -57,7 +57,7 @@ public class PropertiesToUTF8 {
FileOutputStream out = new FileOutputStream(target);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
// keys is sorted
for (Enumeration en = prop.keys(); en.hasMoreElements();) {
for (Enumeration<Object> en = prop.keys(); en.hasMoreElements();) {
String key = (String) en.nextElement();
String value = prop.getProperty(key, null);
writer.println("@" + key);
......@@ -117,9 +117,7 @@ public class PropertiesToUTF8 {
}
private static void convert(String source) throws Exception {
File[] list = new File(source).listFiles();
for (int i = 0; list != null && i < list.length; i++) {
File f = list[i];
for (File f : new File(source).listFiles()) {
if (!f.getName().endsWith(".properties")) {
continue;
}
......
......@@ -14,8 +14,8 @@ import java.util.HashMap;
*/
public class HtmlConverter {
private static HashMap charMap = new HashMap();
private static HashMap codeMap = new HashMap();
private static HashMap<String, Character> charMap = new HashMap<String, Character>();
private static HashMap<Character, String> codeMap = new HashMap<Character, String>();
private static final String[] CHARS = { "quot:34", "amp:38", "lt:60", "gt:62", "nbsp:160", "iexcl:161", "cent:162",
"pound:163", "curren:164", "yen:165", "brvbar:166", "sect:167", "uml:168", "copy:169", "ordf:170",
......@@ -55,8 +55,7 @@ public class HtmlConverter {
}
static {
for (int i = 0; i < CHARS.length; i++) {
String token = CHARS[i];
for (String token : CHARS) {
int idx = token.indexOf(':');
String key = token.substring(0, idx);
int ch = Integer.parseInt(token.substring(idx + 1));
......@@ -82,8 +81,7 @@ public class HtmlConverter {
StringBuffer buff = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
Character c = new Character(ch);
String token = (String) codeMap.get(c);
String token = codeMap.get(ch);
if (token == null) {
if (ch < 128) {
buff.append(ch);
......@@ -144,7 +142,7 @@ public class HtmlConverter {
repl = null;
}
} else {
repl = (Character) charMap.get(key);
repl = charMap.get(key);
}
if (repl == null) {
buff.append("???" + key + "???");
......
......@@ -36,14 +36,14 @@ public class Indexer {
"also;back;after;use;two;how;our;work;first;well;way;even;new;want;" +
"because;any;these;give;most;us;";
private ArrayList pages = new ArrayList();
private ArrayList<Page> pages = new ArrayList<Page>();
/**
* Lower case word to Word map.
*/
private HashMap words = new HashMap();
private HashSet noIndex = new HashSet();
private ArrayList wordList;
private HashMap<String, Word> words = new HashMap<String, Word>();
private HashSet<String> noIndex = new HashSet<String>();
private ArrayList <Word>wordList;
private int totalAllWeights;
private PrintWriter output;
private Page page;
......@@ -92,20 +92,18 @@ public class Indexer {
}
private void setNoIndex(String[] strings) {
for (int i = 0; i < strings.length; i++) {
noIndex.add(strings[i]);
for (String s : strings) {
noIndex.add(s);
}
}
private void sortWords() {
ArrayList names = new ArrayList(words.keySet());
for (int i = 0; i < names.size(); i++) {
String name = (String) names.get(i);
for (String name : words.keySet()) {
if (name.endsWith("s")) {
String singular = name.substring(0, name.length() - 1);
if (words.containsKey(singular)) {
Word wp = (Word) words.get(name);
Word ws = (Word) words.get(singular);
Word wp = words.get(name);
Word ws = words.get(singular);
ws.addAll(wp);
words.remove(name);
}
......@@ -113,12 +111,12 @@ public class Indexer {
words.remove(name);
}
}
wordList = new ArrayList(words.values());
wordList = new ArrayList<Word>(words.values());
// ignored very common words (to shrink the index)
String ignored = "";
int maxSize = pages.size() / 4;
for (int i = 0; i < wordList.size(); i++) {
Word word = (Word) wordList.get(i);
Word word = wordList.get(i);
String search = ";" + word.name.toLowerCase() + ";";
int idxCommon = VERY_COMMON.indexOf(search);
if (word.pages.size() >= maxSize || idxCommon >= 0) {
......@@ -133,23 +131,20 @@ public class Indexer {
// output.println("var ignored = '" + convertUTF(ignored) + "'");
// TODO support A, B, C,... class links in the index file and use them
// for combined AND searches
Collections.sort(wordList, new Comparator() {
public int compare(Object o0, Object o1) {
Word w0 = (Word) o0;
Word w1 = (Word) o1;
Collections.sort(wordList, new Comparator<Word>() {
public int compare(Word w0, Word w1) {
return w0.name.compareToIgnoreCase(w1.name);
}
});
}
private void removeOverflowRelations() {
for (int i = 0; i < wordList.size(); i++) {
Word word = (Word) wordList.get(i);
ArrayList weights = word.getSortedWeights();
for (Word word : wordList) {
ArrayList<Weight> weights = word.getSortedWeights();
int max = MAX_RELATIONS;
if (weights.size() > max) {
while (max < weights.size()) {
Weight weight = (Weight) weights.get(max);
Weight weight = weights.get(max);
if (weight.value < Weight.HEADER) {
break;
}
......@@ -157,7 +152,7 @@ public class Indexer {
}
}
while (max < weights.size()) {
Weight weight = (Weight) weights.get(max);
Weight weight = weights.get(max);
weights.remove(max);
weight.page.relations--;
}
......@@ -165,22 +160,19 @@ public class Indexer {
}
private void sortPages() {
Collections.sort(pages, new Comparator() {
public int compare(Object o0, Object o1) {
Page p0 = (Page) o0;
Page p1 = (Page) o1;
Collections.sort(pages, new Comparator<Page>() {
public int compare(Page p0, Page p1) {
return p0.relations == p1.relations ? 0 : p0.relations < p1.relations ? 1 : -1;
}
});
for (int i = 0; i < pages.size(); i++) {
Page page = (Page) pages.get(i);
Page page = pages.get(i);
page.id = i;
}
}
private void listPages() {
for (int i = 0; i < pages.size(); i++) {
Page page = (Page) pages.get(i);
for (Page page : pages) {
output.println("pages[" + page.id + "]=new Page('" + convertUTF(page.title) + "', '" + page.fileName
+ "');");
}
......@@ -190,9 +182,8 @@ public class Indexer {
String name = file.getName();
String fileName = dir.length() > 0 ? dir + "/" + name : level > 0 ? name : "";
if (file.isDirectory()) {
File[] list = file.listFiles();
for (int i = 0; i < list.length; i++) {
readPages(fileName, list[i], level + 1);
for (File f : file.listFiles()) {
readPages(fileName, f, level + 1);
}
return;
}
......@@ -216,9 +207,8 @@ public class Indexer {
String first = "";
int firstLen = 1;
int totalRelations = 0;
for (int i = 0; i < wordList.size(); i++) {
Word word = (Word) wordList.get(i);
ArrayList weights = word.getSortedWeights();
for (Word word : wordList) {
ArrayList<Weight> weights = word.getSortedWeights();
String lower = StringUtils.toLowerEnglish(word.name);
if (!first.equals(lower.substring(0, firstLen))) {
if (buff.length() > 0) {
......@@ -235,7 +225,7 @@ public class Indexer {
String weightString = "r";
totalRelations += weights.size();
for (int j = 0; j < weights.size(); j++) {
Weight weight = (Weight) weights.get(j);
Weight weight = weights.get(j);
Page page = weight.page;
if (j > 0) {
buff.append(",");
......@@ -356,7 +346,7 @@ public class Indexer {
continue;
}
String lower = StringUtils.toLowerEnglish(token);
Word word = (Word) words.get(lower);
Word word = words.get(lower);
if (word == null) {
word = new Word(token);
words.put(lower, word);
......
......@@ -10,8 +10,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
/**
* Represents a word of the full text index.
......@@ -26,9 +25,9 @@ public class Word {
/**
* The pages map.
*/
HashMap pages = new HashMap();
HashMap<Page, Weight> pages = new HashMap<Page, Weight>();
private ArrayList weightList;
private ArrayList<Weight> weightList;
Word(String name) {
this.name = name;
......@@ -41,7 +40,7 @@ public class Word {
* @param weight the weight of this word in this page
*/
void addPage(Page page, int weight) {
Weight w = (Weight) pages.get(page);
Weight w = pages.get(page);
if (w == null) {
w = new Weight();
w.page = page;
......@@ -61,21 +60,18 @@ public class Word {
* @param other the other word
*/
void addAll(Word other) {
for (Iterator it = other.pages.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Page p = (Page) entry.getKey();
Weight w = (Weight) entry.getValue();
for (Entry<Page, Weight> entry : other.pages.entrySet()) {
Page p = entry.getKey();
Weight w = entry.getValue();
addPage(p, w.value);
}
}
ArrayList getSortedWeights() {
ArrayList<Weight> getSortedWeights() {
if (weightList == null) {
weightList = new ArrayList(pages.values());
Collections.sort(weightList, new Comparator() {
public int compare(Object o0, Object o1) {
Weight w0 = (Weight) o0;
Weight w1 = (Weight) o1;
weightList = new ArrayList<Weight>(pages.values());
Collections.sort(weightList, new Comparator<Weight>() {
public int compare(Weight w0, Weight w1) {
return w0.value < w1.value ? 1 : w0.value == w1.value ? 0 : -1;
}
});
......
......@@ -303,9 +303,7 @@ public class FtpClient {
* @param dir the directory to remove
*/
public void removeDirectoryRecursive(String dir) throws IOException {
File[] list = listFiles(dir);
for (int i = 0; i < list.length; i++) {
File f = list[i];
for (File f : listFiles(dir)) {
if (f.isDirectory()) {
removeDirectoryRecursive(dir + "/" + f.getName());
} else {
......@@ -351,9 +349,8 @@ public class FtpClient {
if (file.isDirectory()) {
makeDirectory(file.getName());
changeWorkingDirectory(file.getName());
File[] list = file.listFiles();
for (int i = 0; i < list.length; i++) {
storeRecursive(list[i]);
for (File f : file.listFiles()) {
storeRecursive(f);
}
changeWorkingDirectory("..");
} else {
......@@ -430,9 +427,8 @@ public class FtpClient {
* @return true if it exists
*/
public boolean exists(String dir, String name) throws IOException {
File[] list = listFiles(dir);
for (int i = 0; i < list.length; i++) {
if (list[i].getName().equals(name)) {
for (File f : listFiles(dir)) {
if (f.getName().equals(name)) {
return true;
}
}
......
......@@ -80,7 +80,7 @@ public class FtpServer extends Tool implements Service {
private String root = DEFAULT_ROOT;
private String writeUserName = DEFAULT_WRITE, writePassword = DEFAULT_WRITE_PASSWORD;
private String readUserName = DEFAULT_READ;
private HashMap tasks = new HashMap();
private HashMap<String, Process> tasks = new HashMap<String, Process>();
private FileSystem fs;
private boolean trace;
......@@ -295,10 +295,8 @@ public class FtpServer extends Tool implements Service {
* @return the list
*/
String getDirectoryListing(String directory, boolean listDirectories) throws SQLException {
String[] list = fs.listFiles(directory);
StringBuffer buff = new StringBuffer();
for (int i = 0; list != null && i < list.length; i++) {
String fileName = list[i];
for (String fileName : fs.listFiles(directory)) {
if (!fs.isDirectory(fileName) || (fs.isDirectory(fileName) && listDirectories)) {
appendFile(buff, fileName);
}
......@@ -512,7 +510,7 @@ public class FtpServer extends Tool implements Service {
*/
void stopTask(String processName) {
trace("kill process: " + processName);
Process p = (Process) tasks.remove(processName);
Process p = tasks.remove(processName);
if (p == null) {
return;
}
......
......@@ -50,9 +50,9 @@ public class SecureKeyStoreBuilder {
System.out.println("KeyStore store = KeyStore.getInstance(\""+store.getType()+"\");");
System.out.println("store.load(null, password.toCharArray());");
//System.out.println("keystore provider="+store.getProvider().getName());
Enumeration en = store.aliases();
Enumeration<String> en = store.aliases();
while (en.hasMoreElements()) {
String alias = (String) en.nextElement();
String alias = en.nextElement();
Key key = store.getKey(alias, password.toCharArray());
System.out.println("KeyFactory keyFactory = KeyFactory.getInstance(\"" + key.getAlgorithm() + "\");");
System.out.println("store.load(null, password.toCharArray());");
......@@ -61,10 +61,8 @@ public class SecureKeyStoreBuilder {
System.out.println(pkFormat + "EncodedKeySpec keySpec = new " + pkFormat + "EncodedKeySpec(getBytes(\""
+ encoded + "\"));");
System.out.println("PrivateKey privateKey = keyFactory.generatePrivate(keySpec);");
System.out.println("Certificate[] certs = new Certificate[]{");
Certificate[] certs = store.getCertificateChain(alias);
for (int i = 0; i < certs.length; i++) {
Certificate cert = certs[i];
System.out.println("Certificate[] certs = new Certificate[] {");
for (Certificate cert : store.getCertificateChain(alias)) {
System.out.println(" CertificateFactory.getInstance(\""+cert.getType()+"\").");
String enc = ByteUtils.convertBytesToString(cert.getEncoded());
System.out.println(" generateCertificate(new ByteArrayInputStream(getBytes(\""+enc+"\"))),");
......
......@@ -105,7 +105,7 @@ public class FileViewer extends Tool {
}
if (tail) {
long pos = length - 100 * lines;
ArrayList list = null;
ArrayList<String> list = null;
while (pos > 0) {
file.seek(pos);
list = readLines(file, Integer.MAX_VALUE);
......@@ -165,18 +165,18 @@ public class FileViewer extends Tool {
return -1;
}
private void list(long pos, String header, ArrayList list) {
private void list(long pos, String header, ArrayList<String> list) {
System.out.println("-----------------------------------------------");
System.out.println("[" + pos + "]: " + header);
System.out.println("-----------------------------------------------");
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
for (String l : list) {
System.out.println(l);
}
System.out.println("-----------------------------------------------");
}
private ArrayList readLines(RandomAccessFile file, int maxLines) throws IOException {
ArrayList lines = new ArrayList();
private ArrayList<String> readLines(RandomAccessFile file, int maxLines) throws IOException {
ArrayList<String> lines = new ArrayList<String>();
ByteArrayOutputStream buff = new ByteArrayOutputStream(100);
boolean lastNewline = false;
while (maxLines > 0) {
......
......@@ -22,7 +22,7 @@ class Condition<A> implements Token {
this.y = y;
}
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
query.appendSQL(stat, x);
stat.appendSQL(" ");
stat.appendSQL(compareType.getString());
......
......@@ -20,7 +20,7 @@ enum ConditionAndOr implements Token {
this.text = text;
}
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL(text);
}
......
......@@ -30,7 +30,7 @@ public class Db {
Utils.newWeakIdentityHashMap();
private final Connection conn;
private final Map<Class, TableDefinition> classMap = Utils.newHashMap();
private final Map<Class< ? >, TableDefinition< ? >> classMap = Utils.newHashMap();
Db(Connection conn) {
this.conn = conn;
......@@ -94,9 +94,9 @@ public class Db {
}
<T> TableDefinition<T> define(Class<T> clazz) {
TableDefinition def = classMap.get(clazz);
TableDefinition<T> def = getTableDefinition(clazz);
if (def == null) {
def = new TableDefinition(clazz);
def = new TableDefinition<T>(clazz);
def.mapFields();
classMap.put(clazz, def);
if (Table.class.isAssignableFrom(clazz)) {
......@@ -134,8 +134,9 @@ public class Db {
}
}
TableDefinition getTableDefinition(Class< ? > clazz) {
return classMap.get(clazz);
@SuppressWarnings("unchecked")
<T> TableDefinition<T> getTableDefinition(Class<T> clazz) {
return (TableDefinition<T>) classMap.get(clazz);
}
ResultSet executeQuery(String sql) {
......
......@@ -13,7 +13,7 @@ package org.h2.jaqu;
//## Java 1.5 begin ##
public class Define {
private static TableDefinition currentTableDefinition;
private static TableDefinition< ? > currentTableDefinition;
private static Table currentTable;
public static void primaryKey(Object... columns) {
......@@ -35,7 +35,7 @@ public class Define {
currentTableDefinition.setTableName(tableName);
}
static synchronized void define(TableDefinition tableDefinition, Table table) {
static synchronized <T> void define(TableDefinition<T> tableDefinition, Table table) {
currentTableDefinition = tableDefinition;
currentTable = table;
tableDefinition.mapObject(table);
......
......@@ -26,7 +26,7 @@ public class Function implements Token {
this.x = x;
}
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL(name);
stat.appendSQL("(");
for (int i = 0; i < x.length; i++) {
......@@ -47,6 +47,7 @@ public class Function implements Token {
Utils.newObject(Integer.class), new Function("LENGTH", x));
}
@SuppressWarnings("unchecked")
public static <T extends Number> T sum(T x) {
return (T) Db.registerToken(
Utils.newObject(x.getClass()), new Function("SUM", x));
......@@ -60,7 +61,7 @@ public class Function implements Token {
public static Boolean isNull(Object x) {
return Db.registerToken(
Utils.newObject(Boolean.class), new Function("", x) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
query.appendSQL(stat, x[0]);
stat.appendSQL(" IS NULL");
}
......@@ -70,7 +71,7 @@ public class Function implements Token {
public static Boolean isNotNull(Object x) {
return Db.registerToken(
Utils.newObject(Boolean.class), new Function("", x) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
query.appendSQL(stat, x[0]);
stat.appendSQL(" IS NOT NULL");
}
......@@ -80,7 +81,7 @@ public class Function implements Token {
public static Boolean not(Boolean x) {
return Db.registerToken(
Utils.newObject(Boolean.class), new Function("", x) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("NOT ");
query.appendSQL(stat, x[0]);
}
......@@ -91,7 +92,7 @@ public class Function implements Token {
return Db.registerToken(
Utils.newObject(Boolean.class),
new Function("", (Object[]) x) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
for (int i = 0; i < x.length; i++) {
if (i > 0) {
stat.appendSQL(" OR ");
......@@ -106,7 +107,7 @@ public class Function implements Token {
return Db.registerToken(
Utils.newObject(Boolean.class),
new Function("", (Object[]) x) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
for (int i = 0; i < x.length; i++) {
if (i > 0) {
stat.appendSQL(" AND ");
......@@ -117,12 +118,14 @@ public class Function implements Token {
});
}
@SuppressWarnings("unchecked")
public static <X> X min(X x) {
Class<X> clazz = (Class<X>) x.getClass();
X o = Utils.newObject(clazz);
return Db.registerToken(o, new Function("MIN", x));
}
@SuppressWarnings("unchecked")
public static <X> X max(X x) {
Class<X> clazz = (Class<X>) x.getClass();
X o = Utils.newObject(clazz);
......@@ -132,7 +135,7 @@ public class Function implements Token {
public static Boolean like(String x, String pattern) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function("LIKE", x, pattern) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" LIKE ");
......
......@@ -9,17 +9,17 @@ package org.h2.jaqu;
/**
* An expression to order by in a query.
*
* @param <T> the expression data type
* @param <T> the query data type
*/
//## Java 1.5 begin ##
class OrderExpression<T> {
private Query query;
private T expression;
private Query<T> query;
private Object expression;
private boolean desc;
private boolean nullsFirst;
private boolean nullsLast;
OrderExpression(Query query, T expression, boolean desc,
OrderExpression(Query<T> query, Object expression, boolean desc,
boolean nullsFirst, boolean nullsLast) {
this.query = query;
this.expression = expression;
......
......@@ -27,19 +27,20 @@ public class Query<T> {
private Db db;
private SelectTable<T> from;
private ArrayList<Token> conditions = Utils.newArrayList();
private ArrayList<SelectTable> joins = Utils.newArrayList();
private final HashMap<Object, SelectColumn> aliasMap = Utils.newHashMap();
private ArrayList<OrderExpression> orderByList = Utils.newArrayList();
private ArrayList<SelectTable< ? >> joins = Utils.newArrayList();
private final HashMap<Object, SelectColumn<T>> aliasMap = Utils.newHashMap();
private ArrayList<OrderExpression<T>> orderByList = Utils.newArrayList();
private Object[] groupByExpressions;
Query(Db db) {
this.db = db;
}
@SuppressWarnings("unchecked")
static <T> Query<T> from(Db db, T alias) {
Query<T> query = new Query<T>(db);
TableDefinition def = db.define(alias.getClass());
query.from = new SelectTable(db, query, alias, false);
TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());
query.from = new SelectTable<T>(db, query, alias, false);
def.initSelectObject(query.from, alias, query.aliasMap);
return query;
}
......@@ -65,6 +66,7 @@ public class Query<T> {
return select(true);
}
@SuppressWarnings("unchecked")
public <X, Z> X selectFirst(Z x) {
List<X> list = (List<X>) select(x);
return list.isEmpty() ? null : list.get(0);
......@@ -109,6 +111,7 @@ public class Query<T> {
return select(x, false);
}
@SuppressWarnings("unchecked")
private <X, Z> List<X> select(Z x, boolean distinct) {
Class< ? > clazz = x.getClass();
if (Utils.isSimpleType(clazz)) {
......@@ -135,6 +138,7 @@ public class Query<T> {
return result;
}
@SuppressWarnings("unchecked")
private <X> List<X> getSimple(X x, boolean distinct) {
SqlStatement selectList = new SqlStatement(db);
appendSQL(selectList, x);
......@@ -175,16 +179,16 @@ public class Query<T> {
//## Java 1.5 begin ##
public Query<T> orderBy(Object... expressions) {
for (Object expr : expressions) {
OrderExpression<Object> e =
new OrderExpression<Object>(this, expr, false, false, false);
OrderExpression<T> e =
new OrderExpression<T>(this, expr, false, false, false);
addOrderBy(e);
}
return this;
}
public Query<T> orderByDesc(Object expr) {
OrderExpression<Object> e =
new OrderExpression<Object>(this, expr, true, false, false);
OrderExpression<T> e =
new OrderExpression<T>(this, expr, true, false, false);
addOrderBy(e);
return this;
}
......@@ -204,7 +208,7 @@ public class Query<T> {
token.appendSQL(stat, this);
return;
}
SelectColumn col = aliasMap.get(x);
SelectColumn<T> col = aliasMap.get(x);
if (col != null) {
col.appendSQL(stat);
return;
......@@ -227,6 +231,7 @@ public class Query<T> {
}
}
@SuppressWarnings("unchecked")
SqlStatement prepare(SqlStatement selectList, boolean distinct) {
SqlStatement stat = selectList;
String selectSQL = stat.getSQL();
......@@ -275,9 +280,10 @@ public class Query<T> {
* @return the joined query
*/
//## Java 1.5 begin ##
public QueryJoin innerJoin(Object alias) {
TableDefinition def = db.define(alias.getClass());
SelectTable join = new SelectTable(db, this, alias, false);
@SuppressWarnings("unchecked")
public <U> QueryJoin innerJoin(U alias) {
TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());
SelectTable<T> join = new SelectTable(db, this, alias, false);
def.initSelectObject(join, alias, aliasMap);
joins.add(join);
return new QueryJoin(this, join);
......@@ -291,11 +297,11 @@ public class Query<T> {
return !joins.isEmpty();
}
SelectColumn getSelectColumn(Object obj) {
SelectColumn<T> getSelectColumn(Object obj) {
return aliasMap.get(obj);
}
void addOrderBy(OrderExpression expr) {
void addOrderBy(OrderExpression<T> expr) {
orderByList.add(expr);
}
......
......@@ -13,9 +13,9 @@ package org.h2.jaqu;
public class QueryJoin {
private Query< ? > query;
private SelectTable join;
private SelectTable< ? > join;
QueryJoin(Query< ? > query, SelectTable join) {
QueryJoin(Query< ? > query, SelectTable< ? > join) {
this.query = query;
this.join = join;
}
......
......@@ -15,10 +15,10 @@ package org.h2.jaqu;
public class QueryJoinCondition<A> {
private Query< ? > query;
private SelectTable join;
private SelectTable< ? > join;
private A x;
QueryJoinCondition(Query< ? > query, SelectTable join, A x) {
QueryJoinCondition(Query< ? > query, SelectTable< ? > join, A x) {
this.query = query;
this.join = join;
this.x = x;
......
......@@ -35,7 +35,7 @@ public class QueryWhere<T> {
}
public <X, Z> List<X> select(Z x) {
return (List<X>) query.select(x);
return query.select(x);
}
public String getSQL() {
......@@ -45,11 +45,11 @@ public class QueryWhere<T> {
}
public <X, Z> List<X> selectDistinct(Z x) {
return (List<X>) query.selectDistinct(x);
return query.selectDistinct(x);
}
public <X, Z> X selectFirst(Z x) {
List<X> list = (List<X>) query.select(x);
List<X> list = query.select(x);
return list.isEmpty() ? null : list.get(0);
}
......@@ -77,44 +77,44 @@ public class QueryWhere<T> {
//## Java 1.5 begin ##
public QueryWhere<T> orderBy(Object... expressions) {
for (Object expr : expressions) {
OrderExpression<Object> e =
new OrderExpression<Object>(query, expr, false, false, false);
OrderExpression<T> e =
new OrderExpression<T>(query, expr, false, false, false);
query.addOrderBy(e);
}
return this;
}
public QueryWhere<T> orderByNullsFirst(Object expr) {
OrderExpression<Object> e =
new OrderExpression<Object>(query, expr, false, true, false);
OrderExpression<T> e =
new OrderExpression<T>(query, expr, false, true, false);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByNullsLast(Object expr) {
OrderExpression<Object> e =
new OrderExpression<Object>(query, expr, false, false, true);
OrderExpression<T> e =
new OrderExpression<T>(query, expr, false, false, true);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByDesc(Object expr) {
OrderExpression<Object> e =
new OrderExpression<Object>(query, expr, true, false, false);
OrderExpression<T> e =
new OrderExpression<T>(query, expr, true, false, false);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByDescNullsFirst(Object expr) {
OrderExpression<Object> e =
new OrderExpression<Object>(query, expr, true, true, false);
OrderExpression<T> e =
new OrderExpression<T>(query, expr, true, true, false);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByDescNullsLast(Object expr) {
OrderExpression<Object> e =
new OrderExpression<Object>(query, expr, true, false, true);
OrderExpression<T> e =
new OrderExpression<T>(query, expr, true, false, true);
query.addOrderBy(e);
return this;
}
......
......@@ -13,14 +13,14 @@ import org.h2.jaqu.TableDefinition.FieldDefinition;
/**
* This class represents a column of a table in a query.
*
* @param <X> the column data type
* @param <T> the table data type
*/
//## Java 1.5 begin ##
class SelectColumn<X> {
private SelectTable selectTable;
private FieldDefinition<X> fieldDef;
class SelectColumn<T> {
private SelectTable<T> selectTable;
private FieldDefinition fieldDef;
SelectColumn(SelectTable table, FieldDefinition<X> fieldDef) {
SelectColumn(SelectTable<T> table, FieldDefinition fieldDef) {
this.selectTable = table;
this.fieldDef = fieldDef;
}
......@@ -33,11 +33,11 @@ class SelectColumn<X> {
}
}
FieldDefinition<X> getFieldDefinition() {
FieldDefinition getFieldDefinition() {
return fieldDef;
}
SelectTable getSelectTable() {
SelectTable<T> getSelectTable() {
return selectTable;
}
......
......@@ -22,7 +22,7 @@ import org.h2.jaqu.util.Utils;
class SelectTable <T> {
private static int asCounter;
private Query query;
private Query<T> query;
private Class<T> clazz;
private T current;
private String as;
......@@ -30,10 +30,11 @@ class SelectTable <T> {
private boolean outerJoin;
private ArrayList<Token> joinConditions = Utils.newArrayList();
SelectTable(Db db, Query query, T alias, boolean outerJoin) {
@SuppressWarnings("unchecked")
SelectTable(Db db, Query<T> query, T alias, boolean outerJoin) {
this.query = query;
this.outerJoin = outerJoin;
aliasDef = db.getTableDefinition(alias.getClass());
aliasDef = (TableDefinition<T>) db.getTableDefinition(alias.getClass());
clazz = ClassUtils.getClass(alias);
as = "T" + asCounter++;
}
......@@ -42,7 +43,7 @@ class SelectTable <T> {
return Utils.newObject(clazz);
}
TableDefinition getAliasDefinition() {
TableDefinition<T> getAliasDefinition() {
return aliasDef;
}
......@@ -54,7 +55,7 @@ class SelectTable <T> {
}
}
void appendSQLAsJoin(SqlStatement stat, Query query) {
void appendSQLAsJoin(SqlStatement stat, Query<T> query) {
if (outerJoin) {
stat.appendSQL(" LEFT OUTER JOIN ");
} else {
......@@ -74,7 +75,7 @@ class SelectTable <T> {
return outerJoin;
}
Query getQuery() {
Query<T> getQuery() {
return query;
}
......
......@@ -20,7 +20,7 @@ import java.util.ArrayList;
public class SqlStatement {
private Db db;
private String sql = "";
private ArrayList params = new ArrayList();
private ArrayList<Object> params = new ArrayList<Object>();
SqlStatement(Db db) {
this.db = db;
......
......@@ -41,7 +41,7 @@ class TableDefinition<T> {
* The meta data of a field.
*/
//## Java 1.5 begin ##
static class FieldDefinition<X> {
static class FieldDefinition {
String columnName;
Field field;
String dataType;
......@@ -69,10 +69,9 @@ class TableDefinition<T> {
}
}
@SuppressWarnings("unchecked")
X read(ResultSet rs, int columnIndex) {
Object read(ResultSet rs, int columnIndex) {
try {
return (X) rs.getObject(columnIndex);
return rs.getObject(columnIndex);
} catch (SQLException e) {
throw new RuntimeException(e);
}
......@@ -184,7 +183,7 @@ class TableDefinition<T> {
stat.executeUpdate();
}
TableDefinition createTableIfRequired(Db db) {
TableDefinition<T> createTableIfRequired(Db db) {
SqlStatement stat = new SqlStatement(db);
StringBuilder buff = new StringBuilder("CREATE TABLE IF NOT EXISTS ");
buff.append(tableName);
......@@ -232,11 +231,11 @@ class TableDefinition<T> {
}
}
void initSelectObject(SelectTable table, Object obj,
Map<Object, SelectColumn> map) {
void initSelectObject(SelectTable<T> table, Object obj,
Map<Object, SelectColumn<T>> map) {
for (FieldDefinition def : fields) {
def.initWithNewObject(obj);
SelectColumn column = new SelectColumn(table, def);
SelectColumn<T> column = new SelectColumn<T>(table, def);
map.put(def.getValue(obj), column);
}
}
......@@ -249,7 +248,7 @@ class TableDefinition<T> {
}
}
<X> SqlStatement getSelectList(Query query, X x) {
<Y, X> SqlStatement getSelectList(Query<Y> query, X x) {
SqlStatement selectList = new SqlStatement(query.getDb());
for (int i = 0; i < fields.size(); i++) {
if (i > 0) {
......@@ -262,10 +261,10 @@ class TableDefinition<T> {
return selectList;
}
<U, X> void copyAttributeValues(Query query, X to, X map) {
<Y, X> void copyAttributeValues(Query<Y> query, X to, X map) {
for (FieldDefinition def : fields) {
Object obj = def.getValue(map);
SelectColumn col = query.getSelectColumn(obj);
SelectColumn<Y> col = query.getSelectColumn(obj);
Object value = col.getCurrentValue();
def.setValue(to, value);
}
......
......@@ -25,7 +25,7 @@ public class TestCondition<A> {
public Boolean is(A y) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function("=", x, y) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" = ");
......@@ -38,7 +38,7 @@ public class TestCondition<A> {
public Boolean bigger(A y) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function(">", x, y) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" > ");
......@@ -51,7 +51,7 @@ public class TestCondition<A> {
public Boolean biggerEqual(A y) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function(">=", x, y) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" >= ");
......@@ -64,7 +64,7 @@ public class TestCondition<A> {
public Boolean smaller(A y) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function("<", x, y) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" < ");
......@@ -77,7 +77,7 @@ public class TestCondition<A> {
public Boolean smallerEqual(A y) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function("<=", x, y) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" <= ");
......@@ -90,7 +90,7 @@ public class TestCondition<A> {
public Boolean like(A pattern) {
Boolean o = Utils.newObject(Boolean.class);
return Db.registerToken(o, new Function("LIKE", x, pattern) {
public void appendSQL(SqlStatement stat, Query query) {
public <T> void appendSQL(SqlStatement stat, Query<T> query) {
stat.appendSQL("(");
query.appendSQL(stat, x[0]);
stat.appendSQL(" LIKE ");
......
......@@ -10,7 +10,13 @@ package org.h2.jaqu;
* Classes implementing this interface can be used as a token in a statement.
*/
interface Token {
/**
* Append the SQL to the given statement using the given query.
*
* @param stat the statement to append the SQL to
* @param query the query to use
*/
//## Java 1.5 begin ##
void appendSQL(SqlStatement stat, Query query);
<T> void appendSQL(SqlStatement stat, Query<T> query);
//## Java 1.5 end ##
}
......@@ -20,8 +20,7 @@ public class ClassUtils {
//## Java 1.5 begin ##
@SuppressWarnings("unchecked")
public
static <X> Class<X> getClass(X x) {
public static <X> Class<X> getClass(X x) {
return (Class<X>) x.getClass();
}
......
......@@ -128,7 +128,7 @@ public class Utils {
if (o == null) {
return null;
}
Class currentType = o.getClass();
Class< ? > currentType = o.getClass();
if (currentType == targetType) {
return o;
}
......
......@@ -24,7 +24,7 @@ import java.util.Set;
//## Java 1.5 begin ##
public class WeakIdentityHashMap<K, V> implements Map<K, V> {
private static final int MAX_LOAD = 90;
private static final WeakReference DELETED_KEY = new WeakReference(null);
private static final WeakReference<Object> DELETED_KEY = new WeakReference<Object>(null);
private int mask, len, size, deletedCount, level;
private int maxSize, minSize, maxDeleted;
private WeakReference<K>[] keys;
......@@ -59,6 +59,7 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> {
return System.identityHashCode(key) & mask;
}
@SuppressWarnings("unchecked")
private void reset(int newLevel) {
minSize = size * 3 / 4;
size = 0;
......@@ -139,8 +140,9 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> {
return null;
}
@SuppressWarnings("unchecked")
private void delete(int index) {
keys[index] = DELETED_KEY;
keys[index] = (WeakReference<K>) DELETED_KEY;
values[index] = null;
deletedCount++;
size--;
......
......@@ -101,7 +101,7 @@ public class FunctionsMySQL {
* @param timestamp the timestamp
* @return the current timestamp in seconds (not milliseconds).
*/
public static int unixTimestamp(java.sql.Timestamp timestamp) throws SQLException {
public static int unixTimestamp(java.sql.Timestamp timestamp) {
return (int) (timestamp.getTime() / 1000L);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论