mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-27 05:02:00 +02:00
Refactor: KeyValue: Don't require _payload.equals
Don't require _payload.equals to be implemented (correctly) and avoids inconsistencies with _payload.compareTo, which is required by type.
This commit is contained in:
parent
f7c5b74940
commit
3ea5c8d6b7
@ -137,7 +137,9 @@ public final class KeyValue implements Comparable<KeyValue>
|
|||||||
*/
|
*/
|
||||||
private final Comparable _payload;
|
private final Comparable _payload;
|
||||||
|
|
||||||
/** This field encodes three things: Kind, flags and value. */
|
/** This field encodes three things: Kind (KIND_BITS), flags (FLAGS_BITS) and
|
||||||
|
value (VALUE_BITS).
|
||||||
|
The meaning of the value depends on the kind. */
|
||||||
private final int _code;
|
private final int _code;
|
||||||
|
|
||||||
public Kind getKind()
|
public Kind getKind()
|
||||||
@ -267,6 +269,8 @@ public final class KeyValue implements Comparable<KeyValue>
|
|||||||
d = _code - snd._code;
|
d = _code - snd._code;
|
||||||
if (d != 0)
|
if (d != 0)
|
||||||
return d;
|
return d;
|
||||||
|
// Calls [compareTo] assuming that if [_code] matches, then [_payload] are
|
||||||
|
// of the same class.
|
||||||
return _payload.compareTo(snd._payload);
|
return _payload.compareTo(snd._payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +279,7 @@ public final class KeyValue implements Comparable<KeyValue>
|
|||||||
{
|
{
|
||||||
if (snd == null)
|
if (snd == null)
|
||||||
return false;
|
return false;
|
||||||
return _code == snd._code && _payload.equals(snd._payload);
|
return _code == snd._code && _payload.compareTo(snd._payload) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -757,14 +761,6 @@ public final class KeyValue implements Comparable<KeyValue>
|
|||||||
@Override
|
@Override
|
||||||
public abstract int compareTo(Complex snd);
|
public abstract int compareTo(Complex snd);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object snd)
|
|
||||||
{
|
|
||||||
if (snd instanceof Complex)
|
|
||||||
return compareTo((Complex)snd) == 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user