Source Code Cross Referenced for Range.java in  » Testing » mocquer » org » jingle » mocquer » 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 » Testing » mocquer » org.jingle.mocquer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jingle.mocquer;
002:
003:        /**
004:         * This class defines the limitation method call occurrence
005:         *
006:         * @author JianLu
007:         * @version 1.0 2004-10-28
008:         * @since 1.0
009:         */
010:        public class Range {
011:            /**
012:             * 
013:             * Range limitation
014:             *
015:             * @author JianLu
016:             * @version 1.0 2004-11-11
017:             * @since 1.0
018:             */
019:            static class RangeLimit {
020:                RangeLimit() {
021:                }
022:            };
023:
024:            /**
025:             *  Special range limitation -- no limit
026:             */
027:            public static final RangeLimit NO_LIMIT = new RangeLimit();
028:
029:            /**
030:             * Occurrence happens only once
031:             */
032:            public static final Range ONE = new Range(1);
033:
034:            /**
035:             * Occurrence happens one or more times
036:             */
037:            public static final Range ONE_OR_MORE = new Range(1, NO_LIMIT);
038:
039:            /**
040:             * Occurrence happens zero or more times
041:             */
042:            public static final Range ZERO_OR_MORE = new Range(0, NO_LIMIT);
043:
044:            /**
045:             * The min value of the range
046:             */
047:            int min;
048:
049:            /**
050:             * The max value of the range
051:             */
052:            int max;
053:
054:            /**
055:             * Constructor
056:             * @param min The min value of the range
057:             * @param max The RangeLimit stands for the max value of the range
058:             */
059:            public Range(int min, RangeLimit max) {
060:                verify(min, max);
061:                this .min = min;
062:                this .max = -1;
063:            }
064:
065:            /**
066:             * Constructor
067:             * @param num The min and max value of the range
068:             */
069:            public Range(int num) {
070:                this (num, num);
071:            }
072:
073:            /**
074:             * Constructor
075:             * @param min The min value of the range
076:             * @param max The max value of the range
077:             */
078:            public Range(int min, int max) {
079:                verify(min, max);
080:                this .min = min;
081:                this .max = max;
082:            }
083:
084:            /**
085:             * Verify the min value and max value
086:             * @param min The min value of the range
087:             * @param max The max value of the range
088:             */
089:            protected void verify(int min, int max) {
090:                if (min < 0)
091:                    throw new AssertionFailedError("min times should >= 0");
092:                if (max < 1)
093:                    throw new AssertionFailedError("max times should >= 1");
094:                if (max < min)
095:                    throw new AssertionFailedError(
096:                            "max times should >= min times");
097:            }
098:
099:            /**
100:             * Verify the min value and max value
101:             * @param min The min value of the range
102:             * @param max The RangeLimt stands for the max value of the range
103:             */
104:            protected void verify(int min, RangeLimit max) {
105:                if (max != NO_LIMIT)
106:                    throw new AssertionFailedError(
107:                            "Invalid argument. RangeLimit needed");
108:                if (min < 0)
109:                    throw new AssertionFailedError("min times should >= 0");
110:            }
111:
112:            /**
113:             * Is the given number same as the max value of the range
114:             * @param num The given number
115:             * @return true or false
116:             */
117:            public boolean isMax(int num) {
118:                if (max == -1)
119:                    return false;
120:                return (num == max);
121:            }
122:
123:            /**
124:             * Is the given number same as the min value of the range
125:             * @param num The given number
126:             * @return true or false
127:             */
128:            public boolean isMin(int num) {
129:                return (num == min);
130:            }
131:
132:            /**
133:             * Is the given number greater than the max value of the range
134:             * @param num The given number
135:             * @return true or false
136:             */
137:            public boolean greaterThanMax(int num) {
138:                if (max == -1)
139:                    return false;
140:                return num > max;
141:            }
142:
143:            /**
144:             * Is the given number lsee than the min value of the range
145:             * @param num The given number
146:             * @return true or false
147:             */
148:            public boolean lessThanMin(int num) {
149:                return num < min;
150:            }
151:
152:            /**
153:             * Is the given number in the range
154:             * @param num The given number
155:             * @return true or false
156:             */
157:            public boolean inRange(int num) {
158:                if (max == -1)
159:                    return num >= min;
160:                return ((num >= min) && (num <= max));
161:            }
162:
163:            /**
164:             * Is the range has no upper limitation
165:             * @return true or false
166:             */
167:            public boolean isNoLimit() {
168:                return (max == -1);
169:            }
170:
171:            /** 
172:             * (non-Javadoc)
173:             * @see java.lang.Object#toString()
174:             */
175:            public String toString() {
176:                StringBuffer sb = new StringBuffer();
177:                sb.append("[").append(min).append(",");
178:                if (max != -1)
179:                    sb.append(max);
180:                else
181:                    sb.append("*");
182:                sb.append("]");
183:                return sb.toString();
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.