Source Code Cross Referenced for IOCase.java in  » Library » apache-common-IO » org » apache » commons » io » 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 » Library » apache common IO » org.apache.commons.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.io;
018:
019:        import java.io.Serializable;
020:
021:        /**
022:         * Enumeration of IO case sensitivity.
023:         * <p>
024:         * Different filing systems have different rules for case-sensitivity.
025:         * Windows is case-insensitive, Unix is case-sensitive.
026:         * <p>
027:         * This class captures that difference, providing an enumeration to
028:         * control how filename comparisons should be performed. It also provides
029:         * methods that use the enumeration to perform comparisons.
030:         * <p>
031:         * Wherever possible, you should use the <code>check</code> methods in this
032:         * class to compare filenames.
033:         *
034:         * @author Stephen Colebourne
035:         * @version $Id: IOCase.java 484844 2006-12-08 23:27:18Z ggregory $
036:         * @since Commons IO 1.3
037:         */
038:        public final class IOCase implements  Serializable {
039:
040:            /**
041:             * The constant for case sensitive regardless of operating system.
042:             */
043:            public static final IOCase SENSITIVE = new IOCase("Sensitive", true);
044:            /**
045:             * The constant for case insensitive regardless of operating system.
046:             */
047:            public static final IOCase INSENSITIVE = new IOCase("Insensitive",
048:                    false);
049:            /**
050:             * The constant for case sensitivity determined by the current operating system.
051:             * Windows is case-insensitive when comparing filenames, Unix is case-sensitive.
052:             * <p>
053:             * If you derialize this constant of Windows, and deserialize on Unix, or vice
054:             * versa, then the value of the case-sensitivity flag will change.
055:             */
056:            public static final IOCase SYSTEM = new IOCase("System",
057:                    !FilenameUtils.isSystemWindows());
058:
059:            /** Serialization version. */
060:            private static final long serialVersionUID = -6343169151696340687L;
061:
062:            /** The enumeration name. */
063:            private final String name;
064:            /** The sensitivity flag. */
065:            private final transient boolean sensitive;
066:
067:            //-----------------------------------------------------------------------
068:            /**
069:             * Factory method to create an IOCase from a name.
070:             * 
071:             * @param name  the name to find
072:             * @return the IOCase object
073:             * @throws IllegalArgumentException if the name is invalid
074:             */
075:            public static IOCase forName(String name) {
076:                if (IOCase.SENSITIVE.name.equals(name)) {
077:                    return IOCase.SENSITIVE;
078:                }
079:                if (IOCase.INSENSITIVE.name.equals(name)) {
080:                    return IOCase.INSENSITIVE;
081:                }
082:                if (IOCase.SYSTEM.name.equals(name)) {
083:                    return IOCase.SYSTEM;
084:                }
085:                throw new IllegalArgumentException("Invalid IOCase name: "
086:                        + name);
087:            }
088:
089:            //-----------------------------------------------------------------------
090:            /**
091:             * Private constructor.
092:             * 
093:             * @param name  the name
094:             * @param sensitive  the sensitivity
095:             */
096:            private IOCase(String name, boolean sensitive) {
097:                this .name = name;
098:                this .sensitive = sensitive;
099:            }
100:
101:            /**
102:             * Replaces the enumeration from the stream with a real one.
103:             * This ensures that the correct flag is set for SYSTEM.
104:             * 
105:             * @return the resolved object
106:             */
107:            private Object readResolve() {
108:                return forName(name);
109:            }
110:
111:            //-----------------------------------------------------------------------
112:            /**
113:             * Gets the name of the constant.
114:             * 
115:             * @return the name of the constant
116:             */
117:            public String getName() {
118:                return name;
119:            }
120:
121:            /**
122:             * Does the object represent case sensitive comparison.
123:             * 
124:             * @return true if case sensitive
125:             */
126:            public boolean isCaseSensitive() {
127:                return sensitive;
128:            }
129:
130:            //-----------------------------------------------------------------------
131:            /**
132:             * Compares two strings using the case-sensitivity rule.
133:             * <p>
134:             * This method mimics {@link String#equals} but takes case-sensitivity
135:             * into account.
136:             * 
137:             * @param str1  the first string to compare, not null
138:             * @param str2  the second string to compare, not null
139:             * @return true if equal using the case rules
140:             * @throws NullPointerException if either string is null
141:             */
142:            public boolean checkEquals(String str1, String str2) {
143:                if (str1 == null || str2 == null) {
144:                    throw new NullPointerException(
145:                            "The strings must not be null");
146:                }
147:                return sensitive ? str1.equals(str2) : str1
148:                        .equalsIgnoreCase(str2);
149:            }
150:
151:            /**
152:             * Checks if one string starts with another using the case-sensitivity rule.
153:             * <p>
154:             * This method mimics {@link String#startsWith(String)} but takes case-sensitivity
155:             * into account.
156:             * 
157:             * @param str  the string to check, not null
158:             * @param start  the start to compare against, not null
159:             * @return true if equal using the case rules
160:             * @throws NullPointerException if either string is null
161:             */
162:            public boolean checkStartsWith(String str, String start) {
163:                return str.regionMatches(!sensitive, 0, start, 0, start
164:                        .length());
165:            }
166:
167:            /**
168:             * Checks if one string ends with another using the case-sensitivity rule.
169:             * <p>
170:             * This method mimics {@link String#endsWith} but takes case-sensitivity
171:             * into account.
172:             * 
173:             * @param str  the string to check, not null
174:             * @param end  the end to compare against, not null
175:             * @return true if equal using the case rules
176:             * @throws NullPointerException if either string is null
177:             */
178:            public boolean checkEndsWith(String str, String end) {
179:                int endLen = end.length();
180:                return str.regionMatches(!sensitive, str.length() - endLen,
181:                        end, 0, endLen);
182:            }
183:
184:            /**
185:             * Checks if one string contains another at a specific index using the case-sensitivity rule.
186:             * <p>
187:             * This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)} 
188:             * but takes case-sensitivity into account.
189:             * 
190:             * @param str  the string to check, not null
191:             * @param strStartIndex  the index to start at in str
192:             * @param search  the start to search for, not null
193:             * @return true if equal using the case rules
194:             * @throws NullPointerException if either string is null
195:             */
196:            public boolean checkRegionMatches(String str, int strStartIndex,
197:                    String search) {
198:                return str.regionMatches(!sensitive, strStartIndex, search, 0,
199:                        search.length());
200:            }
201:
202:            /**
203:             * Converts the case of the input String to a standard format.
204:             * Subsequent operations can then use standard String methods.
205:             * 
206:             * @param str  the string to convert, null returns null
207:             * @return the lower-case version if case-insensitive
208:             */
209:            String convertCase(String str) {
210:                if (str == null) {
211:                    return null;
212:                }
213:                return sensitive ? str : str.toLowerCase();
214:            }
215:
216:            //-----------------------------------------------------------------------
217:            /**
218:             * Gets a string describing the sensitivity.
219:             * 
220:             * @return a string describing the sensitivity
221:             */
222:            public String toString() {
223:                return name;
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.