Skip to content
Permalink
Browse files

[#1314] Fix compare to for NULL_VALUE (#1343)

fixes #1314
  • Loading branch information...
timo95 authored and ChrizZz110 committed Aug 8, 2019
1 parent fe73953 commit 974dfd1fcc7b42c5f2387cfcf22d77cf6827d6fe
@@ -675,6 +675,14 @@ public int hashCode() {
return Arrays.hashCode(PropertyValueStrategyFactory.getRawBytes(value));
}

/**
* Compares this to another {@link PropertyValue}. See {@link PropertyValueStrategyFactory#compare}.
*
* @see PropertyValueStrategyFactory#compare
* @param other the property value to be compared.
* @return a negative integer, zero, or a positive integer as this object is less than, equal to,
* or greater than the specified object.
*/
@Override
public int compareTo(PropertyValue other) {
return PropertyValueStrategyFactory.compare(value, other.value);
@@ -41,8 +41,10 @@ public Object read(DataInputView inputView, byte typeByte) throws IOException {
public int compare(Object value, Object other) {
if (value == null && other == null) {
return 0;
} else if (value == null) {
return -1;
}
return -1;
return 1;
}

@Override
@@ -83,18 +83,21 @@ public static Object fromRawBytes(byte[] bytes) {
}

/**
* Compares two values.
* If {@code other} is not comparable to {@code value}, the used {@link PropertyValueStrategy}
* will throw an {@code IllegalArgumentException}.
* Compares two values.<br>
* {@link PropertyValue#NULL_VALUE} is considered to be less than all other properties.
* <p>
* If {@code other} is not comparable to {@code value}, the used {@link PropertyValueStrategy} will throw an
* {@code IllegalArgumentException}. This behavior violates the requirements of
* {@link Comparable#compareTo}.
*
* @param value first value.
* @param other second value.
* @return a negative integer, zero, or a positive integer as {@code value} is less than, equal
* to, or greater than {@code other}.
*/
public static int compare(Object value, Object other) {
if (value == null) {
return INSTANCE.nullStrategy.compare(null, other);
if (value == null || other == null) {
return INSTANCE.nullStrategy.compare(value, other);
} else {
PropertyValueStrategy strategy = get(value.getClass());
return strategy.compare(value, other);
@@ -506,7 +506,7 @@ public void testEqualsWithNull() {
@Test
public void testCompareTo() {
// null
assertEquals(create(null).compareTo(create(null)), 0);
validateCompareTo(create(null), create(null), create(12));
// boolean
validateCompareTo(create(false), create(false), create(true));
// short

0 comments on commit 974dfd1

Please sign in to comment.
You can’t perform that action at this time.