org.apache.commons.io
Class IOCase

java.lang.Object
  extended by org.apache.commons.io.IOCase
All Implemented Interfaces:
java.io.Serializable

public final class IOCase
extends java.lang.Object
implements 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.

Since:
Commons IO 1.3
Version:
$Id: IOCase.java 1003647 2010-10-01 20:53:59Z niallp $
Author:
Stephen Colebourne
See Also:
Serialized Form

Field Summary
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.
 
Constructor Summary
private IOCase(java.lang.String name, boolean sensitive)
          Private constructor.
 
Method Summary
 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.
 int checkIndexOf(java.lang.String str, int strStartIndex, java.lang.String search)
          Checks if one string contains another starting at a specific index 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.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.


serialVersionUID

private static final long serialVersionUID
Serialization version.

See Also:
Constant Field Values

name

private final java.lang.String name
The enumeration name.


sensitive

private final transient boolean sensitive
The sensitivity flag.

Constructor Detail

IOCase

private IOCase(java.lang.String name,
               boolean sensitive)
Private constructor.

Parameters:
name - the name
sensitive - the sensitivity
Method Detail

forName

public static IOCase forName(java.lang.String name)
Factory method to create an IOCase from a name.

Parameters:
name - the name to find
Returns:
the IOCase object
Throws:
java.lang.IllegalArgumentException - if the name is invalid

readResolve

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.

Returns:
the resolved object

getName

public java.lang.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(java.lang.String str1,
                          java.lang.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 null
str2 - the second string to compare, not null
Returns:
true if equal using the case rules
Throws:
java.lang.NullPointerException - if either string is null

checkEquals

public boolean checkEquals(java.lang.String str1,
                           java.lang.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 null
str2 - the second string to compare, not null
Returns:
true if equal using the case rules
Throws:
java.lang.NullPointerException - if either string is null

checkStartsWith

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 String.startsWith(String) but takes case-sensitivity into account.

Parameters:
str - the string to check, not null
start - the start to compare against, not null
Returns:
true if equal using the case rules
Throws:
java.lang.NullPointerException - if either string is null

checkEndsWith

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 String.endsWith(java.lang.String) but takes case-sensitivity into account.

Parameters:
str - the string to check, not null
end - the end to compare against, not null
Returns:
true if equal using the case rules
Throws:
java.lang.NullPointerException - if either string is null

checkIndexOf

public int checkIndexOf(java.lang.String str,
                        int strStartIndex,
                        java.lang.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 null
strStartIndex - the index to start at in str
search - the start to search for, not null
Returns:
the first index of the search String, -1 if no match or null string input
Throws:
java.lang.NullPointerException - if either string is null
Since:
Commons IO 2.0

checkRegionMatches

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 String.regionMatches(boolean, int, String, int, int) but takes case-sensitivity into account.

Parameters:
str - the string to check, not null
strStartIndex - the index to start at in str
search - the start to search for, not null
Returns:
true if equal using the case rules
Throws:
java.lang.NullPointerException - if either string is null

toString

public java.lang.String toString()
Gets a string describing the sensitivity.

Overrides:
toString in class java.lang.Object
Returns:
a string describing the sensitivity


Copyright (c) 2002-2012 Apache Software Foundation