【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-Currency.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
/* -*- mode: Java; fill-column: 72 -*-
* The contents of this file are subject to the ClickBlocks Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.clickblocks.org
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied, including, but not limited to, the implied warranties of
* merchantability, fitness for a particular purpose and
* non-infringement. See the License for the specific language
* governing rights and limitations under the License.
*
* ClickBlocks, the ClickBlocks logo and combinations thereof are
* trademarks of ClickBlocks, LLC in the United States and other
* countries.
*
* The Initial Developer of the Original Code is ClickBlocks, LLC.
* Portions created by ClickBlocks, LLC are Copyright (C) 2000.
* All Rights Reserved.
*/
/*
* $Log: Currency.java,v $
* Revision 1.3 2000/11/14 12:25:15 mgrand
* Moved to clickblocks packages.
*
* Revision 1.2 2000/11/03 10:25:42 mgrand
* moved to clickblocks package structure.
*
* Revision 1.1.1.1 2000/10/30 01:37:36 mgrand
* reestablished local repository
*/
package org.clickblocks.accounting;
import org.clickblocks.util.CBInternalException;
/**
* Describe a currency
* @stereotype description
* @author Mark Grand
*/
public class Currency {
private String name;
private String localCurrencySymbol;
private String internationalCurrencySymbol;
/**
* A no-currency currency for use with zero monetary amounts for
* which no currency has yet been established.
*/
public static final Currency NULL_CURRENCY = new Currency("Null Currency",
"", "", 0);
/**
* A constant for US Dollars.
*/
public static final Currency USD = new Currency("U.S. Dollar",
"$", "USD", 2);
/**
* The customary number of decimal places used to express amounts in
* this currency.
*/
private int decimalPlaces;
/**
* constructor
* @param name The name of this currency
* @param localCurrencySymbol A possibly ambigous symbol used for a
* currency within its issuing country,
* such as "$".
* @param internationalCurrencySymbol An unambiguous symbol used for
* for a currency, such as "USD".
* @param decimalPlaces The customary number of decimal places used
* to express amounts in this currency.
*/
public Currency(String name,
String localCurrencySymbol,
String internationalCurrencySymbol,
int decimalPlaces) {
this.name = name;
this.localCurrencySymbol = localCurrencySymbol;
this.internationalCurrencySymbol = internationalCurrencySymbol;
this.decimalPlaces = decimalPlaces;
} // constructor(String, String, String)
/**
* Return the name of this currency.
*/
public String getName(){
return name;
} // getName()
/**
* Return a possibly ambigous symbol used for a currency within its
* issuing country, such as "$".
*/
public String getLocalCurrencySymbol(){
return localCurrencySymbol;
} // getLocalCurrencySymbol()
/**
* Return the symbol used to unambiguously indicate a currency.
* i.e. "USD".
*/
public String getInternationalCurrencySymbol(){
return internationalCurrencySymbol;
} // getInternationalCurrencySymbol()
/**
* Convert the given monetary amount to a monetary amount that uses
* this currency.
*<p>
* The current implementation of this method is incomplete and is
* intended only for internal use. It is a noop if the given
* monetary amount is already in this currency.
* Otherwise, it throws and CBInternalException complaining that
* that currency conversions are not yet supported.
*<p>
* Future versions of this method will continue to simply return the
* given monetary amount when it is already in the desired currency.
*
* @param amount The monetary amount to convert to this currency.
*/
public MonetaryAmount convert(MonetaryAmount amount) {
if (this.equals(amount.getCurrency())) {
return amount;
} // if
if (this.equals(NULL_CURRENCY)) {
String msg = "Cannot convert to null currency";
throw new CBInternalException(toString(), msg);
} // if
if (amount.getCurrency().equals(NULL_CURRENCY)) {
return new MonetaryAmount(amount.getCurrency(),
amount.getAmount());
} // if
String msg = "Currency conversion not yet supported";
throw new CBInternalException(toString(), msg);
} // convert(MonetaryAmount)
/**
* Return true if the given object is an equivalent currency object
*/
public boolean equals(Object obj) {
if (obj instanceof Currency) {
Currency that = (Currency)obj;
return ( this.name.equals(that.name)
&& localCurrencySymbol.equals(that.localCurrencySymbol)
&& internationalCurrencySymbol.equals(
that.internationalCurrencySymbol));
} // if
return false;
} // equals(Object)
/**
* Return a hash code for this object
*/
public int hashCode() {
return (name.hashCode()^localCurrencySymbol.hashCode()
^internationalCurrencySymbol.hashCode());
} // hashCode()
/**
* Return the customary number of decimal places used to express
* amounts in this currency.
*/
public int getDecimalPlaces(){
return decimalPlaces;
} // getDecimalPlaces()
} // class Currency
上一篇:
CurrDateTime.java
下一篇:
2014年4月12日十五省联考《申论》真题(含答案解析)