~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to java/demo/Freeze/transform/Read.java

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
23
23
 
24
24
        Connection connection = Util.createConnection(communicator(), "db");
25
25
 
26
 
        final java.util.Comparator less =
27
 
        new java.util.Comparator()
 
26
        final java.util.Comparator<String> less = new java.util.Comparator<String>()
28
27
        {
29
 
            public int compare(Object o1, Object o2)
 
28
            public int compare(String s1, String s2)
30
29
            {
31
 
                if(o1 == o2)
 
30
                if(s1 == s2)
32
31
                {
33
32
                    return 0;
34
33
                }
35
 
                else if(o1 == null)
 
34
                else if(s1 == null)
36
35
                {
37
 
                    return -((Comparable)o2).compareTo(o1);
 
36
                    return -s2.compareTo(s1);
38
37
                }
39
38
                else
40
39
                {
41
 
                    return ((Comparable)o1).compareTo(o2);
 
40
                    return s1.compareTo(s2);
42
41
                }
43
42
            }
44
43
        };
45
44
 
46
 
        java.util.Map indexComparators = new java.util.HashMap();
47
 
        indexComparators.put("phoneNumber", less);
48
 
 
49
45
        try
50
46
        {
 
47
            Contacts.IndexComparators indexComparators = new Contacts.IndexComparators(less);
51
48
            Contacts contacts = new Contacts(connection, "contacts", false, less, indexComparators);
52
 
            
 
49
 
53
50
            System.out.println("All contacts (default order)");
54
 
            java.util.Iterator p = contacts.entrySet().iterator();
55
 
            while(p.hasNext())
 
51
            for(java.util.Map.Entry<String, ContactData> entry : contacts.entrySet())
56
52
            {
57
 
                java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
58
 
                System.out.println((String)entry.getKey() + ":\t\t"
59
 
                                   + ((ContactData)entry.getValue()).phoneNumber);
 
53
                System.out.println(entry.getKey() + ":\t\t" + entry.getValue().phoneNumber);
60
54
            }
61
 
            
 
55
 
62
56
            System.out.println("\nAll contacts (ordered by phone number)");
63
 
            java.util.SortedMap phoneNumberMap = contacts.mapForIndex("phoneNumber");
64
 
            p = phoneNumberMap.values().iterator();
65
 
            while(p.hasNext())
 
57
            java.util.SortedMap<String, java.util.Set<java.util.Map.Entry<String, ContactData>>> phoneNumberMap =
 
58
                contacts.mapForPhoneNumber();
 
59
            for(java.util.Set<java.util.Map.Entry<String, ContactData>> entries : phoneNumberMap.values())
66
60
            {
67
 
                java.util.Set entries = (java.util.Set)p.next();
68
 
                java.util.Iterator q = entries.iterator();
69
 
                while(q.hasNext())
 
61
                for(java.util.Map.Entry<String, ContactData> entry : entries)
70
62
                {
71
 
                    java.util.Map.Entry entry = (java.util.Map.Entry)q.next();
72
 
                    System.out.println((String)entry.getKey() + ":\t\t"
73
 
                                       + ((ContactData)entry.getValue()).phoneNumber);
 
63
                    System.out.println(entry.getKey() + ":\t\t" + entry.getValue().phoneNumber);
74
64
                }
75
65
            }
76
66
        }
78
68
        {
79
69
            connection.close();
80
70
        }
81
 
    
 
71
 
82
72
        return 0;
83
73
    }
84
74
 
86
76
    main(String[] args)
87
77
    {
88
78
        Read app = new Read();
89
 
        app.main("demo.Freeze.transform.Read", args);
 
79
        int status = app.main("demo.Freeze.transform.Read", args);
 
80
        System.exit(status);
90
81
    }
91
82
}