Source Code Cross Referenced for MenuItemComparator.java in  » Groupware » ivatagroupware » com » ivata » groupware » navigation » menu » item » 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 » Groupware » ivatagroupware » com.ivata.groupware.navigation.menu.item 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata groupware may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: MenuItemComparator.java,v $
031:         * Revision 1.4  2005/10/03 10:21:15  colinmacleod
032:         * Fixed some style and javadoc issues.
033:         *
034:         * Revision 1.3  2005/10/02 14:08:58  colinmacleod
035:         * Added/improved log4j logging.
036:         *
037:         * Revision 1.2  2005/04/09 17:19:58  colinmacleod
038:         * Changed copyright text to GPL v2 explicitly.
039:         *
040:         * Revision 1.1.1.1  2005/03/10 17:51:32  colinmacleod
041:         * Restructured ivata op around Hibernate/PicoContainer.
042:         * Renamed ivata groupware.
043:         *
044:         * -----------------------------------------------------------------------------
045:         */
046:        package com.ivata.groupware.navigation.menu.item;
047:
048:        import org.apache.log4j.Logger;
049:
050:        import java.util.Comparator;
051:
052:        /**
053:         * Sorts menu items by their <code>priority</code> properties.
054:         *
055:         * @since ivata groupware 0.10 (Feb 14, 2005)
056:         * @author Colin MacLeod
057:         * <a href="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
058:         * @version $Revision: 1.4 $
059:         */
060:
061:        public class MenuItemComparator implements  Comparator {
062:            /**
063:             * Logger for this class.
064:             */
065:            private static final Logger logger = Logger
066:                    .getLogger(MenuItemComparator.class);
067:
068:            /**
069:             * Sorts menu items by their <code>priority</code> properties.
070:             * <copyDoc>Refer to {@link Comparator}.</copyDoc>
071:             *
072:             * @param item0Object first menu item to compare.
073:             * @param item1Object first menu item to compare.
074:             * @return <copyDoc>Refer to {@link Comparator}.</copyDoc>
075:             * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
076:             */
077:            public int compare(Object item0Object, Object item1Object) {
078:                if (logger.isDebugEnabled()) {
079:                    logger.debug("compare(Object item0Object = " + item0Object
080:                            + ", Object item1Object = " + item1Object
081:                            + ") - start");
082:                }
083:
084:                MenuItemDO menuItem0 = (MenuItemDO) item0Object;
085:                MenuItemDO menuItem1 = (MenuItemDO) item1Object;
086:
087:                // first rule out whichever is null (if one is or both are)
088:                Integer compareNull = compareNull(menuItem0, menuItem1);
089:                if (compareNull != null) {
090:                    int returnint = compareNull.intValue();
091:                    if (logger.isDebugEnabled()) {
092:                        logger
093:                                .debug("compare(Object, Object) - end - return value = "
094:                                        + returnint);
095:                    }
096:                    return returnint;
097:                }
098:
099:                // try to use priority - if they are the same, compare id values
100:                compareNull = compareNull(menuItem0.getPriority(), menuItem1
101:                        .getPriority());
102:                if (compareNull != null) {
103:                    int returnint = compareNull.intValue();
104:                    if (logger.isDebugEnabled()) {
105:                        logger
106:                                .debug("compare(Object, Object) - end - return value = "
107:                                        + returnint);
108:                    }
109:                    return returnint;
110:                }
111:                int returnValue = menuItem0.getPriority().compareTo(
112:                        menuItem1.getPriority());
113:                if (returnValue == 0) {
114:                    compareNull = compareNull(menuItem0.getId(), menuItem1
115:                            .getId());
116:                    if (compareNull != null) {
117:                        int returnint = compareNull.intValue();
118:                        if (logger.isDebugEnabled()) {
119:                            logger
120:                                    .debug("compare(Object, Object) - end - return value = "
121:                                            + returnint);
122:                        }
123:                        return returnint;
124:                    }
125:                    int returnint = menuItem0.getId().compareTo(
126:                            menuItem1.getId());
127:                    if (logger.isDebugEnabled()) {
128:                        logger
129:                                .debug("compare(Object, Object) - end - return value = "
130:                                        + returnint);
131:                    }
132:                    return returnint;
133:                }
134:
135:                if (logger.isDebugEnabled()) {
136:                    logger
137:                            .debug("compare(Object, Object) - end - return value = "
138:                                    + returnValue);
139:                }
140:                return returnValue;
141:            }
142:
143:            /**
144:             * Private helper. Compare two objects to see if either is null and return
145:             * as appropriate, otherwise return <code>null</code>.
146:             *
147:             * @param object0 first object to compare.
148:             * @param object1 second object to compare.
149:             * @return <code>0</code> if both are <code>null</code>, <code>1</code> if
150:             * only <code>object0</code> is <code>null</code>,   <code>-1</code> if only
151:             * <code>object1</code> is <code>null</code>, otherwise <code>null</code>.
152:             */
153:            private Integer compareNull(final Object object0,
154:                    final Object object1) {
155:                if (logger.isDebugEnabled()) {
156:                    logger.debug("compareNull(Object object0 = " + object0
157:                            + ", Object object1 = " + object1 + ") - start");
158:                }
159:
160:                if (object0 == null) {
161:                    if ((object1 == null)) {
162:                        Integer returnInteger = new Integer(0);
163:                        if (logger.isDebugEnabled()) {
164:                            logger
165:                                    .debug("compareNull(Object, Object) - end - return value = "
166:                                            + returnInteger);
167:                        }
168:                        return returnInteger;
169:                    }
170:                    Integer returnInteger = new Integer(1);
171:                    if (logger.isDebugEnabled()) {
172:                        logger
173:                                .debug("compareNull(Object, Object) - end - return value = "
174:                                        + returnInteger);
175:                    }
176:                    return returnInteger;
177:                } else if (object1 == null) {
178:                    if ((object0 == null)) {
179:                        Integer returnInteger = new Integer(0);
180:                        if (logger.isDebugEnabled()) {
181:                            logger
182:                                    .debug("compareNull(Object, Object) - end - return value = "
183:                                            + returnInteger);
184:                        }
185:                        return returnInteger;
186:                    }
187:                    Integer returnInteger = new Integer(-1);
188:                    if (logger.isDebugEnabled()) {
189:                        logger
190:                                .debug("compareNull(Object, Object) - end - return value = "
191:                                        + returnInteger);
192:                    }
193:                    return returnInteger;
194:                }
195:
196:                if (logger.isDebugEnabled()) {
197:                    logger
198:                            .debug("compareNull(Object, Object) - end - return value = "
199:                                    + null);
200:                }
201:                return null;
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.