org.hamcrest
Class TypeSafeMatcher<T>

java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.hamcrest.TypeSafeMatcher<T>
All Implemented Interfaces:
Matcher<T>, SelfDescribing
Direct Known Subclasses:
HasProperty, HasPropertyWithValue, HasXPath, IsArray, IsArrayContaining, IsCloseTo, IsCollectionContaining, IsCompatibleType, IsEqualIgnoringCase, IsEqualIgnoringWhiteSpace, IsEventFrom, IsGreaterThan, IsMapContaining, PatternMatcher, SubstringMatcher

public abstract class TypeSafeMatcher<T>
extends BaseMatcher<T>

Convenient base class for Matchers that require a non-null value of a specific type. This simply implements the null check, checks the type and then casts.

Author:
Joe Walnes

Constructor Summary
protected TypeSafeMatcher()
           
protected TypeSafeMatcher(java.lang.Class<T> expectedType)
           
 
Method Summary
 boolean matches(java.lang.Object item)
          Method made final to prevent accidental override.
abstract  boolean matchesSafely(T item)
          Subclasses should implement this.
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.hamcrest.SelfDescribing
describeTo
 

Constructor Detail

TypeSafeMatcher

protected TypeSafeMatcher()

TypeSafeMatcher

protected TypeSafeMatcher(java.lang.Class<T> expectedType)
Method Detail

matchesSafely

public abstract boolean matchesSafely(T item)
Subclasses should implement this. The item will already have been checked for the specific type and will never be null.


matches

public final boolean matches(java.lang.Object item)
Method made final to prevent accidental override. If you need to override this, there's no point on extending TypeSafeMatcher. Instead, extend the BaseMatcher.

Parameters:
item - the object against which the matcher is evaluated.
Returns:
true if item matches, otherwise false.
See Also:
BaseMatcher