Source Code Cross Referenced for TypeComparator.java in  » Database-DBMS » db4o-6.4 » EDU » purdue » cs » bloat » editor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db4o 6.4 » EDU.purdue.cs.bloat.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package EDU.purdue.cs.bloat.editor;
022:
023:        import java.util.*;
024:
025:        import EDU.purdue.cs.bloat.util.*;
026:
027:        // // For testing only
028:        // import EDU.purdue.cs.bloat.file.*;
029:        // import EDU.purdue.cs.bloat.context.*;
030:
031:        /**
032:         * A <tt>TypeComparator</tt> orders <tt>Type</tt>s such that a subclass
033:         * preceededs its superclass. Note that this doesn't really work with
034:         * interfaces.
035:         */
036:        public final class TypeComparator implements  Comparator {
037:
038:            public static boolean DEBUG = false;
039:
040:            private EditorContext context;
041:
042:            private static void db(final String s) {
043:                if (TypeComparator.DEBUG) {
044:                    System.out.println(s);
045:                }
046:            }
047:
048:            /**
049:             * Constructor.
050:             */
051:            public TypeComparator(final EditorContext context) {
052:                this .context = context;
053:            }
054:
055:            /**
056:             * Returns a negative value if o1 < o2 (t1 is a subclass of t2). Otherwise,
057:             * it returns a positive value.
058:             */
059:            public int compare(final Object o1, final Object o2) {
060:                Assert.isTrue(o1 instanceof  Type, o1 + " is not a Type");
061:                Assert.isTrue(o2 instanceof  Type, o2 + " is not a Type");
062:
063:                final Type t1 = (Type) o1;
064:                final Type t2 = (Type) o2;
065:
066:                TypeComparator.db("Comparing " + t1 + " to " + t2);
067:
068:                final ClassHierarchy hier = context.getHierarchy();
069:
070:                if (hier.subclassOf(t1, t2)) {
071:                    TypeComparator.db("  " + t1 + " is a subclass of " + t2);
072:                    return (-1);
073:
074:                } else if (hier.subclassOf(t2, t1)) {
075:                    TypeComparator.db("  " + t2 + " is a subclass of " + t1);
076:                    return (1);
077:
078:                } else {
079:                    TypeComparator.db("  " + t1 + " and " + t2
080:                            + " are unrelated");
081:
082:                    // Don't return 0. If you do, the type will not get included in
083:                    // the sorted set. Weird.
084:                    return (1);
085:                }
086:            }
087:
088:            /**
089:             * Indicates whether some other object is "equal to" this Comparator.
090:             */
091:            public boolean equals(final Object other) {
092:                return (other instanceof  TypeComparator);
093:            }
094:
095:            // /**
096:            // * Test program. Reads class names from the command line.
097:            // */
098:            // public static void main(String[] args) {
099:            // // Make a list of class names
100:            // List names = new ArrayList();
101:            // for(int i = 0; i < args.length; i++) {
102:            // names.add(args[i]);
103:            // }
104:
105:            // // Do some BLOAT magic
106:            // EditorContext context =
107:            // new CachingBloatContext(new ClassFileLoader(), names, false);
108:            // Collection classes = context.getHierarchy().classes();
109:
110:            // TypeComparator.DEBUG = true;
111:            // SortedSet sorted = new TreeSet(new TypeComparator(context));
112:            // sorted.addAll(classes);
113:
114:            // System.out.println(classes.size() + " classes");
115:            // System.out.println(sorted.size() + " sorted types:");
116:            // Object[] array = sorted.toArray();
117:            // for(int i = 0; i < array.length; i++) {
118:            // System.out.println(" " + array[i]);
119:            // }
120:            // }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.