CharSequenceLength (Hamcrest 2.2 API)
Date: 2019-10-17

org.hamcrest.text

## Class CharSequenceLength

- java.lang.Object
- - org.hamcrest.BaseMatcher<T>
  - - org.hamcrest.TypeSafeDiagnosingMatcher<T>
    - - org.hamcrest.FeatureMatcher<java.lang.CharSequence,java.lang.Integer>
      - - org.hamcrest.text.CharSequenceLength

- All Implemented Interfaces:
    Matcher<java.lang.CharSequence>, SelfDescribing

      public class CharSequenceLength
      extends FeatureMatcher<java.lang.CharSequence,java.lang.Integer>

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CharSequenceLength(Matcher<? super java.lang.Integer> lengthMatcher)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.lang.Integer` | `featureValueOf(java.lang.CharSequence actual)` Implement this to extract the interesting feature.
    `static Matcher<java.lang.CharSequence>` | `hasLength(int length)` Creates a matcher of `CharSequence` that matches when a char sequence has the given length For example:
    `static Matcher<java.lang.CharSequence>` | `hasLength(Matcher<? super java.lang.Integer> lengthMatcher)` Creates a matcher of `CharSequence` that matches when a char sequence has the given length For example:

    - ### Methods inherited from class org.hamcrest.FeatureMatcher

      `describeTo, matchesSafely`

    - ### Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher

      `describeMismatch, matches`

    - ### Methods inherited from class org.hamcrest.BaseMatcher

      `_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### CharSequenceLength

          public CharSequenceLength(Matcher<? super java.lang.Integer> lengthMatcher)

      Parameters:
        `lengthMatcher` - The matcher to apply to the feature

  - ### Method Detail

    - #### featureValueOf

          protected java.lang.Integer featureValueOf(java.lang.CharSequence actual)

      Description copied from class: `FeatureMatcher`
      Implement this to extract the interesting feature.
      Specified by:
        `featureValueOf` in class `FeatureMatcher<java.lang.CharSequence,java.lang.Integer>`
      Parameters:
        `actual` - the target object
      Returns:
        the feature to be matched

    - #### hasLength

          public static Matcher<java.lang.CharSequence> hasLength(int length)

      Creates a matcher of `CharSequence` that matches when a char sequence has the given length For example:

           assertThat("text", hasLength(4))

      Parameters:
        `length` - the expected length of the string

    - #### hasLength

          public static Matcher<java.lang.CharSequence> hasLength(Matcher<? super java.lang.Integer> lengthMatcher)

      Creates a matcher of `CharSequence` that matches when a char sequence has the given length For example:

           assertThat("text", hasLength(lessThan(4)))

      Parameters:
        `lengthMatcher` - the expected length of the string