devnied/EMV-NFC-Paycard-Enrollment

Enhancement, TLV equals&hashcode

nlucian opened this issue · 1 comments

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();
}

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