org.apache.commons.io
Class IOCase
java.lang.Object
org.apache.commons.io.IOCase
- Serializable
public final class IOCase
extends java.lang.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
check
methods in this
class to compare filenames.
$Id: IOCase.java 606345 2007-12-21 23:43:01Z ggregory $static IOCase | INSENSITIVE - The constant for case insensitive regardless of operating system.
|
static IOCase | SENSITIVE - The constant for case sensitive regardless of operating system.
|
static IOCase | SYSTEM - The constant for case sensitivity determined by the current operating system.
|
private String | name - The enumeration name.
|
private boolean | sensitive - The sensitivity flag.
|
private static long | serialVersionUID - Serialization version.
|
IOCase(String name, boolean sensitive) - Private constructor.
|
int | checkCompareTo(String str1, String str2) - Compares two strings using the case-sensitivity rule.
|
boolean | checkEndsWith(String str, String end) - Checks if one string ends with another using the case-sensitivity rule.
|
boolean | checkEquals(String str1, String str2) - Compares two strings using the case-sensitivity rule.
|
boolean | checkRegionMatches(String str, int strStartIndex, String search) - Checks if one string contains another at a specific index using the case-sensitivity rule.
|
boolean | checkStartsWith(String str, String start) - Checks if one string starts with another using the case-sensitivity rule.
|
(package private) String | convertCase(String str) - Converts the case of the input String to a standard format.
|
static IOCase | forName(String name) - Factory method to create an IOCase from a name.
|
String | getName() - Gets the name of the constant.
|
boolean | isCaseSensitive() - Does the object represent case sensitive comparison.
|
private Object | readResolve() - Replaces the enumeration from the stream with a real one.
|
String | toString() - Gets a string describing the sensitivity.
|
INSENSITIVE
public static final IOCase INSENSITIVE
The constant for case insensitive regardless of operating system.
SENSITIVE
public static final IOCase SENSITIVE
The constant for case sensitive 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.
If you derialize this constant of Windows, and deserialize on Unix, or vice
versa, then the value of the case-sensitivity flag will change.
name
private final String name
The enumeration name.
sensitive
private final boolean sensitive
The sensitivity flag.
serialVersionUID
private static final long serialVersionUID
Serialization version.
IOCase
private IOCase(String name,
boolean sensitive)
Private constructor.
name
- the namesensitive
- the sensitivity
checkCompareTo
public int checkCompareTo(String str1,
String str2)
Compares two strings using the case-sensitivity rule.
This method mimics
String.compareTo
but takes case-sensitivity
into account.
str1
- the first string to compare, not nullstr2
- the second string to compare, not null
- true if equal using the case rules
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
but takes case-sensitivity
into account.
str
- the string to check, not nullend
- the end to compare against, not null
- true if equal using the case rules
checkEquals
public boolean checkEquals(String str1,
String str2)
Compares two strings using the case-sensitivity rule.
This method mimics
String.equals
but takes case-sensitivity
into account.
str1
- the first string to compare, not nullstr2
- the second string to compare, not null
- true if equal using the case rules
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.
str
- the string to check, not nullstrStartIndex
- the index to start at in strsearch
- the start to search for, not null
- true if equal using the case rules
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.
str
- the string to check, not nullstart
- the start to compare against, not null
- true if equal using the case rules
convertCase
(package private) String convertCase(String str)
Converts the case of the input String to a standard format.
Subsequent operations can then use standard String methods.
str
- the string to convert, null returns null
- the lower-case version if case-insensitive
forName
public static IOCase forName(String name)
Factory method to create an IOCase from a name.
getName
public String getName()
Gets the name of the constant.
isCaseSensitive
public boolean isCaseSensitive()
Does the object represent case sensitive comparison.
readResolve
private Object readResolve()
Replaces the enumeration from the stream with a real one.
This ensures that the correct flag is set for SYSTEM.
toString
public String toString()
Gets a string describing the sensitivity.
- a string describing the sensitivity
Copyright (c) 2002-2008 Apache Software Foundation