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

Implement ReadOnlyHasValue helper #4208

Merged
merged 5 commits into from
May 31, 2018
Merged

Implement ReadOnlyHasValue helper #4208

merged 5 commits into from
May 31, 2018

Conversation

pekam
Copy link
Contributor

@pekam pekam commented May 30, 2018

Ported change from vaadin/framework#10643


This change is Reviewable

*/
public class ReadOnlyHasValue<V>
implements HasValue<ValueChangeEvent<V>, V>, Serializable {
private V value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Make "value" transient or serializable. rule

implements HasValue<ValueChangeEvent<V>, V>, Serializable {
private V value;
private final SerializableConsumer<V> valueProcessor;
private final V emptyValue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Make "emptyValue" transient or serializable. rule

@denis-anisimov
Copy link
Contributor

Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks broke.


a discussion (no related file):
There is no doc changes in flow-and-components-documentation repo


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 106 at r2 (raw file):

Quoted 21 lines of code…
                        new ValueChangeEvent<V>() {
                            @Override
                            public HasValue<?, V> getHasValue() {
                                return that;
                            }
 
                            @Override
                            public boolean isFromClient() {
                                return false;
                            }
 
                            @Override
                            public V getOldValue() {
                                return oldValue;
                            }
 
                            @Override
                            public V getValue() {
                                return value;
                            }
                        });

This is very long anonymous class inside for inside if inside method.
Please extract it as a separate nested class.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 136 at r2 (raw file):

throw new IllegalArgumentException("Not Writable");

Curly brackets around.
Even though it's not in the original PR.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 142 at r2 (raw file):

throw new IllegalArgumentException("Not Writable");

Curly brackets around.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 154 at r2 (raw file):

        return emptyValue;
    }
}

new line


Comments from Reviewable

@pekam
Copy link
Contributor Author

pekam commented May 31, 2018

Review status: 1 of 2 files reviewed at latest revision, 7 unresolved discussions.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 106 at r2 (raw file):

Previously, denis-anisimov (Denis) wrote…
                        new ValueChangeEvent<V>() {
                            @Override
                            public HasValue<?, V> getHasValue() {
                                return that;
                            }
 
                            @Override
                            public boolean isFromClient() {
                                return false;
                            }
 
                            @Override
                            public V getOldValue() {
                                return oldValue;
                            }
 
                            @Override
                            public V getValue() {
                                return value;
                            }
                        });

This is very long anonymous class inside for inside if inside method.
Please extract it as a separate nested class.

I can't because I need to implement those getters to return correct values for each case.

I extracted a method that creates and fires the event instead.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 136 at r2 (raw file):

Previously, denis-anisimov (Denis) wrote…
throw new IllegalArgumentException("Not Writable");

Curly brackets around.
Even though it's not in the original PR.

Done.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 142 at r2 (raw file):

Previously, denis-anisimov (Denis) wrote…
throw new IllegalArgumentException("Not Writable");

Curly brackets around.

Done.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 154 at r2 (raw file):

Previously, denis-anisimov (Denis) wrote…

new line

Done.


Comments from Reviewable

@denis-anisimov
Copy link
Contributor

Review status: all files reviewed at latest revision, 4 unresolved discussions.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 106 at r2 (raw file):

Previously, pekam (Pekka Maanpää) wrote…

I can't because I need to implement those getters to return correct values for each case.

I extracted a method that creates and fires the event instead.

I don't really see any problem here.
HasValue<ValueChangeEvent<V>, V> , oldValue , value may be provided as arguments in a CTOR for the class (in the same way as they have been provided as arguments in the fireValueChangeEvent method) .
It is always possible the question is just how many arguments you will need to pass to the CTOR.
There are only three of them here. Not that many.

If you make this class nested then there will no need on the method but instead there will be a long CTOR. In the result it's the same number of lines but it's more readable.


Comments from Reviewable

@pekam
Copy link
Contributor Author

pekam commented May 31, 2018

Review status: 1 of 2 files reviewed at latest revision, 4 unresolved discussions.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 106 at r2 (raw file):

Previously, denis-anisimov (Denis) wrote…

I don't really see any problem here.
HasValue<ValueChangeEvent<V>, V> , oldValue , value may be provided as arguments in a CTOR for the class (in the same way as they have been provided as arguments in the fireValueChangeEvent method) .
It is always possible the question is just how many arguments you will need to pass to the CTOR.
There are only three of them here. Not that many.

If you make this class nested then there will no need on the method but instead there will be a long CTOR. In the result it's the same number of lines but it's more readable.

Right.. Didn't realize that. Thank you! :)
Done.


Comments from Reviewable

implements ValueChangeEvent<V> {

private HasValue<?, V> hasValue;
private V value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Make "value" transient or serializable. rule


private HasValue<?, V> hasValue;
private V value;
private V oldValue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Make "oldValue" transient or serializable. rule

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 4 issues

  • MAJOR 4 major

Watch the comments in this conversation to review them.

@pekam
Copy link
Contributor Author

pekam commented May 31, 2018

Review status: 1 of 2 files reviewed at latest revision, 6 unresolved discussions.


a discussion (no related file):

Previously, denis-anisimov (Denis) wrote…

There is no doc changes in flow-and-components-documentation repo

Done:
vaadin/flow-and-components-documentation#166


Comments from Reviewable

@denis-anisimov
Copy link
Contributor

:lgtm:


Review status: all files reviewed at latest revision, 5 unresolved discussions.


flow-data/src/main/java/com/vaadin/flow/data/binder/ReadOnlyHasValue.java, line 135 at r4 (raw file):

private static class ReadOnlyValueChangeEvent<V>

I think we have some kind of agreement to keep nested class definitions on the top of the class.
I personally like those classes on the bottom. So if SQ doesn't complain then I'm OK with this as well.


Comments from Reviewable

@pekam pekam merged commit 2ce7820 into master May 31, 2018
@pekam pekam deleted the port-10643 branch May 31, 2018 08:39
@ZheSun88 ZheSun88 added this to the 1.0.0.rc2 milestone Jun 6, 2018
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

Successfully merging this pull request may close these issues.

None yet

4 participants