Class Strings.CsStrings

  • Enclosing class:
    Strings

    private static final class Strings.CsStrings
    extends Strings
    Case-sentive extension.
    • Field Summary

      • Fields inherited from class org.apache.commons.lang3.Strings

        CI, CS
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CsStrings​(boolean nullIsLess)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.String s1, java.lang.String s2)
      Compare two Strings lexicographically, like String.compareTo(String).
      boolean contains​(java.lang.CharSequence seq, java.lang.CharSequence searchSeq)
      Tests if CharSequence contains a search CharSequence, handling null.
      boolean equals​(java.lang.CharSequence cs1, java.lang.CharSequence cs2)
      Compares two CharSequences, returning true if they represent equal sequences of characters.
      boolean equals​(java.lang.String s1, java.lang.String s2)
      Compares two CharSequences, returning true if they represent equal sequences of characters.
      int indexOf​(java.lang.CharSequence seq, java.lang.CharSequence searchSeq, int startPos)
      Finds the first index within a CharSequence, handling null.
      int lastIndexOf​(java.lang.CharSequence seq, java.lang.CharSequence searchSeq, int startPos)
      Finds the last index within a CharSequence, handling null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CsStrings

        private CsStrings​(boolean nullIsLess)
    • Method Detail

      • compare

        public int compare​(java.lang.String s1,
                           java.lang.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.compare(null, null)   = 0
         Strings.CI.compare(null , "a")   < 0
         Strings.CI.compare("a", null)    > 0
         Strings.CI.compare("abc", "abc") = 0
         Strings.CI.compare("abc", "ABC") = 0
         Strings.CI.compare("a", "b")     < 0
         Strings.CI.compare("b", "a")     > 0
         Strings.CI.compare("a", "B")     < 0
         Strings.CI.compare("A", "b")     < 0
         Strings.CI.compare("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:
        String.compareTo(String)
      • contains

        public boolean contains​(java.lang.CharSequence seq,
                                java.lang.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.contains(null, *)    = false
         Strings.CI.contains(*, null)    = false
         Strings.CI.contains("", "")     = true
         Strings.CI.contains("abc", "")  = true
         Strings.CI.contains("abc", "a") = true
         Strings.CI.contains("abc", "z") = false
         Strings.CI.contains("abc", "A") = true
         Strings.CI.contains("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​(java.lang.CharSequence cs1,
                              java.lang.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.equals(null, null)   = true
         Strings.CI.equals(null, "abc")  = false
         Strings.CI.equals("abc", null)  = false
         Strings.CI.equals("abc", "abc") = true
         Strings.CI.equals("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:
        Object.equals(Object), String.compareTo(String), String.equalsIgnoreCase(String)
      • equals

        public boolean equals​(java.lang.String s1,
                              java.lang.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.equals(null, null)   = true
         Strings.CI.equals(null, "abc")  = false
         Strings.CI.equals("abc", null)  = false
         Strings.CI.equals("abc", "abc") = true
         Strings.CI.equals("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:
        Object.equals(Object), String.compareTo(String), String.equalsIgnoreCase(String)
      • indexOf

        public int indexOf​(java.lang.CharSequence seq,
                           java.lang.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.indexOf(null, *, *)          = -1
         Strings.CI.indexOf(*, null, *)          = -1
         Strings.CI.indexOf("", "", 0)           = 0
         Strings.CI.indexOf("aabaabaa", "A", 0)  = 0
         Strings.CI.indexOf("aabaabaa", "B", 0)  = 2
         Strings.CI.indexOf("aabaabaa", "AB", 0) = 1
         Strings.CI.indexOf("aabaabaa", "B", 3)  = 5
         Strings.CI.indexOf("aabaabaa", "B", 9)  = -1
         Strings.CI.indexOf("aabaabaa", "B", -1) = 2
         Strings.CI.indexOf("aabaabaa", "", 2)   = 2
         Strings.CI.indexOf("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​(java.lang.CharSequence seq,
                               java.lang.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.lastIndexOf(null, *, *)          = -1
         Strings.CI.lastIndexOf(*, null, *)          = -1
         Strings.CI.lastIndexOf("aabaabaa", "A", 8)  = 7
         Strings.CI.lastIndexOf("aabaabaa", "B", 8)  = 5
         Strings.CI.lastIndexOf("aabaabaa", "AB", 8) = 4
         Strings.CI.lastIndexOf("aabaabaa", "B", 9)  = 5
         Strings.CI.lastIndexOf("aabaabaa", "B", -1) = -1
         Strings.CI.lastIndexOf("aabaabaa", "A", 0)  = 0
         Strings.CI.lastIndexOf("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