org.apache.commons.io
public final class IOCase extends java.lang.Object implements java.io.Serializable
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.
Modifier and Type | Field and Description |
---|---|
static IOCase |
INSENSITIVE
The constant for case insensitive regardless of operating system.
|
private java.lang.String |
name
The enumeration name.
|
private boolean |
sensitive
The sensitivity flag.
|
static IOCase |
SENSITIVE
The constant for case sensitive regardless of operating system.
|
private static long |
serialVersionUID
Serialization version.
|
static IOCase |
SYSTEM
The constant for case sensitivity determined by the current operating system.
|
Modifier | Constructor and Description |
---|---|
private |
IOCase(java.lang.String name,
boolean sensitive)
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
checkCompareTo(java.lang.String str1,
java.lang.String str2)
Compares two strings using the case-sensitivity rule.
|
boolean |
checkEndsWith(java.lang.String str,
java.lang.String end)
Checks if one string ends with another using the case-sensitivity rule.
|
boolean |
checkEquals(java.lang.String str1,
java.lang.String str2)
Compares two strings using the case-sensitivity rule.
|
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.
|
boolean |
checkStartsWith(java.lang.String str,
java.lang.String start)
Checks if one string starts with another using the case-sensitivity rule.
|
(package private) java.lang.String |
convertCase(java.lang.String str)
Converts the case of the input String to a standard format.
|
static IOCase |
forName(java.lang.String name)
Factory method to create an IOCase from a name.
|
java.lang.String |
getName()
Gets the name of the constant.
|
boolean |
isCaseSensitive()
Does the object represent case sensitive comparison.
|
private java.lang.Object |
readResolve()
Replaces the enumeration from the stream with a real one.
|
java.lang.String |
toString()
Gets a string describing the sensitivity.
|
public static final IOCase SENSITIVE
public static final IOCase INSENSITIVE
public static final IOCase SYSTEM
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 serialVersionUID
private final java.lang.String name
private final transient boolean sensitive
private IOCase(java.lang.String name, boolean sensitive)
name
- the namesensitive
- the sensitivitypublic static IOCase forName(java.lang.String name)
name
- the name to findjava.lang.IllegalArgumentException
- if the name is invalidprivate java.lang.Object readResolve()
public java.lang.String getName()
public boolean isCaseSensitive()
public int checkCompareTo(java.lang.String str1, java.lang.String str2)
This method mimics String.compareTo(java.lang.String)
but takes case-sensitivity
into account.
str1
- the first string to compare, not nullstr2
- the second string to compare, not nulljava.lang.NullPointerException
- if either string is nullpublic boolean checkEquals(java.lang.String str1, java.lang.String str2)
This method mimics String.equals(java.lang.Object)
but takes case-sensitivity
into account.
str1
- the first string to compare, not nullstr2
- the second string to compare, not nulljava.lang.NullPointerException
- if either string is nullpublic boolean checkStartsWith(java.lang.String str, java.lang.String start)
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 nulljava.lang.NullPointerException
- if either string is nullpublic boolean checkEndsWith(java.lang.String str, java.lang.String end)
This method mimics String.endsWith(java.lang.String)
but takes case-sensitivity
into account.
str
- the string to check, not nullend
- the end to compare against, not nulljava.lang.NullPointerException
- if either string is nullpublic boolean checkRegionMatches(java.lang.String str, int strStartIndex, java.lang.String search)
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 nulljava.lang.NullPointerException
- if either string is nulljava.lang.String convertCase(java.lang.String str)
str
- the string to convert, null returns nullpublic java.lang.String toString()
toString
in class java.lang.Object
Copyright (c) 2002-2014 Apache Software Foundation