devnied / EMV-NFC-Paycard-Enrollment

A Java library used to read and extract data from NFC EMV credit cards (Android/PCSC).
Apache License 2.0
1.44k stars 586 forks source link

Enhancement, TLV equals&hashcode #88

Closed nlucian closed 11 months ago

nlucian commented 11 months ago

It would be nice updating the TLV class with the equals&hashcode contract. Would you approve such a change please? There are lookup cases where it's nice leveraging the power of a hash structure instead of o(n) lookup (and without extra wrappers)

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof TLV)) {
        return false;
    }

    TLV targetTlv = (TLV) obj;

    if (getTagBytes().length != targetTlv.getTagBytes().length) {
        return false;
    }

    return Arrays.equals(getTagBytes(), targetTlv.getTagBytes());
}

@Override
public int hashCode() {
    return this.getTag().hashCode();
}
nlucian commented 11 months ago

Not needed anymore, but anyway it's a good idea having the contract added :)