Source Code Cross Referenced for BigDecimalCache.java in  » ERP-CRM-Financial » jGnash-2 » jgnash » util » 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 » jGnash 2 » jgnash.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * jGnash, a personal finance application
003:         * Copyright (C) 2001-2008 Craig Cavanaugh
004:         * 
005:         * This program is free software: you can redistribute it and/or modify
006:         * it under the terms of the GNU General Public License as published by
007:         * the Free Software Foundation, either version 3 of the License, or
008:         * (at your option) any later version.
009:         *
010:         *  This program is distributed in the hope that it will be useful,
011:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         *  GNU General Public License for more details.
014:         *
015:         *  You should have received a copy of the GNU General Public License
016:         *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
017:         */
018:        package jgnash.util;
019:
020:        import java.math.BigDecimal;
021:
022:        /**
023:         * A list class to cache BigDecimals at specified indexes.  BigDecimalCache
024:         * operates under the assumption that it may need to expand the size of the list
025:         * if an index larger than the current capacity is being set.  A returned value
026:         * of null on a get(index) operation means that the value at that index has not
027:         * been set.
028:         * 
029:         * @author Craig Cavanaugh
030:         *
031:         * $Id: BigDecimalCache.java 197 2008-01-01 08:13:35Z ccavanaugh $
032:         */
033:        public class BigDecimalCache {
034:            private BigDecimal cache[] = new BigDecimal[0];
035:
036:            public BigDecimalCache(int capacity) {
037:                ensureCapacity(capacity);
038:            }
039:
040:            /**
041:             * Trims the capacity of this <tt>BigDecimalCache</tt> instance to the
042:             * specified size.
043:             *
044:             * @param   size    the new capacity of the cache
045:             */
046:            public void trimToSize(int size) {
047:                int oldCapacity = cache.length;
048:                if (size < oldCapacity) {
049:                    BigDecimal oldData[] = cache;
050:                    cache = new BigDecimal[size];
051:                    System.arraycopy(oldData, 0, cache, 0, size);
052:                }
053:            }
054:
055:            /**
056:             * Increases the capacity of this <tt>BigDecimalCache</tt> instance, if
057:             * necessary, to ensure that it can hold at least the number of BigDecimals
058:             * specified by the minimum capacity argument.
059:             *
060:             * @param   minCapacity   the desired minimum capacity.
061:             */
062:            public void ensureCapacity(int minCapacity) {
063:                if (minCapacity > cache.length) {
064:                    int oldCapacity = cache.length;
065:                    BigDecimal oldCache[] = cache;
066:                    int newCapacity = oldCapacity + 5;
067:                    if (newCapacity < minCapacity) {
068:                        newCapacity = minCapacity;
069:                    }
070:                    cache = new BigDecimal[newCapacity];
071:                    System.arraycopy(oldCache, 0, cache, 0, oldCapacity);
072:                }
073:            }
074:
075:            /**
076:             * Returns the capacity of the cache
077:             *
078:             * @return  the capacity of the cache.
079:             */
080:            public int capacity() {
081:                return cache.length;
082:            }
083:
084:            /**
085:             * Returns the <tt>BigDecimal</tt> at the specified position in the cache
086:             *
087:             * @param  index index of the <tt>BigDecimal</tt> to return.
088:             * @return the <tt>BigDecimal</tt> at the specified position in this list.
089:             */
090:            public final BigDecimal get(int index) {
091:                return cache[index];
092:            }
093:
094:            /**
095:             * Sets the <tt>BigDecimal</tt> at the specified position in this cache.
096:             *
097:             * @param index index of the <tt>BigDecimal</tt> to replace.
098:             * @param element <tt>BigDecimal</tt> to be stored at the specified position.
099:             */
100:            public void set(int index, BigDecimal element) {
101:                ensureCapacity(index + 1); // capacity is one more than index
102:                cache[index] = element;
103:            }
104:
105:            /**
106:             * Clear all of the BigDecimals in the cache.
107:             */
108:            public void clear() {
109:                cache = new BigDecimal[cache.length];
110:            }
111:
112:            /**
113:             * Clears the cache all of <tt>BigDecimals</tt> starting at fromIndex.
114:             *
115:             * @param fromIndex index of first BigDecimal to be cleared.
116:             */
117:            public void clear(int fromIndex) {
118:                if (fromIndex >= 0 && fromIndex < cache.length - 1) {
119:                    int toIndex = cache.length;
120:                    for (int i = fromIndex; i < toIndex; i++) {
121:                        cache[i] = null;
122:                    }
123:                } else {
124:                    ensureCapacity(fromIndex + 1);
125:                }
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.