fix equals and hashcode of trade, crypto, and traditional currencies

This commit is contained in:
woodser 2024-11-11 06:49:04 -05:00
parent 9c3e405fe0
commit 3cdfa0fa27
4 changed files with 20 additions and 8 deletions

View file

@ -19,10 +19,8 @@ package haveno.core.locale;
import com.google.protobuf.Message;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@EqualsAndHashCode(callSuper = true)
public final class CryptoCurrency extends TradeCurrency {
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
private final static String PREFIX = "";

View file

@ -19,19 +19,16 @@ package haveno.core.locale;
import haveno.common.proto.ProtobufferRuntimeException;
import haveno.common.proto.persistable.PersistablePayload;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
@EqualsAndHashCode
@ToString
@Getter
@Slf4j
public abstract class TradeCurrency implements PersistablePayload, Comparable<TradeCurrency> {
protected final String code;
@EqualsAndHashCode.Exclude
protected final String name;
public TradeCurrency(String code, String name) {
@ -82,4 +79,23 @@ public abstract class TradeCurrency implements PersistablePayload, Comparable<Tr
return this.name.compareTo(other.name);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof TradeCurrency) {
TradeCurrency other = (TradeCurrency) obj;
return code.equals(other.code);
}
return false;
}
@Override
public int hashCode() {
return code.hashCode();
}
}

View file

@ -36,14 +36,12 @@ package haveno.core.locale;
import com.google.protobuf.Message;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import java.util.Currency;
import java.util.Locale;
@EqualsAndHashCode(callSuper = true)
@ToString
@Getter
public final class TraditionalCurrency extends TradeCurrency {

View file

@ -187,7 +187,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
@Override
protected void activate() {
// We want to have it updated in case an asset got removed
allCryptoCurrencies = FXCollections.observableArrayList(CurrencyUtil.getActiveSortedCryptoCurrencies( filterManager));
allCryptoCurrencies = FXCollections.observableArrayList(CurrencyUtil.getActiveSortedCryptoCurrencies(filterManager));
allCryptoCurrencies.removeAll(cryptoCurrencies);
activateGeneralOptions();