Source Code Cross Referenced for Bond.java in  » ERP-CRM-Financial » jmoney » net » sf » jmoney » stocks » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » jmoney » net.sf.jmoney.stocks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *  JMoney - A Personal Finance Manager
004:         *  Copyright (c) 2002 Johann Gyger <johann.gyger@switzerland.org>
005:         *
006:         *
007:         *  This program is free software; you can redistribute it and/or modify
008:         *  it under the terms of the GNU General Public License as published by
009:         *  the Free Software Foundation; either version 2 of the License, or
010:         *  (at your option) any later version.
011:         *
012:         *  This program is distributed in the hope that it will be useful,
013:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         *  GNU General Public License for more details.
016:         *
017:         *  You should have received a copy of the GNU General Public License
018:         *  along with this program; if not, write to the Free Software
019:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020:         *
021:         */
022:
023:        package net.sf.jmoney.stocks;
024:
025:        import java.text.NumberFormat;
026:        import java.text.ParseException;
027:
028:        import net.sf.jmoney.model2.Commodity;
029:        import net.sf.jmoney.model2.Currency;
030:        import net.sf.jmoney.model2.IObjectKey;
031:        import net.sf.jmoney.model2.IValues;
032:        import net.sf.jmoney.model2.ListKey;
033:
034:        public class Bond extends Commodity {
035:
036:            private static final int MAX_DECIMALS = 4;
037:            private static final short[] SCALE_FACTOR = { 1, 10, 100, 1000,
038:                    10000 };
039:            private static NumberFormat[] numberFormat = null;
040:
041:            /**
042:             * Guaranteed non-null because the session default currency is
043:             * set by default.
044:             */
045:            protected IObjectKey currencyKey;
046:
047:            private long redemptionValue;
048:            private int interestRate;
049:
050:            private static void initNumberFormat() {
051:                numberFormat = new NumberFormat[MAX_DECIMALS + 1];
052:                for (int i = 0; i < numberFormat.length; i++) {
053:                    numberFormat[i] = NumberFormat.getNumberInstance();
054:                    numberFormat[i].setMaximumFractionDigits(i);
055:                    numberFormat[i].setMinimumFractionDigits(i);
056:                }
057:            }
058:
059:            /**
060:             * Constructor used by datastore plug-ins to create
061:             * a stock object.
062:             */
063:            public Bond(IObjectKey objectKey, ListKey parentKey, String name,
064:                    IObjectKey currencyKey, long redemptionValue,
065:                    int interestRate, IValues extensionValues) {
066:                super (objectKey, parentKey, name, extensionValues);
067:
068:                /*
069:                 * The currency for this account is not allowed to be null, because
070:                 * users of this class may assume it to be non-null and would not know
071:                 * how to handle this account if it were null.
072:                 * 
073:                 * If null is passed, set to the default currency for the session.
074:                 * This is guaranteed to be never null.
075:                 */
076:                if (currencyKey != null) {
077:                    this .currencyKey = currencyKey;
078:                } else {
079:                    this .currencyKey = objectKey.getSession()
080:                            .getDefaultCurrency().getObjectKey();
081:                }
082:
083:                this .redemptionValue = redemptionValue;
084:                this .interestRate = interestRate;
085:            }
086:
087:            /**
088:             * Constructor used by datastore plug-ins to create
089:             * a stock object.
090:             */
091:            public Bond(IObjectKey objectKey, ListKey parentKey) {
092:                super (objectKey, parentKey);
093:
094:                // Set the currency to the session default currency.
095:                this .currencyKey = objectKey.getSession().getDefaultCurrency()
096:                        .getObjectKey();
097:
098:                this .redemptionValue = 0;
099:                this .interestRate = 0;
100:            }
101:
102:            @Override
103:            protected String getExtendablePropertySetId() {
104:                return "net.sf.jmoney.stocks.bond";
105:            }
106:
107:            public Currency getCurrency() {
108:                return (Currency) currencyKey.getObject();
109:            }
110:
111:            public void setCurrency(Currency aCurrency) {
112:                if (aCurrency == null)
113:                    throw new IllegalArgumentException();
114:                Currency oldCurrency = getCurrency();
115:                currencyKey = aCurrency.getObjectKey();
116:
117:                // Notify the change manager.
118:                processPropertyChange(BondInfo.getCurrencyAccessor(),
119:                        oldCurrency, aCurrency);
120:            }
121:
122:            /**
123:             * @return the redemption value.
124:             */
125:            public long getRedemptionValue() {
126:                return redemptionValue;
127:            }
128:
129:            public void setRedemptionValue(long redemptionValue) {
130:                long oldRedemptionValue = this .redemptionValue;
131:                this .redemptionValue = redemptionValue;
132:
133:                // Notify the change manager.
134:                processPropertyChange(BondInfo.getRedemptionValueAccessor(),
135:                        new Long(oldRedemptionValue), new Long(redemptionValue));
136:            }
137:
138:            /**
139:             * @return the redemption value.
140:             */
141:            public int getInterestRate() {
142:                return interestRate;
143:            }
144:
145:            public void setInterestRate(int interestRate) {
146:                int oldInterestRate = this .interestRate;
147:                this .interestRate = interestRate;
148:
149:                // Notify the change manager.
150:                processPropertyChange(BondInfo.getInterestRateAccessor(),
151:                        new Integer(oldInterestRate), new Integer(interestRate));
152:            }
153:
154:            /**
155:             * @return a number format instance for this currency.
156:             */
157:
158:            private NumberFormat getNumberFormat() {
159:                if (numberFormat == null)
160:                    initNumberFormat();
161:                return numberFormat[2];
162:            }
163:
164:            @Override
165:            public long parse(String amountString) {
166:                Number amount;
167:                try {
168:                    amount = getNumberFormat().parse(amountString);
169:                } catch (ParseException pex) {
170:                    amount = new Double(0);
171:                }
172:                return Math.round(amount.doubleValue() * getScaleFactor());
173:            }
174:
175:            @Override
176:            public String format(long amount) {
177:                double a = ((double) amount) / getScaleFactor();
178:                return getNumberFormat().format(a);
179:            }
180:
181:            /**
182:             * @return the scale factor for this currency (10 to the number of decimals)
183:             */
184:            @Override
185:            public short getScaleFactor() {
186:                return SCALE_FACTOR[2];
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.