Skip to content
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

HashCode and Equals?! #53

Open
doubl3p opened this issue Feb 16, 2017 · 1 comment
Open

HashCode and Equals?! #53

doubl3p opened this issue Feb 16, 2017 · 1 comment

Comments

@doubl3p
Copy link

doubl3p commented Feb 16, 2017

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;
  }
@pwittchen
Copy link
Owner

pwittchen commented Feb 16, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants