Skip to content

Commit

Permalink
[modbus] equals and hashcode implementation for ModbusRegisterArray (o…
Browse files Browse the repository at this point in the history
…penhab#2164)

Signed-off-by: Sami Salonen <ssalonen@gmail.com>
  • Loading branch information
ssalonen authored Jan 30, 2021
1 parent 46666eb commit de61ce1
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Arrays;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.util.HexUtils;

/**
Expand Down Expand Up @@ -110,4 +111,30 @@ public String toHexString() {
}
return HexUtils.bytesToHex(getBytes());
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(bytes);
return result;
}

@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
ModbusRegisterArray other = (ModbusRegisterArray) obj;
if (!Arrays.equals(bytes, other.bytes)) {
return false;
}
return true;
}
}

0 comments on commit de61ce1

Please sign in to comment.