/** * Factory * * @param commonCode commonly used code for this currency: "BTC" * @param name Name of the currency: "Bitcoin" * @param unicode Unicode symbol for the currency: "\u20BF" or "฿" * @param alternativeCodes Alternative codes for the currency: "XBT" */ private static Currency createCurrency( String commonCode, String name, String unicode, String... alternativeCodes) { CurrencyAttributes attributes = new CurrencyAttributes(commonCode, name, unicode, alternativeCodes); Currency currency = new Currency(commonCode, attributes); for (String code : attributes.codes) { if (commonCode.equals(code)) { // common code will always be part of the currencies map currencies.put(code, currency); } else if (!currencies.containsKey(code)) { // alternative codes will never overwrite common codes currencies.put(code, new Currency(code, attributes)); } } return currency; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Currency other = (Currency) obj; return attributes.equals(other.attributes); }
/** * Factory * * @param commonCode commonly used code for this currency: "BTC" * @param name Name of the currency: "Bitcoin" * @param unicode Unicode symbol for the currency: "\u20BF" or "฿" * @param alternativeCodes Alternative codes for the currency: "XBT" */ private static Currency createCurrency( String commonCode, String name, String unicode, String... alternativeCodes) { CurrencyAttributes attributes = new CurrencyAttributes(commonCode, name, unicode, alternativeCodes); Currency currency = new Currency(commonCode, attributes); for (String code : attributes.codes) { if (commonCode.equals(code)) { // common code will always be part of the currencies map currencies.put(code, currency); } else if (!currencies.containsKey(code)) { // alternative codes will never overwrite common codes currencies.put(code, new Currency(code, attributes)); } } return currency; }
@Override public int hashCode() { return attributes.hashCode(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Currency other = (Currency) obj; return attributes.equals(other.attributes); }
@Override public int compareTo(Currency o) { if (attributes.equals(o.attributes)) return 0; int comparison = code.compareTo(o.code); if (comparison == 0) comparison = getDisplayName().compareTo(o.getDisplayName()); if (comparison == 0) comparison = hashCode() - o.hashCode(); return comparison; }
@Override public int hashCode() { return attributes.hashCode(); }
@Override public int compareTo(Currency o) { if (attributes.equals(o.attributes)) return 0; int comparison = code.compareTo(o.code); if (comparison == 0) comparison = getDisplayName().compareTo(o.getDisplayName()); if (comparison == 0) comparison = hashCode() - o.hashCode(); return comparison; }