Class Strings.CsStrings

java.lang.Object
org.apache.commons.lang3.Strings
org.apache.commons.lang3.Strings.CsStrings
Enclosing class:
Strings

private static final class Strings.CsStrings extends Strings
Case-sentive extension.
  • Constructor Details

    • CsStrings

      private CsStrings(boolean nullIsLess)
  • Method Details

    • compare

      public int compare(String s1, String s2)
      Description copied from class: Strings
      Compare two Strings lexicographically, like String.compareTo(String).

      The return values are:

      • int = 0, if str1 is equal to str2 (or both null)
      • int < 0, if str1 is less than str2
      • int > 0, if str1 is greater than str2

      This is a null safe version of :

       str1.compareTo(str2)
       

      null value is considered less than non-null value. Two null references are considered equal.

      Case-sensitive examples

      
       Strings.CS.compare(null, null)   = 0
       Strings.CS.compare(null , "a")   < 0
       Strings.CS.compare("a", null)   > 0
       Strings.CS.compare("abc", "abc") = 0
       Strings.CS.compare("a", "b")     < 0
       Strings.CS.compare("b", "a")     > 0
       Strings.CS.compare("a", "B")     > 0
       Strings.CS.compare("ab", "abc")  < 0
       

      Case-insensitive examples

      
       Strings.CI.compareIgnoreCase(null, null)   = 0
       Strings.CI.compareIgnoreCase(null , "a")   < 0
       Strings.CI.compareIgnoreCase("a", null)    > 0
       Strings.CI.compareIgnoreCase("abc", "abc") = 0
       Strings.CI.compareIgnoreCase("abc", "ABC") = 0
       Strings.CI.compareIgnoreCase("a", "b")     < 0
       Strings.CI.compareIgnoreCase("b", "a")     > 0
       Strings.CI.compareIgnoreCase("a", "B")     < 0
       Strings.CI.compareIgnoreCase("A", "b")     < 0
       Strings.CI.compareIgnoreCase("ab", "ABC")  < 0
       
      Specified by:
      compare in class Strings
      Parameters:
      s1 - the String to compare from
      s2 - the String to compare to
      Returns:
      < 0, 0, > 0, if str1 is respectively less, equal or greater than str2
      See Also:
    • contains

      public boolean contains(CharSequence seq, CharSequence searchSeq)
      Description copied from class: Strings
      Tests if CharSequence contains a search CharSequence, handling null. This method uses String.indexOf(String) if possible.

      A null CharSequence will return false.

      Case-sensitive examples

       Strings.CS.contains(null, *)     = false
       Strings.CS.contains(*, null)     = false
       Strings.CS.contains("", "")      = true
       Strings.CS.contains("abc", "")   = true
       Strings.CS.contains("abc", "a")  = true
       Strings.CS.contains("abc", "z")  = false
       

      Case-insensitive examples

       Strings.CI.containsIgnoreCase(null, *)    = false
       Strings.CI.containsIgnoreCase(*, null)    = false
       Strings.CI.containsIgnoreCase("", "")     = true
       Strings.CI.containsIgnoreCase("abc", "")  = true
       Strings.CI.containsIgnoreCase("abc", "a") = true
       Strings.CI.containsIgnoreCase("abc", "z") = false
       Strings.CI.containsIgnoreCase("abc", "A") = true
       Strings.CI.containsIgnoreCase("abc", "Z") = false
       
      Specified by:
      contains in class Strings
      Parameters:
      seq - the CharSequence to check, may be null
      searchSeq - the CharSequence to find, may be null
      Returns:
      true if the CharSequence contains the search CharSequence, false if not or null string input
    • equals

      public boolean equals(CharSequence cs1, CharSequence cs2)
      Description copied from class: Strings
      Compares two CharSequences, returning true if they represent equal sequences of characters.

      nulls are handled without exceptions. Two null references are considered to be equal.

      Case-sensitive examples

       Strings.CS.equals(null, null)   = true
       Strings.CS.equals(null, "abc")  = false
       Strings.CS.equals("abc", null)  = false
       Strings.CS.equals("abc", "abc") = true
       Strings.CS.equals("abc", "ABC") = false
       

      Case-insensitive examples

       Strings.CI.equalsIgnoreCase(null, null)   = true
       Strings.CI.equalsIgnoreCase(null, "abc")  = false
       Strings.CI.equalsIgnoreCase("abc", null)  = false
       Strings.CI.equalsIgnoreCase("abc", "abc") = true
       Strings.CI.equalsIgnoreCase("abc", "ABC") = true
       
      Specified by:
      equals in class Strings
      Parameters:
      cs1 - the first CharSequence, may be null
      cs2 - the second CharSequence, may be null
      Returns:
      true if the CharSequences are equal (case-sensitive), or both null
      See Also:
    • equals

      public boolean equals(String s1, String s2)
      Description copied from class: Strings
      Compares two CharSequences, returning true if they represent equal sequences of characters.

      nulls are handled without exceptions. Two null references are considered to be equal.

      Case-sensitive examples

       Strings.CS.equals(null, null)   = true
       Strings.CS.equals(null, "abc")  = false
       Strings.CS.equals("abc", null)  = false
       Strings.CS.equals("abc", "abc") = true
       Strings.CS.equals("abc", "ABC") = false
       

      Case-insensitive examples

       Strings.CI.equalsIgnoreCase(null, null)   = true
       Strings.CI.equalsIgnoreCase(null, "abc")  = false
       Strings.CI.equalsIgnoreCase("abc", null)  = false
       Strings.CI.equalsIgnoreCase("abc", "abc") = true
       Strings.CI.equalsIgnoreCase("abc", "ABC") = true
       
      Specified by:
      equals in class Strings
      Parameters:
      s1 - the first CharSequence, may be null
      s2 - the second CharSequence, may be null
      Returns:
      true if the CharSequences are equal (case-sensitive), or both null
      See Also:
    • indexOf

      public int indexOf(CharSequence seq, CharSequence searchSeq, int startPos)
      Description copied from class: Strings
      Finds the first index within a CharSequence, handling null. This method uses String.indexOf(String, int) if possible.

      A null CharSequence will return -1. A negative start position is treated as zero. An empty ("") search CharSequence always matches. A start position greater than the string length only matches an empty search CharSequence.

      Case-sensitive examples

       Strings.CS.indexOf(null, *, *)          = -1
       Strings.CS.indexOf(*, null, *)          = -1
       Strings.CS.indexOf("", "", 0)           = 0
       Strings.CS.indexOf("", *, 0)            = -1 (except when * = "")
       Strings.CS.indexOf("aabaabaa", "a", 0)  = 0
       Strings.CS.indexOf("aabaabaa", "b", 0)  = 2
       Strings.CS.indexOf("aabaabaa", "ab", 0) = 1
       Strings.CS.indexOf("aabaabaa", "b", 3)  = 5
       Strings.CS.indexOf("aabaabaa", "b", 9)  = -1
       Strings.CS.indexOf("aabaabaa", "b", -1) = 2
       Strings.CS.indexOf("aabaabaa", "", 2)   = 2
       Strings.CS.indexOf("abc", "", 9)        = 3
       

      Case-insensitive examples

       Strings.CI.indexOfIgnoreCase(null, *, *)          = -1
       Strings.CI.indexOfIgnoreCase(*, null, *)          = -1
       Strings.CI.indexOfIgnoreCase("", "", 0)           = 0
       Strings.CI.indexOfIgnoreCase("aabaabaa", "A", 0)  = 0
       Strings.CI.indexOfIgnoreCase("aabaabaa", "B", 0)  = 2
       Strings.CI.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
       Strings.CI.indexOfIgnoreCase("aabaabaa", "B", 3)  = 5
       Strings.CI.indexOfIgnoreCase("aabaabaa", "B", 9)  = -1
       Strings.CI.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
       Strings.CI.indexOfIgnoreCase("aabaabaa", "", 2)   = 2
       Strings.CI.indexOfIgnoreCase("abc", "", 9)        = -1
       
      Specified by:
      indexOf in class Strings
      Parameters:
      seq - the CharSequence to check, may be null
      searchSeq - the CharSequence to find, may be null
      startPos - the start position, negative treated as zero
      Returns:
      the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input
    • lastIndexOf

      public int lastIndexOf(CharSequence seq, CharSequence searchSeq, int startPos)
      Description copied from class: Strings
      Finds the last index within a CharSequence, handling null. This method uses String.lastIndexOf(String, int) if possible.

      A null CharSequence will return -1. A negative start position returns -1. An empty ("") search CharSequence always matches unless the start position is negative. A start position greater than the string length searches the whole string. The search starts at the startPos and works backwards; matches starting after the start position are ignored.

      Case-sensitive examples

       Strings.CS.lastIndexOf(null, *, *)          = -1
       Strings.CS.lastIndexOf(*, null, *)          = -1
       Strings.CS.lastIndexOf("aabaabaa", "a", 8)  = 7
       Strings.CS.lastIndexOf("aabaabaa", "b", 8)  = 5
       Strings.CS.lastIndexOf("aabaabaa", "ab", 8) = 4
       Strings.CS.lastIndexOf("aabaabaa", "b", 9)  = 5
       Strings.CS.lastIndexOf("aabaabaa", "b", -1) = -1
       Strings.CS.lastIndexOf("aabaabaa", "a", 0)  = 0
       Strings.CS.lastIndexOf("aabaabaa", "b", 0)  = -1
       Strings.CS.lastIndexOf("aabaabaa", "b", 1)  = -1
       Strings.CS.lastIndexOf("aabaabaa", "b", 2)  = 2
       Strings.CS.lastIndexOf("aabaabaa", "ba", 2)  = 2
       

      Case-insensitive examples

       Strings.CI.lastIndexOfIgnoreCase(null, *, *)          = -1
       Strings.CI.lastIndexOfIgnoreCase(*, null, *)          = -1
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "A", 8)  = 7
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", 8)  = 5
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "AB", 8) = 4
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", 9)  = 5
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", -1) = -1
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "A", 0)  = 0
       Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", 0)  = -1
       
      Specified by:
      lastIndexOf in class Strings
      Parameters:
      seq - the CharSequence to check, may be null
      searchSeq - the CharSequence to find, may be null
      startPos - the start position, negative treated as zero
      Returns:
      the last index of the search CharSequence (always ≤ startPos), -1 if no match or null string input