InternalFunctors { static TokenMap<Token> tokenWithSameValue(final Object value) { return new TokenMap<Token>() { @Override public Token map(Token token) { return (value == token.value()) ? token : null; } @Override public String toString() { return String.valueOf(value); } }; }    }
@Test public void testTokenWithSameValue() { Integer i = new Integer(10); TokenMap<Token> fromToken = InternalFunctors.tokenWithSameValue(i); assertEquals("10", fromToken.toString()); assertNull(fromToken.map(new Token(1, 1, "foo"))); assertNull(fromToken.map(new Token(1, 1, 2))); assertNull(fromToken.map(new Token(1, 1, null))); Token token = new Token(1, 1, i); assertSame(token, fromToken.map(token)); }