ReactiveBeacons icon indicating copy to clipboard operation
ReactiveBeacons copied to clipboard

HashCode and Equals?!

Open doubl3p opened this issue 7 years ago • 1 comments

Wouldn't it be better just to use MacAddress for equals and hashcode? So you could compare them while observe and just list the current values of a specifiy beacon.

@Override public boolean equals(Object o) {
    if (this == o) {
      return true;
    }

    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    Beacon beacon = (Beacon) o;

    if (rssi != beacon.rssi) {
      return false;
    }

    if (!device.equals(beacon.device)) {
      return false;
    }

    return Arrays.equals(scanRecord, beacon.scanRecord);
  }

  @Override public int hashCode() {
    int result = device.hashCode();
    result = 31 * result + rssi;
    result = 31 * result + (scanRecord != null ? Arrays.hashCode(scanRecord) : 0);
    return result;
  }

doubl3p avatar Feb 16 '17 20:02 doubl3p

We can consider that. MacAddress class was introduced later. It simply wraps and validates data coming from device.getAddress() method. Moreover, device.hashCode() method is used in hashCode() generation for the Beacon class. We should check if introducing MacAdress in the hashCode() and equals() methods won't be redundant to calling device.hashCode() method and using device object.

pwittchen avatar Feb 16 '17 20:02 pwittchen