/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.csv;

import static org.hamcrest.core.AllOf.allOf;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;

/**
 * Collection of matchers for asserting the type and content of tokens.
 */
final class TokenMatchers {

    public static Matcher<Token> hasType(final Token.Type expectedType) {
        return new TypeSafeDiagnosingMatcher<Token>() {

            public void describeTo(final Description description) {
                description.appendText("token has type ");
                description.appendValue(expectedType);
            }

            @Override
            protected boolean matchesSafely(final Token item,
                    final Description mismatchDescription) {
                mismatchDescription.appendText("token type is ");
                mismatchDescription.appendValue(item.type);
                if (item.type == expectedType) {
                    return true;
                }
                return false;
            }
        };
    }

    public static Matcher<Token> hasContent(final String expectedContent) {
        return new TypeSafeDiagnosingMatcher<Token>() {

            public void describeTo(final Description description) {
                description.appendText("token has content ");
                description.appendValue(expectedContent);
            }

            @Override
            protected boolean matchesSafely(final Token item,
                    final Description mismatchDescription) {
                mismatchDescription.appendText("token content is ");
                mismatchDescription.appendValue(item.content.toString());
                if (expectedContent.equals(item.content.toString())) {
                    return true;
                }
                return false;
            }
        };
    }

    public static Matcher<Token> isReady() {
        return new TypeSafeDiagnosingMatcher<Token>() {

            public void describeTo(final Description description) {
                description.appendText("token is ready ");
            }

            @Override
            protected boolean matchesSafely(final Token item,
                    final Description mismatchDescription) {
                mismatchDescription.appendText("token is not ready ");
                return item.isReady;
            }
        };
    }

    public static Matcher<Token> matches(final Token.Type expectedType, final String expectedContent) {
        return allOf(hasType(expectedType), hasContent(expectedContent));
    }

}

@@ -1709,20 +1709,23 @@
         
-if (
+return 
 item.typ
@@ -1745,91 +1745,8 @@
 Type
-) %7B%0A                    return true;%0A                %7D%0A                return false
 ;%0A  
@@ -2419,12 +2419,15 @@
     
-if (
+return 
 expe
@@ -2473,91 +2473,8 @@
 g())
-) %7B%0A                    return true;%0A                %7D%0A                return false
 ;%0A  

Simplify if statements