Enum IOCase

java.lang.Object
java.lang.Enum<IOCase>
org.apache.commons.vfs2.filter.IOCase
All Implemented Interfaces:
Serializable, Comparable<IOCase>, java.lang.constant.Constable

public enum IOCase extends Enum<IOCase>
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 file name 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 file names.

Since:
2.4
See Also:
  • "http://commons.apache.org/proper/commons-io/"
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    The constant for case insensitive regardless of operating system.
    The constant for case sensitive regardless of operating system.
    The constant for case sensitivity determined by the current operating system.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
    The enumeration name.
    private final boolean
    The sensitivity flag.
    private static final long
    Serialization version.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    IOCase(String name, boolean sensitive)
    Constructs a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares two strings using the case-sensitivity rule.
    boolean
    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.
    int
    checkIndexOf(String str, int strStartIndex, String search)
    Checks if one string contains another starting at a specific index 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
    Checks if one string starts with another using the case-sensitivity rule.
    static IOCase
    Factory method to create an IOCase from a name.
    Gets the name of the constant.
    boolean
    Does the object represent case sensitive comparison.
    private Object
    Replaces the enumeration from the stream with a real one.
    Gets a string describing the sensitivity.
    static IOCase
    Returns the enum constant of this type with the specified name.
    static IOCase[]
    Returns an array containing the constants of this enum type, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • 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 file names, 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 serialize this constant on Windows, and deserialize on Unix, or vice versa, then the value of the case-sensitivity flag will change.

  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version.
      See Also:
    • name

      private final String name
      The enumeration name.
    • sensitive

      private final transient boolean sensitive
      The sensitivity flag.
  • Constructor Details

    • IOCase

      private IOCase(String name, boolean sensitive)
      Constructs a new instance.
      Parameters:
      name - the name
      sensitive - the sensitivity
  • Method Details

    • values

      public static IOCase[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static IOCase valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • forName

      public static IOCase forName(String name)
      Factory method to create an IOCase from a name.
      Parameters:
      name - the name to find
      Returns:
      the IOCase object
      Throws:
      IllegalArgumentException - if the name is invalid
    • readResolve

      private 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 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(String str1, 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:
      NullPointerException - if either string is null
    • checkEquals

      public boolean checkEquals(String str1, 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:
      NullPointerException - if either string is null
    • 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.

      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:
      NullPointerException - if either string is null
    • 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(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:
      NullPointerException - if either string is null
    • checkIndexOf

      public int checkIndexOf(String str, int strStartIndex, 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:
      NullPointerException - if either string is null
      Since:
      2.0
    • 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.

      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:
      NullPointerException - if either string is null
    • toString

      public String toString()
      Gets a string describing the sensitivity.
      Overrides:
      toString in class Enum<IOCase>
      Returns:
      a string describing the sensitivity