Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is InputPreprocessor interface doing too much? #21

Closed
drapostolos opened this issue Jul 7, 2014 · 2 comments
Closed

Is InputPreprocessor interface doing too much? #21

drapostolos opened this issue Jul 7, 2014 · 2 comments

Comments

@drapostolos
Copy link
Owner

The contract for the InputPreprocessor interface currently states :

 If a null object is returned from this method, the called {@link Parser} implementation is
expected to return either:     
 * An empty {@link Collection}/ {@link Map} / Array type.
 * A null object for types other than above.

It should not be up to the InputPreprocessor to decide if an input string is considered a null object or not.

How about change the contract of InputPreprocessor interface to simply receive a string and return a string (in other words just pre-process the string as the name sugests). It should not be allowed to return a null object.

A second callback interface would be needed instead to decide if a input string should represent a null object or not, something like this:

public interface NullStringStrategy {
    boolean isNullString(String input);
}

Your comments?

@drapostolos
Copy link
Owner Author

This has been pushed to master branch now.

    public interface NullStringStrategy {
        boolean isNullString(String input, NullStringStrategyHelper helper);
    }

Where the contract of InputPreprocessor interface has changed to the following:

    /**
     * Callback interface that allows clients to do their own preparation of the input string to parse.
     * Implementations of this interface are expected to be immutable.
     * 
     * @see <a href="https://github.com/drapostolos/type-parser/wiki/User-Guide"
     *      target="_blank">User-Guide</a>
     */
    public interface InputPreprocessor {

        /**
         * Prepares the input string to be parsed. Must return a {@link String} object.
         * <p/>
         * Returning a <code>null</code> object is not supported. If a null object is return, an
         * {@link UnsupportedOperationException} will be thrown.
         * 
         * @param input String to prepare for parsing. This may be a {@code NullString} but will never
         *        be {@code null}.
         * @param helper Helper class injected automatically by the {@link TypeParser}.
         * @return a prepared string to be parsed.
         * @throws RuntimeException Any exception thrown within this method will be wrapped and
         *         re-thrown as a {@link TypeParserException} to the client.
         */
        String prepare(String input, InputPreprocessorHelper helper);
    }

@drapostolos
Copy link
Owner Author

Released in v0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant