-
Notifications
You must be signed in to change notification settings - Fork 17
Issue 6091: Remove Facebook collections library #6129
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
base: develop
Are you sure you want to change the base?
Conversation
|
Could we replace this with a commons lang3 Pair? They have ImmutablePair and MutablePair as required. |
|
Personally I'd rather avoid using a Pair-type data structure at all, in favour of something with a more descriptive name. Using a Java record lets you achieve that with very little boilerplate, something like this: public record FieldValue<T>(String fieldName, T value) {
}I'd keep that in the Athena code, next to where it's used, maybe nest it in the class and make it static. |
| */ | ||
| package sleeper.athena.record; | ||
|
|
||
| public record FieldAtDimension(int dimension, Object value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is field AT dimension whereas other is field AS String. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed typo
| * | ||
| * @param array1 first ByteArray object | ||
| * @param array2 second ByteArray object | ||
| * @return true is equal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true if* equal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed typo
| * Method for checking equality versus generic object declaration. | ||
| * | ||
| * @param o object to compare versus | ||
| * @return true is equal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true if* equal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed typo
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class ByteArrayTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth testing equals validation for one null one not and for the contents of the arrays being equal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
ca61688
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few small comments otherwise looks good
| } | ||
|
|
||
| /** | ||
| * Method for checking equaility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo on equaility - should be equality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
patchwork01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Facebook have the same license as this project. I'm basing this review on my own reading of the terms:
https://github.com/facebookarchive/jcommon/blob/master/LICENSE
|
|
||
| Facebook Jcommon collections (com.facebook.jcommon:collections:0.*) | ||
|
|
||
| - Apache License, Version 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer a Maven dependency, but we've copied code directly from there so I think we need to state that in this file. I think we still need this notice, but in its own section explaining we copied the ByteArray class.
| /** | ||
| * Class to provide wrapper object for primitive byte array into an object. | ||
| * Require as hashCode and equals requied for usage of type within a HashSet. | ||
| * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra blank line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
|
|
||
| /** | ||
| * Class to provide wrapper object for primitive byte array into an object. | ||
| * Require as hashCode and equals requied for usage of type within a HashSet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the Oracle Javadoc style guide:
https://www.oracle.com/uk/technical-resources/articles/java/javadoc-tool.html#styleguide
A class description shouldn't start with "class", see "Class/interface/field descriptions can omit the subject and simply state the object." If we take the first sentence as it is, it could start with "A wrapper for ...".
There's a typo at "requied".
There are grammatical problems at "for primitive", "Require as", "equals required", "usage of type".
It's not technically true that by wrapping a byte array we turn it into an object. A byte array is already an object.
I don't think HashSet is relevant to this class?
I think the important part for us is it implements Comparable and equals/hashCode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed,
disagree on the HashSet comment as otherwise we could just use the primitive here, it is directly because we use in within HashSets that we need it as a separate class.
| public static final ByteArrayComparator BYTE_ARRAY_COMPARATOR = new ByteArrayComparator(); | ||
|
|
||
| /** | ||
| * Returns contents of object as primitive type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine for this to be a phrase rather than a full sentence, but there are grammatical problems. It's missing "the", "this", "a". I'd put "Returns the contents of this object as a primitive byte array".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| /** | ||
| * Returns contents of object as primitive type. | ||
| * | ||
| * @return array details in primitive type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what "details" or "in primitive type" means here. I'd just put "the byte array".
| } | ||
|
|
||
| /** | ||
| * Method for checking equaility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A method description shouldn't start with "method", see "Class/interface/field descriptions can omit the subject and simply state the object."
https://www.oracle.com/uk/technical-resources/articles/java/javadoc-tool.html#styleguide
There's also a typo at "equaility".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| * @param o object to compare versus | ||
| * @return true if equal | ||
| */ | ||
| public boolean equals(Object o) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually for equals/hashCode/toString we use an @Override annotation and inherit the Javadoc from Object. The Javadoc you get when you just use @Override explains a bit more.
There are a number of instances of this in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| /** | ||
| * Declared implementation of PureByteArray to match design for Arrays comparion. | ||
| */ | ||
| class PureByteArray extends ByteArray { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make this a nested static class as it was in the Facebook code, this can be private.
| /** | ||
| * Comparator for ByteArray type. | ||
| */ | ||
| class ByteArrayComparator implements Comparator<ByteArray> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make this a nested static class as it was in the Facebook code, this can be private.
| } | ||
|
|
||
| /** | ||
| * Declared implementation of PureByteArray to match design for Arrays comparion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this trying to say?
There's a typo at "comparion".
| ByteArray second = ByteArray.wrap(new byte[]{7, 8, 9}); | ||
|
|
||
| // When / Then | ||
| assertThat(first.getArray()).isEqualTo(second.getArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't testing comparison of the ByteArray objects, it's retrieving the arrays and asserting that those are equal.
I think we need to call first.equals(second) directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| ByteArray second = ByteArray.wrap(data); | ||
|
|
||
| // Then | ||
| assertThat(first.getArray()).isEqualTo(second.getArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't testing comparison of the ByteArray objects, it's retrieving the arrays and asserting that those are equal.
I think we need to call first.equals(second) directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| ByteArray result = ByteArray.wrap(data); | ||
|
|
||
| // Then | ||
| assertThat(result.getArray()).isEqualTo(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as the first test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, was from time where first test was validation something different
| } | ||
|
|
||
| @Test | ||
| void shouldValidateEqualityWhenContentsOfArraysComeFromSameSource() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be more specific than "validate equality", e.g. shouldFindByteArraysAreEqualWithSameSourceArray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| } | ||
|
|
||
| @Test | ||
| void shouldCompareByteArraysCorrectly() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test name is too vague, it suggests it's asserting more than it is. I think you wanted to assert that when we wrap two separate arrays containing the same data, they are equal?
| } | ||
|
|
||
| @Test | ||
| void shouldValidateEqualsMethodWithNullObjects() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test name should describe the behaviour being asserted, rather than name the method being tested.
| ByteArray valid = ByteArray.wrap(new byte[]{'a', 2, 3}); | ||
|
|
||
| // When / Then | ||
| assertThat(ByteArray.equals(valid, null)).isFalse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we need a version of these tests for the instance method as well?
I don't think we ever use ByteArray.equals(ByteArray, ByteArray), so it might be simpler to get rid of that and only keep the instance method?
| void shouldValidateEqualsMethodsWithDeclaredEmptyArrays() { | ||
| // Given | ||
| ByteArray first = ByteArray.wrap(null); | ||
| ByteArray second = ByteArray.wrap(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't empty arrays, they're nulls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| @Test | ||
| void shouldAllowUsageWithinAHashSet() { | ||
| //Give | ||
| TreeSet<ByteArray> treeSet = new TreeSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a HashSet, it's a TreeSet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class ByteArrayTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like we've got any tests for cases where the byte arrays aren't equal, or for using the comparator, e.g. for sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresed
Make sure you have checked all steps below.
Issue
Feature". Note that before an issue is finished, you can still make a pull request by raising a separate issue
for your progress.
Tests
Documentation
separate issue for that below.