11ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot/*  Copyright (c) 2000-2006 hamcrest.org
21ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot */
31ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotpackage org.hamcrest.core;
41ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
51ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport static org.hamcrest.core.IsNot.not;
61ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport org.hamcrest.Description;
71ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport org.hamcrest.Matcher;
81ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport org.hamcrest.Factory;
91ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport org.hamcrest.BaseMatcher;
101ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
111ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot/**
121ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * Is the value null?
131ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot */
141ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotpublic class IsNull<T> extends BaseMatcher<T> {
151ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    public boolean matches(Object o) {
161ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot        return o == null;
171ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    }
181ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
191ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    public void describeTo(Description description) {
201ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot        description.appendText("null");
211ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    }
221ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
231ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    /**
241ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     * Matches if value is null.
251ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     */
261ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    @Factory
271ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    public static <T> Matcher<T> nullValue() {
281ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot        return new IsNull<T>();
291ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    }
301ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
311ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    /**
321ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     * Matches if value is not null.
331ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     */
341ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    @Factory
351ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    public static <T> Matcher<T> notNullValue() {
361ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot        return not(IsNull.<T>nullValue());
371ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    }
381ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
391ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    /**
401ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     * Matches if value is null. With type inference.
411ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     */
421ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    @Factory
431ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    public static <T> Matcher<T> nullValue(@SuppressWarnings("unused") Class<T> type) {
441ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot        return nullValue();
451ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    }
461ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
471ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    /**
481ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     * Matches if value is not null. With type inference.
491ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot     */
501ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    @Factory
511ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    public static <T> Matcher<T> notNullValue(@SuppressWarnings("unused") Class<T> type) {
521ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot        return notNullValue();
531ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot    }
541ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot}
551ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
56