/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.locale;
import io.bitsquare.app.Version;
import io.bitsquare.common.persistance.Persistable;
import org.jetbrains.annotations.NotNull;
public abstract class TradeCurrency implements Persistable, Comparable<TradeCurrency> {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
protected final String code;
protected final String name;
protected String symbol;
public TradeCurrency(String code) {
this.code = code;
this.name = CurrencyUtil.getNameByCode(code);
}
protected TradeCurrency(String code, String name) {
this.code = code;
this.name = name;
}
public TradeCurrency(String code, String name, String symbol) {
this.code = code;
this.name = name;
this.symbol = symbol;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public String getSymbol() {
return symbol;
}
public String getDisplayPrefix() {
return "";
}
public String getNameAndCode() {
return name + " (" + code + ")";
}
public String getCodeAndName() {
return code + " (" + name + ")";
}
@Override
public int compareTo(@NotNull TradeCurrency other) {
return this.getName().compareTo(other.getName());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TradeCurrency)) return false;
TradeCurrency that = (TradeCurrency) o;
return !(getCode() != null ? !getCode().equals(that.getCode()) : that.getCode() != null);
}
@Override
public int hashCode() {
return getCode() != null ? getCode().hashCode() : 0;
}
@Override
public String toString() {
return "TradeCurrency{" +
"code='" + code + '\'' +
", name='" + name + '\'' +
", symbol='" + symbol + '\'' +
'}';
}
}