Class IOCase
- java.lang.Object
-
- org.uberfire.apache.commons.io.IOCase
-
- All Implemented Interfaces:
Serializable
public final class IOCase extends Object implements Serializable
Enumeration of IO case sensitivity.Different filing systems have different rules for case-sensitivity. Windows is case-insensitive, Unix is case-sensitive.
This class captures that difference, providing an enumeration to control how filename comparisons should be performed. It also provides methods that use the enumeration to perform comparisons.
Wherever possible, you should use the
checkmethods in this class to compare filenames.- Since:
- 1.3
- Version:
- $Id$
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static IOCaseINSENSITIVEThe constant for case insensitive regardless of operating system.static IOCaseSENSITIVEThe constant for case sensitive regardless of operating system.static IOCaseSYSTEMThe constant for case sensitivity determined by the current operating system.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcheckCompareTo(String str1, String str2)Compares two strings using the case-sensitivity rule.booleancheckEndsWith(String str, String end)Checks if one string ends with another using the case-sensitivity rule.booleancheckEquals(String str1, String str2)Compares two strings using the case-sensitivity rule.intcheckIndexOf(String str, int strStartIndex, String search)Checks if one string contains another starting at a specific index using the case-sensitivity rule.booleancheckRegionMatches(String str, int strStartIndex, String search)Checks if one string contains another at a specific index using the case-sensitivity rule.booleancheckStartsWith(String str, String start)Checks if one string starts with another using the case-sensitivity rule.static IOCaseforName(String name)Factory method to create an IOCase from a name.StringgetName()Gets the name of the constant.booleanisCaseSensitive()Does the object represent case sensitive comparison.StringtoString()Gets a string describing the sensitivity.
-
-
-
Field Detail
-
SENSITIVE
public static final IOCase SENSITIVE
The constant for case sensitive regardless of operating system.
-
INSENSITIVE
public static final IOCase INSENSITIVE
The constant for case insensitive regardless of operating system.
-
SYSTEM
public static final IOCase SYSTEM
The constant for case sensitivity determined by the current operating system. Windows is case-insensitive when comparing filenames, Unix is case-sensitive.Note: This only caters for Windows and Unix. Other operating systems (e.g. OSX and OpenVMS) are treated as case sensitive if they use the Unix file separator and case-insensitive if they use the Windows file separator (see
File.separatorChar).If you derialize this constant of Windows, and deserialize on Unix, or vice versa, then the value of the case-sensitivity flag will change.
-
-
Method Detail
-
forName
public static IOCase forName(String name)
Factory method to create an IOCase from a name.- Parameters:
name- the name to find- Returns:
- the IOCase object
- Throws:
IllegalArgumentException- if the name is invalid
-
getName
public String getName()
Gets the name of the constant.- Returns:
- the name of the constant
-
isCaseSensitive
public boolean isCaseSensitive()
Does the object represent case sensitive comparison.- Returns:
- true if case sensitive
-
checkCompareTo
public int checkCompareTo(String str1, String str2)
Compares two strings using the case-sensitivity rule.This method mimics
String.compareTo(java.lang.String)but takes case-sensitivity into account.- Parameters:
str1- the first string to compare, not nullstr2- the second string to compare, not null- Returns:
- true if equal using the case rules
- Throws:
NullPointerException- if either string is null
-
checkEquals
public boolean checkEquals(String str1, String str2)
Compares two strings using the case-sensitivity rule.This method mimics
String.equals(java.lang.Object)but takes case-sensitivity into account.- Parameters:
str1- the first string to compare, not nullstr2- the second string to compare, not null- Returns:
- true if equal using the case rules
- Throws:
NullPointerException- if either string is null
-
checkStartsWith
public boolean checkStartsWith(String str, String start)
Checks if one string starts with another using the case-sensitivity rule.This method mimics
String.startsWith(String)but takes case-sensitivity into account.- Parameters:
str- the string to check, not nullstart- the start to compare against, not null- Returns:
- true if equal using the case rules
- Throws:
NullPointerException- if either string is null
-
checkEndsWith
public boolean checkEndsWith(String str, String end)
Checks if one string ends with another using the case-sensitivity rule.This method mimics
String.endsWith(java.lang.String)but takes case-sensitivity into account.- Parameters:
str- the string to check, not nullend- the end to compare against, not null- Returns:
- true if equal using the case rules
- Throws:
NullPointerException- if either string is null
-
checkIndexOf
public int checkIndexOf(String str, int strStartIndex, String search)
Checks if one string contains another starting at a specific index using the case-sensitivity rule.This method mimics parts of
String.indexOf(String, int)but takes case-sensitivity into account.- Parameters:
str- the string to check, not nullstrStartIndex- the index to start at in strsearch- the start to search for, not null- Returns:
- the first index of the search String,
-1 if no match or
nullstring input - Throws:
NullPointerException- if either string is null- Since:
- 2.0
-
checkRegionMatches
public boolean checkRegionMatches(String str, int strStartIndex, String search)
Checks if one string contains another at a specific index using the case-sensitivity rule.This method mimics parts of
String.regionMatches(boolean, int, String, int, int)but takes case-sensitivity into account.- Parameters:
str- the string to check, not nullstrStartIndex- the index to start at in strsearch- the start to search for, not null- Returns:
- true if equal using the case rules
- Throws:
NullPointerException- if either string is null
-
-