01: /*
02: *
03: * JMoney - A Personal Finance Manager
04: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
05: *
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: *
21: */
22:
23: package net.sf.jmoney.model2;
24:
25: import net.sf.jmoney.fields.IAmountFormatter;
26:
27: /**
28: *
29: * @author Nigel
30: */
31: public abstract class Commodity extends ExtendableObject implements
32: Comparable<Commodity>, IAmountFormatter {
33:
34: private String name;
35:
36: protected Commodity(IObjectKey objectKey, ListKey parentKey,
37: String name, IValues extensionValues) {
38: super (objectKey, parentKey, extensionValues);
39: this .name = name;
40: }
41:
42: protected Commodity(IObjectKey objectKey, ListKey parentKey) {
43: super (objectKey, parentKey);
44: this .name = null;
45: }
46:
47: /**
48: * @return the name of the currency.
49: */
50: public String getName() {
51: return name;
52: }
53:
54: public void setName(String name) {
55: String oldName = this .name;
56: this .name = name;
57:
58: // Notify the change manager.
59: processPropertyChange(CommodityInfo.getNameAccessor(), oldName,
60: name);
61: }
62:
63: /**
64: * This method is used for debugging purposes only.
65: */
66: @Override
67: public String toString() {
68: return name;
69: }
70:
71: public int compareTo(Commodity other) {
72: return name.compareToIgnoreCase(other.name);
73: }
74:
75: /**
76: * Converts an amount of this commodity from string to integer
77: * format.
78: *
79: * @return a long value representing the amount of this commodity
80: * in units that are at least as small as the smallest possible
81: * quantity of the commodity.
82: */
83: public abstract long parse(String amountString);
84:
85: /**
86: * Converts an amount of this commodity from integer to string format.
87: */
88: public abstract String format(long amount);
89:
90: /**
91: * Although one normally uses the parse and format methods, this method
92: * is useful when dividing one commodity quantity by another.
93: *
94: * @return the scale factor for this currency (10 to the number of decimals).
95: */
96: public abstract short getScaleFactor();
97: }
|