Top Description Fields Constructors Methods
org.apache.commons.io

public final Class IOCase

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.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.

Author
Stephen Colebourne
Since
Commons IO 1.3
Version
$Id: IOCase.java 484844 2006-12-08 23:27:18Z ggregory $

Field Summary

Modifier and TypeField and Description
public static final IOCase
INSENSITIVE

The constant for case insensitive regardless of operating system.

private final String
name

The enumeration name.

public static final IOCase
SENSITIVE

The constant for case sensitive regardless of operating system.

private final transient boolean
sensitive

The sensitivity flag.

private static final long
serialVersionUID

Serialization version.

public static final IOCase
SYSTEM

The constant for case sensitivity determined by the current operating system.

Constructor Summary

AccessConstructor and Description
private
IOCase(String
the name
name
,
boolean
the sensitivity
sensitive
)

Private constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if equal using the case rules
checkEndsWith
(String
the string to check, not null
str
,
String
the end to compare against, not null
end
)

Checks if one string ends with another using the case-sensitivity rule.

public boolean

Returns:

true if equal using the case rules
checkEquals
(String
the first string to compare, not null
str1
,
String
the second string to compare, not null
str2
)

Compares two strings using the case-sensitivity rule.

public boolean

Returns:

true if equal using the case rules
checkRegionMatches
(String
the string to check, not null
str
,
int
the index to start at in str
strStartIndex
,
String
the start to search for, not null
search
)

Checks if one string contains another at a specific index using the case-sensitivity rule.

public boolean

Returns:

true if equal using the case rules
checkStartsWith
(String
the string to check, not null
str
,
String
the start to compare against, not null
start
)

Checks if one string starts with another using the case-sensitivity rule.

pack-priv String

Returns:

the lower-case version if case-insensitive
convertCase
(String
the string to convert, null returns null
str
)

Converts the case of the input String to a standard format.

public static IOCase

Returns:

the IOCase object
forName
(String
the name to find
name
)

Factory method to create an IOCase from a name.

public String

Returns:

the name of the constant
getName
()

Gets the name of the constant.

public boolean

Returns:

true if case sensitive
isCaseSensitive
()

Does the object represent case sensitive comparison.

private Object

Returns:

the resolved object
readResolve
()

Replaces the enumeration from the stream with a real one.

public String

Returns:

a string describing the sensitivity
toString
()

Overrides java.lang.Object.toString.

Gets a string describing the sensitivity.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

INSENSITIVEback to summary
public static final IOCase INSENSITIVE

The constant for case insensitive regardless of operating system.

nameback to summary
private final String name

The enumeration name.

SENSITIVEback to summary
public static final IOCase SENSITIVE

The constant for case sensitive regardless of operating system.

sensitiveback to summary
private final transient boolean sensitive

The sensitivity flag.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

SYSTEMback to summary
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.

Constructor Detail

IOCaseback to summary
private IOCase(String name, boolean sensitive)

Private constructor.

Parameters
name:String

the name

sensitive:boolean

the sensitivity

Method Detail

checkEndsWithback to summary
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.

Parameters
str:String

the string to check, not null

end:String

the end to compare against, not null

Returns:boolean

true if equal using the case rules

Exceptions
NullPointerException:
if either string is null
checkEqualsback to summary
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.

Parameters
str1:String

the first string to compare, not null

str2:String

the second string to compare, not null

Returns:boolean

true if equal using the case rules

Exceptions
NullPointerException:
if either string is null
checkRegionMatchesback to summary
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:String

the string to check, not null

strStartIndex:int

the index to start at in str

search:String

the start to search for, not null

Returns:boolean

true if equal using the case rules

Exceptions
NullPointerException:
if either string is null
checkStartsWithback to summary
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:String

the string to check, not null

start:String

the start to compare against, not null

Returns:boolean

true if equal using the case rules

Exceptions
NullPointerException:
if either string is null
convertCaseback to summary
pack-priv String convertCase(String str)

Converts the case of the input String to a standard format. Subsequent operations can then use standard String methods.

Parameters
str:String

the string to convert, null returns null

Returns:String

the lower-case version if case-insensitive

forNameback to summary
public static IOCase forName(String name)

Factory method to create an IOCase from a name.

Parameters
name:String

the name to find

Returns:IOCase

the IOCase object

Exceptions
IllegalArgumentException:
if the name is invalid
getNameback to summary
public String getName()

Gets the name of the constant.

Returns:String

the name of the constant

isCaseSensitiveback to summary
public boolean isCaseSensitive()

Does the object represent case sensitive comparison.

Returns:boolean

true if case sensitive

readResolveback to summary
private Object readResolve()

Replaces the enumeration from the stream with a real one. This ensures that the correct flag is set for SYSTEM.

Returns:Object

the resolved object

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Gets a string describing the sensitivity.

Returns:String

a string describing the sensitivity