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

Added .equals() and .hashCode() to all AbstractArray subclasses #22

Merged
merged 13 commits into from
Dec 6, 2018

Conversation

nedtwigg
Copy link
Contributor

Straightforward equality for all the AbstractStruct and AbstractMatFile subclasses. The only wrinkle is that one of the MCOS examples actually creates a cyclic object graph, which causes the equality check to StackOverflow. A cyclic object graph inside a MAT-file seems like enough of a corner case that the feature is valuable on its own, not clear how much effort it's worth expending to dig into such a tiny case.

@ennerf
Copy link
Collaborator

ennerf commented Nov 30, 2018

Thank you for the PR. I'll be travelling until next Thursday, but I'll try to take a look at it as soon as I can.

Copy link
Collaborator

@ennerf ennerf left a comment

Choose a reason for hiding this comment

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

Looks good overall, but is not Java 6 compliant due to java.util.Objects and static interface methods.

@@ -302,4 +303,18 @@ private static void checkMat5Identifier(String description) {

private static final String MAT5_IDENTIFIER = "MATLAB 5.0 MAT-file";

@Override
protected int subHashCode() {
return Objects.hash(description, subsysOffset, byteOrder, version, reduced);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Project should be compatible with Java 6, but Objects was added in Java 7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger. Re: Java 6 compliance, is this a requirement for you, or is it a requirement to make it easier for others to adopt? I think Java 8 penetration is pretty good now (it was 75% in Feb 2018). Gradle 5 now requires Java 8.

Happy to stick to SE6 if you want :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have an API that uses it and should be able to run in MATLAB 2012b (bundles a Java SE 6 runtime). Unless there is a significant upside to it, I'd prefer to not change the requirement to 2013b (bundles Java SE 7 runtime) quite yet.

@@ -48,4 +52,73 @@

void writeMat5(Sink sink) throws IOException;

static int hashCodeForType(@Nullable NumberStore store, boolean logical, MatlabType type) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

static interface methods not allowed pre-Java 8

return hash;
}

static boolean equalForType(@Nullable NumberStore a, @Nullable NumberStore b, boolean logical, MatlabType type) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

static interface methods not allowed pre-Java 8

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this should just be an instance method in UniversalNumberStore::equals for now?

}
}

protected abstract boolean subSubEquals(Object otherGuaranteedSameClass);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see a reason for the first sub- level, but nesting them seems a bit much. I'd prefer children to just override the subEqualsGuaranteedSameClass and call super if necessary.

If you feel strongly about it and really want to enforce explicit implementation, the AbstractStruct::subEqualsGuaranteedSameClass should be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger. Subclassing and equality are tricky, so I like the final approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nvm, I think you are right that calling super. is better, I misunderstood the class hierarchy.

// the object graph is not hierarchical or even a DAG.
// it is a cyclic graph which causes StackOverflow on equality check
// rare enough that it's not clear how much investigation is warranted...
boolean equalityCheck = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok punting on equality cycles.


import java.io.Closeable;
import java.io.IOException;

import javax.annotation.Nullable;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not available on maven build

@nedtwigg
Copy link
Contributor Author

nedtwigg commented Dec 6, 2018

Thanks for the feedback! I addressed all the points, ready for the next round :) mvn test passes on my box, can't figure out how to see the CI error.

@ennerf ennerf merged commit 87bd151 into HebiRobotics:develop Dec 6, 2018
@ennerf
Copy link
Collaborator

ennerf commented Dec 6, 2018

Accepted. Thank you for the PR!

The previous errors were related to @Nullable, but the latest one is a build issue on macOS only. I believe it's related to a new worker machine that was added today and has a different setup than the others. I'll look into it. If you happen to be an expert with Travis I'd be happy to accept a PR for a working script as well :)

@nedtwigg nedtwigg deleted the develop branch December 6, 2018 21:22
@nedtwigg
Copy link
Contributor Author

nedtwigg commented Dec 6, 2018

I'm okay with Travis, but useless with maven ;-)

Well done on MatFileRW, huge maintainability step up from MatFileRW. It looks ready for MatFileRW to point users to this. That okay with you? Happy to wait for 1.0 if you prefer :)

@ennerf
Copy link
Collaborator

ennerf commented Dec 6, 2018

Thanks! Does Travis not support Maven?

I just released the latest changes as version 0.3. I think I'll do the 1.0 after addressing #20 and #21, which will hopefully be next week. This may break backwards compatibility on NamedArray and global, but it's probably already ok to link to Mat-File IO.

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.

2 participants