IOCasepublic final class IOCase extends Object implements SerializableEnumeration 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 check methods in this
class to compare filenames. |
Fields Summary |
---|
public static final IOCase | SENSITIVEThe constant for case sensitive regardless of operating system. | public static final IOCase | INSENSITIVEThe constant for case insensitive regardless of operating system. | public static final IOCase | SYSTEMThe constant for case sensitivity determined by the current operating system.
Windows is case-insensitive when comparing filenames, Unix is case-sensitive.
If you derialize this constant of Windows, and deserialize on Unix, or vice
versa, then the value of the case-sensitivity flag will change. | private static final long | serialVersionUIDSerialization version. | private final String | nameThe enumeration name. | private final transient boolean | sensitiveThe sensitivity flag. |
Constructors Summary |
---|
private IOCase(String name, boolean sensitive)Private constructor.
this.name = name;
this.sensitive = sensitive;
|
Methods Summary |
---|
public int | checkCompareTo(java.lang.String str1, java.lang.String str2)Compares two strings using the case-sensitivity rule.
This method mimics {@link String#compareTo} but takes case-sensitivity
into account.
if (str1 == null || str2 == null) {
throw new NullPointerException("The strings must not be null");
}
return sensitive ? str1.compareTo(str2) : str1.compareToIgnoreCase(str2);
| public boolean | checkEndsWith(java.lang.String str, java.lang.String end)Checks if one string ends with another using the case-sensitivity rule.
This method mimics {@link String#endsWith} but takes case-sensitivity
into account.
int endLen = end.length();
return str.regionMatches(!sensitive, str.length() - endLen, end, 0, endLen);
| public boolean | checkEquals(java.lang.String str1, java.lang.String str2)Compares two strings using the case-sensitivity rule.
This method mimics {@link String#equals} but takes case-sensitivity
into account.
if (str1 == null || str2 == null) {
throw new NullPointerException("The strings must not be null");
}
return sensitive ? str1.equals(str2) : str1.equalsIgnoreCase(str2);
| public boolean | checkRegionMatches(java.lang.String str, int strStartIndex, java.lang.String search)Checks if one string contains another at a specific index using the case-sensitivity rule.
This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)}
but takes case-sensitivity into account.
return str.regionMatches(!sensitive, strStartIndex, search, 0, search.length());
| public boolean | checkStartsWith(java.lang.String str, java.lang.String start)Checks if one string starts with another using the case-sensitivity rule.
This method mimics {@link String#startsWith(String)} but takes case-sensitivity
into account.
return str.regionMatches(!sensitive, 0, start, 0, start.length());
| java.lang.String | convertCase(java.lang.String str)Converts the case of the input String to a standard format.
Subsequent operations can then use standard String methods.
if (str == null) {
return null;
}
return sensitive ? str : str.toLowerCase();
| public static org.apache.commons.io.IOCase | forName(java.lang.String name)Factory method to create an IOCase from a name.
//-----------------------------------------------------------------------
if (IOCase.SENSITIVE.name.equals(name)){
return IOCase.SENSITIVE;
}
if (IOCase.INSENSITIVE.name.equals(name)){
return IOCase.INSENSITIVE;
}
if (IOCase.SYSTEM.name.equals(name)){
return IOCase.SYSTEM;
}
throw new IllegalArgumentException("Invalid IOCase name: " + name);
| public java.lang.String | getName()Gets the name of the constant.
return name;
| public boolean | isCaseSensitive()Does the object represent case sensitive comparison.
return sensitive;
| private java.lang.Object | readResolve()Replaces the enumeration from the stream with a real one.
This ensures that the correct flag is set for SYSTEM.
return forName(name);
| public java.lang.String | toString()Gets a string describing the sensitivity.
return name;
|
|