devnied / EMV-NFC-Paycard-Enrollment

A Java library used to read and extract data from NFC EMV credit cards (Android/PCSC).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhancement, TLV equals&hashcode

nlucian opened this issue · 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 :)