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

Add postProcess from InputMapTemplateTest to InputMapTemplate #3

Open
JordanMartinez opened this issue Apr 14, 2016 · 3 comments
Open

Comments

@JordanMartinez
Copy link
Contributor

See FXMisc/RichTextFX#288

@JordanMartinez
Copy link
Contributor Author

So, I don't really get most of this code (so don't be surprised if this is way off), but by following the test as a model, I came up with this:

public static <S, T extends Event> InputMapTemplate<S, T> postProcess(
        InputMapTemplate<S, T> imt, BiConsumer<? extends S, ? extends T> postConsumption) {
    return new InputMapTemplate<S, T>() {
        @Override
        protected InputHandlerTemplateMap<S, T> getInputHandlerTemplateMap() {
            return imt.getInputHandlerTemplateMap().map(iht -> {
                return  (s, evt) -> {
                    Result res = iht.process(s, evt);
                    if (res == Result.CONSUME) {
                        // Here's the issue: 
                        //  's': capture<? extends S> cannot be applied to 'S'
                        //  'evt': capture<? extends T> cannot be applied to 'T' 
                        postConsumption.accept(s, evt);
                    }
                    return res;
                };
            });
        }
    };
}

If I change the BiConsumer<? extends S, ? extends T> to BiConsumer<S, T>, the above issue goes away, but I wasn't sure if that was correct or not.

@TomasMikula
Copy link
Member

Looks good. The bounds on type parameters should be

<? super S, ? super T>

i.e. super instead of extends.

@JordanMartinez
Copy link
Contributor Author

JordanMartinez commented Apr 15, 2016

Ok that's easy to fix (turns out the method below the place where I positioned this actually uses ? super S, ? super U as well... Should have known 😄 )

Edit: the test I wrote didn't work, but that was because I removed the lines that only applied postConsumption if res == Result.CONSUME. Now that these lines are back in place, the test runs fine.

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

No branches or pull requests

2 participants