summaryrefslogtreecommitdiff
path: root/java/demo
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-05-18 14:03:42 -0700
committerMark Spruiell <mes@zeroc.com>2009-05-18 14:03:42 -0700
commitb30ccc77d3a9822c6ffcebf9b45945822df200bc (patch)
tree94105ea42fa81ad0b8731b05a46c7f64304dec55 /java/demo
parentRemoved Freeze.UseNonmutating (diff)
downloadice-b30ccc77d3a9822c6ffcebf9b45945822df200bc.tar.bz2
ice-b30ccc77d3a9822c6ffcebf9b45945822df200bc.tar.xz
ice-b30ccc77d3a9822c6ffcebf9b45945822df200bc.zip
bug 252 - Freeze finalizers
bug 2552 - Update Freeze for Java5
Diffstat (limited to 'java/demo')
-rw-r--r--java/demo/Freeze/bench/Client.java86
-rw-r--r--java/demo/Freeze/bench/build.xml2
-rw-r--r--java/demo/Freeze/casino/build.xml2
-rw-r--r--java/demo/Freeze/library/Grammar.java14
-rw-r--r--java/demo/Freeze/library/LibraryI.java6
-rw-r--r--java/demo/Freeze/library/Parser.java36
-rw-r--r--java/demo/Freeze/library/build.xml2
-rw-r--r--java/demo/Freeze/phonebook/Grammar.java16
-rw-r--r--java/demo/Freeze/phonebook/build.xml2
-rw-r--r--java/demo/Freeze/transform/Create.java21
-rw-r--r--java/demo/Freeze/transform/Read.java44
-rw-r--r--java/demo/Freeze/transform/ReadNew.java51
-rw-r--r--java/demo/Freeze/transform/Recreate.java21
-rw-r--r--java/demo/Freeze/transform/build.xml2
-rw-r--r--java/demo/book/freeze_filesystem/build.xml2
15 files changed, 137 insertions, 170 deletions
diff --git a/java/demo/Freeze/bench/Client.java b/java/demo/Freeze/bench/Client.java
index 946dae1c76d..8a795cb63ee 100644
--- a/java/demo/Freeze/bench/Client.java
+++ b/java/demo/Freeze/bench/Client.java
@@ -12,7 +12,7 @@ import Demo.*;
class Client extends Ice.Application
{
void
- IntIntMapTest(Freeze.Map m, boolean fast)
+ IntIntMapTest(Freeze.Map<Integer, Integer> m, boolean fast)
{
//
// Populate the database.
@@ -23,14 +23,14 @@ class Client extends Ice.Application
{
for(int i = 0; i < _repetitions; ++i)
{
- m.fastPut(new Integer(i), new Integer(i));
+ m.fastPut(i, i);
}
}
else
{
for(int i = 0; i < _repetitions; ++i)
{
- m.put(new Integer(i), new Integer(i));
+ m.put(i, i);
}
}
tx.commit();
@@ -47,7 +47,7 @@ class Client extends Ice.Application
_watch.start();
for(int i = 0; i < _repetitions; ++i)
{
- Integer n = (Integer)m.get(new Integer(i));
+ Integer n = m.get(i);
test(n.intValue() == i);
}
total = _watch.stop();
@@ -65,20 +65,19 @@ class Client extends Ice.Application
_watch.start();
for(int i = 0; i < _repetitions; ++i)
{
- java.util.Iterator p = indexedM.findByValue(i);
+ java.util.Iterator<java.util.Map.Entry<Integer, Integer>> p = indexedM.findByValue(i);
test(p.hasNext());
- java.util.Map.Entry e = (java.util.Map.Entry)p.next();
- test(((Integer)e.getKey()).intValue() == i);
+ java.util.Map.Entry<Integer, Integer> e = p.next();
+ test(e.getKey().intValue() == i);
m.closeAllIterators();
}
total = _watch.stop();
perRecord = total / _repetitions;
-
+
System.out.println("\ttime for " + _repetitions + " indexed reads: " + total + "ms");
System.out.println("\ttime per indexed read: " + perRecord + "ms");
}
-
//
// Remove each record.
//
@@ -88,14 +87,14 @@ class Client extends Ice.Application
{
for(int i = 0; i < _repetitions; ++i)
{
- test(m.fastRemove(new Integer(i)));
+ test(m.fastRemove(i));
}
}
else
{
for(int i = 0; i < _repetitions; ++i)
{
- Integer n = (Integer)m.remove(new Integer(i));
+ Integer n = m.remove(i);
test(n.intValue() == i);
}
}
@@ -163,7 +162,7 @@ class Client extends Ice.Application
public String
toString()
{
- return new Integer((_max - _min)+1).toString();
+ return new Integer((_max - _min) + 1).toString();
}
private int _min;
@@ -172,20 +171,19 @@ class Client extends Ice.Application
}
void
- generatedRead(Freeze.Map m, int reads, Generator gen)
+ generatedRead(Freeze.Map<Integer, Integer> m, int reads, Generator gen)
{
_watch.start();
for(int i = 0; i < reads; ++i)
{
int key = gen.next();
- Integer n = (Integer)m.get(new Integer(key));
+ Integer n = m.get(key);
test(n.intValue() == key);
}
double total = _watch.stop();
double perRecord = total / reads;
- System.out.println("\ttime for " + reads + " reads of " + gen + " records: " +
- total + "ms");
+ System.out.println("\ttime for " + reads + " reads of " + gen + " records: " + total + "ms");
System.out.println("\ttime per read: " + perRecord + "ms");
if(m instanceof IndexedIntIntMap)
@@ -195,23 +193,23 @@ class Client extends Ice.Application
for(int i = 0; i < reads; ++i)
{
int val = gen.next();
- java.util.Iterator p = indexedM.findByValue(val);
+ java.util.Iterator<java.util.Map.Entry<Integer, Integer>> p = indexedM.findByValue(val);
test(p.hasNext());
- java.util.Map.Entry e = (java.util.Map.Entry)p.next();
- test(((Integer)e.getKey()).intValue() == val);
+ java.util.Map.Entry<Integer, Integer> e = p.next();
+ test(e.getKey().intValue() == val);
m.closeAllIterators();
}
total = _watch.stop();
perRecord = total / reads;
-
- System.out.println("\ttime for " + reads + " reverse (indexed) reads of " + gen + " records: " +
- total + "ms");
+
+ System.out.println("\ttime for " + reads + " reverse (indexed) reads of " + gen + " records: " + total +
+ "ms");
System.out.println("\ttime per reverse (indexed) read: " + perRecord + "ms");
}
}
void
- IntIntMapReadTest(Freeze.Map m)
+ IntIntMapReadTest(Freeze.Map<Integer, Integer> m)
{
//
// Populate the database.
@@ -220,7 +218,7 @@ class Client extends Ice.Application
Freeze.Transaction tx = _connection.beginTransaction();
for(int i = 0; i < _repetitions; ++i)
{
- m.fastPut(new Integer(i), new Integer(i));
+ m.fastPut(i, i);
}
tx.commit();
double total = _watch.stop();
@@ -252,7 +250,7 @@ class Client extends Ice.Application
_watch.start();
for(int i = 0; i < _repetitions; ++i)
{
- test(m.fastRemove(new Integer(i)));
+ test(m.fastRemove(i));
}
total = _watch.stop();
perRecord = total / _repetitions;
@@ -265,7 +263,7 @@ class Client extends Ice.Application
}
void
- Struct1Struct2MapTest(Freeze.Map m)
+ Struct1Struct2MapTest(Freeze.Map<Struct1, Struct2> m)
{
//
// Populate the database.
@@ -295,7 +293,7 @@ class Client extends Ice.Application
for(int i = 0; i < _repetitions; ++i)
{
s1.l = i;
- Struct2 ns2 = (Struct2)m.get(s1);
+ Struct2 ns2 = m.get(s1);
test(ns2.s.equals(new Integer(i).toString()));
}
total = _watch.stop();
@@ -304,7 +302,6 @@ class Client extends Ice.Application
System.out.println("\ttime for " + _repetitions + " reads: " + total + "ms");
System.out.println("\ttime per read: " + perRecord + "ms");
-
//
// Optional index test
//
@@ -316,20 +313,20 @@ class Client extends Ice.Application
for(int i = 0; i < _repetitions; ++i)
{
String s = (new Integer(i)).toString();
- java.util.Iterator p = indexedM.findByS(s);
+ java.util.Iterator<java.util.Map.Entry<Struct1, Struct2>> p = indexedM.findByS(s);
test(p.hasNext());
- java.util.Map.Entry e = (java.util.Map.Entry)p.next();
- test(((Struct1)e.getKey()).l == i);
+ java.util.Map.Entry<Struct1, Struct2> e = p.next();
+ test(e.getKey().l == i);
m.closeAllIterators();
}
for(int i = 0; i < _repetitions; ++i)
{
s1.l = i;
- java.util.Iterator p = indexedM.findByS1(s1);
+ java.util.Iterator<java.util.Map.Entry<Struct1, Struct2>> p = indexedM.findByS1(s1);
test(p.hasNext());
- java.util.Map.Entry e = (java.util.Map.Entry)p.next();
- test(((Struct1)e.getKey()).l == i);
+ java.util.Map.Entry<Struct1, Struct2> e = p.next();
+ test(e.getKey().l == i);
m.closeAllIterators();
}
total = _watch.stop();
@@ -360,7 +357,7 @@ class Client extends Ice.Application
}
void
- Struct1Class1MapTest(Freeze.Map m)
+ Struct1Class1MapTest(Freeze.Map<Struct1, Class1> m)
{
//
// Populate the database.
@@ -389,7 +386,7 @@ class Client extends Ice.Application
for(int i = 0; i < _repetitions; ++i)
{
s1.l = i;
- Class1 nc1 = (Class1)m.get(s1);
+ Class1 nc1 = m.get(s1);
test(nc1.s.equals(new Integer(i).toString()));
}
total = _watch.stop();
@@ -398,7 +395,6 @@ class Client extends Ice.Application
System.out.println("\ttime for " + _repetitions + " reads: " + total + "ms");
System.out.println("\ttime per read: " + perRecord + "ms");
-
//
// Optional index test
//
@@ -410,10 +406,10 @@ class Client extends Ice.Application
for(int i = 0; i < _repetitions; ++i)
{
String s = (new Integer(i)).toString();
- java.util.Iterator p = indexedM.findByS(s);
+ java.util.Iterator<java.util.Map.Entry<Struct1, Class1>> p = indexedM.findByS(s);
test(p.hasNext());
- java.util.Map.Entry e = (java.util.Map.Entry)p.next();
- test(((Struct1)e.getKey()).l == i);
+ java.util.Map.Entry<Struct1, Class1> e = p.next();
+ test(e.getKey().l == i);
m.closeAllIterators();
}
@@ -445,7 +441,7 @@ class Client extends Ice.Application
}
void
- Struct1ObjectMapTest(Freeze.Map m)
+ Struct1ObjectMapTest(Freeze.Map<Struct1, Ice.Object> m)
{
//
// Populate the database.
@@ -460,7 +456,7 @@ class Client extends Ice.Application
for(int i = 0; i < _repetitions; ++i)
{
s1.l = i;
- Object o;
+ Ice.Object o;
if((i % 2) == 0)
{
o = c2;
@@ -489,7 +485,7 @@ class Client extends Ice.Application
{
s1.l = i;
- Object o = m.get(s1);
+ Ice.Object o = m.get(s1);
Class1 nc1;
if((i % 2) == 0)
@@ -530,7 +526,7 @@ class Client extends Ice.Application
m.close();
}
-
+
public int
run(String[] args)
{
@@ -559,7 +555,7 @@ class Client extends Ice.Application
System.out.println("Struct1Struct2Map with index");
Struct1Struct2MapTest(new IndexedStruct1Struct2Map(_connection, "IndexedStruct1Struct2", true));
-
+
System.out.println("Struct1Class1Map");
Struct1Class1MapTest(new Struct1Class1Map(_connection, "Struct1Class1", true));
diff --git a/java/demo/Freeze/bench/build.xml b/java/demo/Freeze/bench/build.xml
index 3b81ad1637b..1bbdc29419a 100644
--- a/java/demo/Freeze/bench/build.xml
+++ b/java/demo/Freeze/bench/build.xml
@@ -56,7 +56,7 @@
<exclude name="${generated.dir}/**"/>
<classpath>
<path refid="ice.classpath"/>
- <path refid="db.classpath"/>
+ <path refid="freeze.classpath"/>
</classpath>
<compilerarg value="${javac.lint}"/>
</javac>
diff --git a/java/demo/Freeze/casino/build.xml b/java/demo/Freeze/casino/build.xml
index 99e67437810..72f8f9dc214 100644
--- a/java/demo/Freeze/casino/build.xml
+++ b/java/demo/Freeze/casino/build.xml
@@ -35,7 +35,7 @@
<exclude name="${generated.dir}/**"/>
<classpath>
<path refid="ice.classpath"/>
- <path refid="db.classpath"/>
+ <path refid="freeze.classpath"/>
</classpath>
<compilerarg value="${javac.lint}"/>
</javac>
diff --git a/java/demo/Freeze/library/Grammar.java b/java/demo/Freeze/library/Grammar.java
index c261cc0921e..1541c3b3b36 100644
--- a/java/demo/Freeze/library/Grammar.java
+++ b/java/demo/Freeze/library/Grammar.java
@@ -53,7 +53,7 @@ class Grammar
}
else if(_token.type == Token.TOK_ADD_BOOK)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -62,7 +62,7 @@ class Grammar
}
else if(_token.type == Token.TOK_FIND_ISBN)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -71,7 +71,7 @@ class Grammar
}
else if(_token.type == Token.TOK_FIND_AUTHORS)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -100,7 +100,7 @@ class Grammar
}
else if(_token.type == Token.TOK_RENT_BOOK)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -128,7 +128,7 @@ class Grammar
}
else if(_token.type == Token.TOK_SET_EVICTOR_SIZE)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -157,10 +157,10 @@ class Grammar
}
}
- private java.util.List
+ private java.util.List<String>
strings()
{
- java.util.List l = new java.util.ArrayList();
+ java.util.List<String> l = new java.util.ArrayList<String>();
while(true)
{
_token = _scanner.nextToken();
diff --git a/java/demo/Freeze/library/LibraryI.java b/java/demo/Freeze/library/LibraryI.java
index ca09c0fb908..9035731ac7f 100644
--- a/java/demo/Freeze/library/LibraryI.java
+++ b/java/demo/Freeze/library/LibraryI.java
@@ -55,7 +55,7 @@ class LibraryI extends _LibraryDisp
//
// Add the isbn number to the authors map.
//
- String[] isbnSeq = (String[])_authors.get(description.authors);
+ String[] isbnSeq = _authors.get(description.authors);
int length = (isbnSeq == null) ? 0 : isbnSeq.length;
String[] newIsbnSeq = new String[length+1];
@@ -111,7 +111,7 @@ class LibraryI extends _LibraryDisp
// Lookup all books that match the given authors, and
// return them to the caller.
//
- String[] isbnSeq = (String[])_authors.get(authors);
+ String[] isbnSeq = _authors.get(authors);
int length = (isbnSeq == null) ? 0 : isbnSeq.length;
BookPrx[] books = new BookPrx[length];
@@ -156,7 +156,7 @@ class LibraryI extends _LibraryDisp
{
try
{
- String[] isbnSeq = (String[])_authors.get(description.authors);
+ String[] isbnSeq = _authors.get(description.authors);
assert isbnSeq != null;
diff --git a/java/demo/Freeze/library/Parser.java b/java/demo/Freeze/library/Parser.java
index 8d2c5256f70..8d11881eb71 100644
--- a/java/demo/Freeze/library/Parser.java
+++ b/java/demo/Freeze/library/Parser.java
@@ -35,21 +35,21 @@ class Parser
}
void
- addBook(java.util.List args)
+ addBook(java.util.List<String> args)
{
if(args.size() != 3)
{
error("`add' requires at exactly three arguments (type `help' for more info)");
return;
}
-
+
try
{
BookDescription desc = new BookDescription();
- desc.isbn = (String)args.get(0);
- desc.title = (String)args.get(1);
- desc.authors = (String)args.get(2);
-
+ desc.isbn = args.get(0);
+ desc.title = args.get(1);
+ desc.authors = args.get(2);
+
BookPrx book = _library.createBook(desc);
System.out.println("added new book with isbn " + desc.isbn);
}
@@ -68,20 +68,20 @@ class Parser
}
void
- findIsbn(java.util.List args)
+ findIsbn(java.util.List<String> args)
{
if(args.size() != 1)
{
error("`isbn' requires exactly one argument (type `help' for more info)");
return;
}
-
+
try
{
_foundBooks = null;
_current = 0;
- BookPrx book = _library.findByIsbn((String)args.get(0));
+ BookPrx book = _library.findByIsbn(args.get(0));
if(book == null)
{
System.out.println("no book with that ISBN number exists.");
@@ -104,17 +104,17 @@ class Parser
}
void
- findAuthors(java.util.List args)
+ findAuthors(java.util.List<String> args)
{
if(args.size() != 1)
{
error("`authors' requires exactly one argument (type `help' for more info)");
return;
}
-
+
try
{
- _foundBooks = _library.findByAuthors((String)args.get(0));
+ _foundBooks = _library.findByAuthors(args.get(0));
_current = 0;
System.out.println("number of books found: " + _foundBooks.length);
printCurrent();
@@ -138,7 +138,7 @@ class Parser
}
printCurrent();
}
-
+
void
printCurrent()
{
@@ -181,7 +181,7 @@ class Parser
}
void
- rentCurrent(java.util.List args)
+ rentCurrent(java.util.List<String> args)
{
if(args.size() != 1)
{
@@ -193,8 +193,8 @@ class Parser
{
if(_foundBooks != null && _current != _foundBooks.length)
{
- _foundBooks[_current].rentBook((String)args.get(0));
- System.out.println("the book is now rented by `" + (String)args.get(0) + "'");
+ _foundBooks[_current].rentBook(args.get(0));
+ System.out.println("the book is now rented by `" + args.get(0) + "'");
}
else
{
@@ -274,7 +274,7 @@ class Parser
}
void
- setEvictorSize(java.util.List args)
+ setEvictorSize(java.util.List<String> args)
{
if(args.size() != 1)
{
@@ -282,7 +282,7 @@ class Parser
return;
}
- String s = (String)args.get(0);
+ String s = args.get(0);
try
{
_library.setEvictorSize(Integer.parseInt(s));
diff --git a/java/demo/Freeze/library/build.xml b/java/demo/Freeze/library/build.xml
index dc8d213a27f..7e67186a72d 100644
--- a/java/demo/Freeze/library/build.xml
+++ b/java/demo/Freeze/library/build.xml
@@ -44,7 +44,7 @@
<exclude name="${generated.dir}/**"/>
<classpath>
<path refid="ice.classpath"/>
- <path refid="db.classpath"/>
+ <path refid="freeze.classpath"/>
</classpath>
<compilerarg value="${javac.lint}"/>
</javac>
diff --git a/java/demo/Freeze/phonebook/Grammar.java b/java/demo/Freeze/phonebook/Grammar.java
index 803966e4977..26ba2198ad2 100644
--- a/java/demo/Freeze/phonebook/Grammar.java
+++ b/java/demo/Freeze/phonebook/Grammar.java
@@ -53,7 +53,7 @@ class Grammar
}
else if(_token.type == Token.TOK_ADD_CONTACTS)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -62,7 +62,7 @@ class Grammar
}
else if(_token.type == Token.TOK_FIND_CONTACTS)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -91,7 +91,7 @@ class Grammar
}
else if(_token.type == Token.TOK_SET_CURRENT_NAME)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -100,7 +100,7 @@ class Grammar
}
else if(_token.type == Token.TOK_SET_CURRENT_ADDRESS)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -109,7 +109,7 @@ class Grammar
}
else if(_token.type == Token.TOK_SET_CURRENT_PHONE)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -128,7 +128,7 @@ class Grammar
}
else if(_token.type == Token.TOK_SET_EVICTOR_SIZE)
{
- java.util.List s = strings();
+ java.util.List<String> s = strings();
if(_token.type != Token.TOK_SEMI)
{
throw new ParseError("Expected ';'");
@@ -157,10 +157,10 @@ class Grammar
}
}
- private java.util.List
+ private java.util.List<String>
strings()
{
- java.util.List l = new java.util.ArrayList();
+ java.util.List<String> l = new java.util.ArrayList<String>();
while(true)
{
_token = _scanner.nextToken();
diff --git a/java/demo/Freeze/phonebook/build.xml b/java/demo/Freeze/phonebook/build.xml
index 6af5e9f1b60..88b7a9ef591 100644
--- a/java/demo/Freeze/phonebook/build.xml
+++ b/java/demo/Freeze/phonebook/build.xml
@@ -41,7 +41,7 @@
<exclude name="${generated.dir}/**"/>
<classpath>
<path refid="ice.classpath"/>
- <path refid="db.classpath"/>
+ <path refid="freeze.classpath"/>
</classpath>
<compilerarg value="${javac.lint}"/>
</javac>
diff --git a/java/demo/Freeze/transform/Create.java b/java/demo/Freeze/transform/Create.java
index 231730c52b4..d55f9301c4e 100644
--- a/java/demo/Freeze/transform/Create.java
+++ b/java/demo/Freeze/transform/Create.java
@@ -22,35 +22,32 @@ class Create extends Ice.Application
}
final String[] names = { "don", "ed", "frank", "gary", "arnold", "bob", "carlos" };
- final String[] phoneNumbers = { "(777)777-7777", "(666)666-6666", "(555)555-5555 x123",
+ final String[] phoneNumbers = { "(777)777-7777", "(666)666-6666", "(555)555-5555 x123",
"(444)444-4444", "(333)333-3333 x1234", "(222)222-2222", "(111)111-1111" };
Connection connection = Util.createConnection(communicator(), "db");
- final java.util.Comparator less =
- new java.util.Comparator()
+ final java.util.Comparator<String> less = new java.util.Comparator<String>()
{
- public int compare(Object o1, Object o2)
+ public int compare(String s1, String s2)
{
- if(o1 == o2)
+ if(s1 == s2)
{
return 0;
}
- else if(o1 == null)
+ else if(s1 == null)
{
- return -((Comparable)o2).compareTo(o1);
+ return -s2.compareTo(s1);
}
else
{
- return ((Comparable)o1).compareTo(o2);
+ return s1.compareTo(s2);
}
}
};
- java.util.Map indexComparators = new java.util.HashMap();
- indexComparators.put("phoneNumber", less);
+ Contacts.IndexComparators indexComparators = new Contacts.IndexComparators(less);
Contacts contacts = new Contacts(connection, "contacts", true, less, indexComparators);
-
//
// Create a bunch of contacts within one transaction, and commit it
@@ -73,7 +70,7 @@ class Create extends Ice.Application
}
System.out.println(names.length + " contacts were successfully created or updated");
-
+
return 0;
}
diff --git a/java/demo/Freeze/transform/Read.java b/java/demo/Freeze/transform/Read.java
index 995cf531409..efab503377d 100644
--- a/java/demo/Freeze/transform/Read.java
+++ b/java/demo/Freeze/transform/Read.java
@@ -23,54 +23,44 @@ class Read extends Ice.Application
Connection connection = Util.createConnection(communicator(), "db");
- final java.util.Comparator less =
- new java.util.Comparator()
+ final java.util.Comparator<String> less = new java.util.Comparator<String>()
{
- public int compare(Object o1, Object o2)
+ public int compare(String s1, String s2)
{
- if(o1 == o2)
+ if(s1 == s2)
{
return 0;
}
- else if(o1 == null)
+ else if(s1 == null)
{
- return -((Comparable)o2).compareTo(o1);
+ return -s2.compareTo(s1);
}
else
{
- return ((Comparable)o1).compareTo(o2);
+ return s1.compareTo(s2);
}
}
};
- java.util.Map indexComparators = new java.util.HashMap();
- indexComparators.put("phoneNumber", less);
-
try
{
+ Contacts.IndexComparators indexComparators = new Contacts.IndexComparators(less);
Contacts contacts = new Contacts(connection, "contacts", false, less, indexComparators);
-
+
System.out.println("All contacts (default order)");
- java.util.Iterator p = contacts.entrySet().iterator();
- while(p.hasNext())
+ for(java.util.Map.Entry<String, ContactData> entry : contacts.entrySet())
{
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- System.out.println((String)entry.getKey() + ":\t\t"
- + ((ContactData)entry.getValue()).phoneNumber);
+ System.out.println(entry.getKey() + ":\t\t" + entry.getValue().phoneNumber);
}
-
+
System.out.println("\nAll contacts (ordered by phone number)");
- java.util.SortedMap phoneNumberMap = contacts.mapForIndex("phoneNumber");
- p = phoneNumberMap.values().iterator();
- while(p.hasNext())
+ java.util.SortedMap<String, java.util.Set<java.util.Map.Entry<String, ContactData>>> phoneNumberMap =
+ contacts.mapForPhoneNumber();
+ for(java.util.Set<java.util.Map.Entry<String, ContactData>> entries : phoneNumberMap.values())
{
- java.util.Set entries = (java.util.Set)p.next();
- java.util.Iterator q = entries.iterator();
- while(q.hasNext())
+ for(java.util.Map.Entry<String, ContactData> entry : entries)
{
- java.util.Map.Entry entry = (java.util.Map.Entry)q.next();
- System.out.println((String)entry.getKey() + ":\t\t"
- + ((ContactData)entry.getValue()).phoneNumber);
+ System.out.println(entry.getKey() + ":\t\t" + entry.getValue().phoneNumber);
}
}
}
@@ -78,7 +68,7 @@ class Read extends Ice.Application
{
connection.close();
}
-
+
return 0;
}
diff --git a/java/demo/Freeze/transform/ReadNew.java b/java/demo/Freeze/transform/ReadNew.java
index 96ba48150a5..30add0aa939 100644
--- a/java/demo/Freeze/transform/ReadNew.java
+++ b/java/demo/Freeze/transform/ReadNew.java
@@ -23,60 +23,47 @@ class ReadNew extends Ice.Application
Connection connection = Util.createConnection(communicator(), "dbnew");
- final java.util.Comparator less =
- new java.util.Comparator()
+ final java.util.Comparator<String> less = new java.util.Comparator<String>()
{
- public int compare(Object o1, Object o2)
+ public int compare(String s1, String s2)
{
- if(o1 == o2)
+ if(s1 == s2)
{
return 0;
}
- else if(o1 == null)
+ else if(s1 == null)
{
- return -((Comparable)o2).compareTo(o1);
+ return -s2.compareTo(s1);
}
else
{
- return ((Comparable)o1).compareTo(o2);
+ return s1.compareTo(s2);
}
}
};
- java.util.Map indexComparators = new java.util.HashMap();
- indexComparators.put("phoneNumber", less);
-
try
{
+ NewContacts.IndexComparators indexComparators = new NewContacts.IndexComparators(less);
boolean createDb = true;
NewContacts contacts = new NewContacts(connection, "contacts", createDb, less, indexComparators);
-
+
System.out.println("All contacts (default order)");
- java.util.Iterator p = contacts.entrySet().iterator();
- while(p.hasNext())
+ for(java.util.Map.Entry<String, NewContactData> entry : contacts.entrySet())
{
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- NewContactData data = (NewContactData)entry.getValue();
-
- System.out.println((String)entry.getKey() + ":\t\t"
- + data.phoneNumber + " " + data.emailAddress);
+ NewContactData data = entry.getValue();
+ System.out.println(entry.getKey() + ":\t\t" + data.phoneNumber + " " + data.emailAddress);
}
-
+
System.out.println("\nAll contacts (ordered by phone number)");
- java.util.SortedMap phoneNumberMap = contacts.mapForIndex("phoneNumber");
- p = phoneNumberMap.values().iterator();
- while(p.hasNext())
+ java.util.SortedMap<String, java.util.Set<java.util.Map.Entry<String, NewContactData>>> phoneNumberMap =
+ contacts.mapForPhoneNumber();
+ for(java.util.Set<java.util.Map.Entry<String, NewContactData>> entries : phoneNumberMap.values())
{
- java.util.Set entries = (java.util.Set)p.next();
- java.util.Iterator q = entries.iterator();
- while(q.hasNext())
+ for(java.util.Map.Entry<String, NewContactData> entry : entries)
{
- java.util.Map.Entry entry = (java.util.Map.Entry)q.next();
- NewContactData data = (NewContactData)entry.getValue();
-
- System.out.println((String)entry.getKey() + ":\t\t"
- + data.phoneNumber + " " + data.emailAddress);
-
+ NewContactData data = entry.getValue();
+ System.out.println(entry.getKey() + ":\t\t" + data.phoneNumber + " " + data.emailAddress);
}
}
}
@@ -84,7 +71,7 @@ class ReadNew extends Ice.Application
{
connection.close();
}
-
+
return 0;
}
diff --git a/java/demo/Freeze/transform/Recreate.java b/java/demo/Freeze/transform/Recreate.java
index fe0bece7663..33a0298d8df 100644
--- a/java/demo/Freeze/transform/Recreate.java
+++ b/java/demo/Freeze/transform/Recreate.java
@@ -23,40 +23,37 @@ class Recreate extends Ice.Application
Connection connection = Util.createConnection(communicator(), "dbnew");
- final java.util.Comparator less =
- new java.util.Comparator()
+ final java.util.Comparator<String> less = new java.util.Comparator<String>()
{
- public int compare(Object o1, Object o2)
+ public int compare(String s1, String s2)
{
- if(o1 == o2)
+ if(s1 == s2)
{
return 0;
}
- else if(o1 == null)
+ else if(s1 == null)
{
- return -((Comparable)o2).compareTo(o1);
+ return -s2.compareTo(s1);
}
else
{
- return ((Comparable)o1).compareTo(o2);
+ return s1.compareTo(s2);
}
}
};
- java.util.Map indexComparators = new java.util.HashMap();
- indexComparators.put("phoneNumber", less);
-
try
{
+ NewContacts.IndexComparators indexComparators = new NewContacts.IndexComparators(less);
NewContacts.recreate(connection, "contacts", less, indexComparators);
}
finally
{
connection.close();
}
-
+
System.out.println("Recreated contacts database successfully!");
-
+
return 0;
}
diff --git a/java/demo/Freeze/transform/build.xml b/java/demo/Freeze/transform/build.xml
index b7a3a940420..786ed1ca1ce 100644
--- a/java/demo/Freeze/transform/build.xml
+++ b/java/demo/Freeze/transform/build.xml
@@ -43,7 +43,7 @@
<exclude name="${generated.dir}/**"/>
<classpath>
<path refid="ice.classpath"/>
- <path refid="db.classpath"/>
+ <path refid="freeze.classpath"/>
</classpath>
<compilerarg value="${javac.lint}"/>
</javac>
diff --git a/java/demo/book/freeze_filesystem/build.xml b/java/demo/book/freeze_filesystem/build.xml
index 96671a6a95c..8010bd22527 100644
--- a/java/demo/book/freeze_filesystem/build.xml
+++ b/java/demo/book/freeze_filesystem/build.xml
@@ -35,7 +35,7 @@
<exclude name="${generated.dir}/**"/>
<classpath>
<path refid="ice.classpath"/>
- <path refid="db.classpath"/>
+ <path refid="freeze.classpath"/>
</classpath>
<compilerarg value="${javac.lint}"/>
</javac>