Source Code Cross Referenced for EnumeratedProperty.java in  » Code-Analyzer » pmd-4.2rc1 » net » sourceforge » pmd » properties » 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 » Code Analyzer » pmd 4.2rc1 » net.sourceforge.pmd.properties 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.pmd.properties;
002:
003:        import java.util.Map;
004:
005:        import net.sourceforge.pmd.util.CollectionUtil;
006:        import net.sourceforge.pmd.util.StringUtil;
007:
008:        /**
009:         * Defines a datatype with a set of preset values of any type as held within a pair of
010:         * maps. While the values are not serialized out, the labels are and serve as keys to
011:         * obtain the values.
012:         * 
013:         * @author Brian Remedios
014:         * @version $Revision$
015:         */
016:        public class EnumeratedProperty<E> extends AbstractPMDProperty {
017:
018:            private Map<String, E> choicesByLabel;
019:            private Map<E, String> labelsByChoice;
020:
021:            /**
022:             * Constructor for EnumeratedProperty.
023:             * @param theName String
024:             * @param theDescription String
025:             * @param theLabels String[]
026:             * @param theChoices E[]
027:             * @param theUIOrder float
028:             */
029:            public EnumeratedProperty(String theName, String theDescription,
030:                    String[] theLabels, E[] theChoices, float theUIOrder) {
031:                this (theName, theDescription, theLabels, theChoices,
032:                        theUIOrder, 1);
033:            }
034:
035:            /**
036:             * Constructor for EnumeratedProperty.
037:             * @param theName String
038:             * @param theDescription String
039:             * @param theLabels String[]
040:             * @param theChoices E[]
041:             * @param theUIOrder float
042:             * @param maxValues int
043:             */
044:            public EnumeratedProperty(String theName, String theDescription,
045:                    String[] theLabels, E[] theChoices, float theUIOrder,
046:                    int maxValues) {
047:                super (theName, theDescription, theChoices[0], theUIOrder);
048:
049:                choicesByLabel = CollectionUtil.mapFrom(theLabels, theChoices);
050:                labelsByChoice = CollectionUtil.invertedMapFrom(choicesByLabel);
051:
052:                maxValueCount(maxValues);
053:            }
054:
055:            /**
056:             * Method type.
057:             * @return Class
058:             * @see net.sourceforge.pmd.PropertyDescriptor#type()
059:             */
060:            public Class<Object> type() {
061:                return Object.class;
062:            }
063:
064:            private String nonLegalValueMsgFor(Object value) {
065:                return "" + value + " is not a legal value";
066:            }
067:
068:            /**
069:             * Method errorFor.
070:             * @param value Object
071:             * @return String
072:             * @see net.sourceforge.pmd.PropertyDescriptor#errorFor(Object)
073:             */
074:            public String errorFor(Object value) {
075:
076:                if (maxValueCount() == 1) {
077:                    return labelsByChoice.containsKey(value) ? null
078:                            : nonLegalValueMsgFor(value);
079:                }
080:
081:                Object[] values = (Object[]) value;
082:                for (int i = 0; i < values.length; i++) {
083:                    if (labelsByChoice.containsKey(values[i]))
084:                        continue;
085:                    return nonLegalValueMsgFor(values[i]);
086:                }
087:                return null;
088:            }
089:
090:            /**
091:             * Method choiceFrom.
092:             * @param label String
093:             * @return E
094:             */
095:            private E choiceFrom(String label) {
096:                E result = choicesByLabel.get(label);
097:                if (result != null)
098:                    return result;
099:                throw new IllegalArgumentException(label);
100:            }
101:
102:            /**
103:             * Method valueFrom.
104:             * @param value String
105:             * @return Object
106:             * @throws IllegalArgumentException
107:             * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
108:             */
109:            public Object valueFrom(String value)
110:                    throws IllegalArgumentException {
111:
112:                if (maxValueCount() == 1)
113:                    return choiceFrom(value);
114:
115:                String[] strValues = StringUtil.substringsOf(value,
116:                        multiValueDelimiter);
117:
118:                Object[] values = new Object[strValues.length];
119:                for (int i = 0; i < values.length; i++)
120:                    values[i] = choiceFrom(strValues[i]);
121:                return values;
122:            }
123:
124:            /**
125:             * Method asDelimitedString.
126:             * @param value Object
127:             * @return String
128:             * @see net.sourceforge.pmd.PropertyDescriptor#asDelimitedString(Object)
129:             */
130:            public String asDelimitedString(Object value) {
131:
132:                if (maxValueCount() == 1)
133:                    return labelsByChoice.get(value);
134:
135:                Object[] choices = (Object[]) value;
136:
137:                StringBuffer sb = new StringBuffer();
138:
139:                sb.append(labelsByChoice.get(choices[0]));
140:
141:                for (int i = 1; i < choices.length; i++) {
142:                    sb.append(multiValueDelimiter);
143:                    sb.append(labelsByChoice.get(choices[i]));
144:                }
145:
146:                return sb.toString();
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.