Source Code Cross Referenced for ListUnivariateImpl.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » stat » descriptive » 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 » Science » Apache commons math 1.1 » org.apache.commons.math.stat.descriptive 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.math.stat.descriptive;
017:
018:        import java.io.Serializable;
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import org.apache.commons.math.MathException;
023:        import org.apache.commons.math.stat.descriptive.UnivariateStatistic;
024:        import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
025:        import org.apache.commons.math.util.DefaultTransformer;
026:        import org.apache.commons.math.util.NumberTransformer;
027:
028:        /**
029:         * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $
030:         */
031:        public class ListUnivariateImpl extends DescriptiveStatistics implements 
032:                Serializable {
033:
034:            /** Serializable version identifier */
035:            private static final long serialVersionUID = -8837442489133392138L;
036:
037:            /**
038:             * Holds a reference to a list - GENERICs are going to make
039:             * out lives easier here as we could only accept List<Number>
040:             */
041:            protected List list;
042:
043:            /** Number Transformer maps Objects to Number for us. */
044:            protected NumberTransformer transformer;
045:
046:            /** hold the window size **/
047:            protected int windowSize = DescriptiveStatistics.INFINITE_WINDOW;
048:
049:            /**
050:             * No argument Constructor
051:             */
052:            public ListUnivariateImpl() {
053:                this (new ArrayList());
054:            }
055:
056:            /**
057:             * Construct a ListUnivariate with a specific List.
058:             * @param list The list that will back this DescriptiveStatistics
059:             */
060:            public ListUnivariateImpl(List list) {
061:                this (list, new DefaultTransformer());
062:            }
063:
064:            /**
065:             * Construct a ListUnivariate with a specific List.
066:             * @param list The list that will back this DescriptiveStatistics
067:             * @param transformer the number transformer used to convert the list items.
068:             */
069:            public ListUnivariateImpl(List list, NumberTransformer transformer) {
070:                super ();
071:                this .list = list;
072:                this .transformer = transformer;
073:            }
074:
075:            /**
076:             * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getValues()
077:             */
078:            public double[] getValues() {
079:
080:                int length = list.size();
081:
082:                // If the window size is not INFINITE_WINDOW AND
083:                // the current list is larger that the window size, we need to
084:                // take into account only the last n elements of the list
085:                // as definied by windowSize
086:
087:                if (windowSize != DescriptiveStatistics.INFINITE_WINDOW
088:                        && windowSize < list.size()) {
089:                    length = list.size()
090:                            - Math.max(0, list.size() - windowSize);
091:                }
092:
093:                // Create an array to hold all values
094:                double[] copiedArray = new double[length];
095:
096:                for (int i = 0; i < copiedArray.length; i++) {
097:                    copiedArray[i] = getElement(i);
098:                }
099:                return copiedArray;
100:            }
101:
102:            /**
103:             * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getElement(int)
104:             */
105:            public double getElement(int index) {
106:
107:                double value = Double.NaN;
108:
109:                int calcIndex = index;
110:
111:                if (windowSize != DescriptiveStatistics.INFINITE_WINDOW
112:                        && windowSize < list.size()) {
113:                    calcIndex = (list.size() - windowSize) + index;
114:                }
115:
116:                try {
117:                    value = transformer.transform(list.get(calcIndex));
118:                } catch (MathException e) {
119:                    e.printStackTrace();
120:                }
121:
122:                return value;
123:            }
124:
125:            /**
126:             * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getN()
127:             */
128:            public long getN() {
129:                int n = 0;
130:
131:                if (windowSize != DescriptiveStatistics.INFINITE_WINDOW) {
132:                    if (list.size() > windowSize) {
133:                        n = windowSize;
134:                    } else {
135:                        n = list.size();
136:                    }
137:                } else {
138:                    n = list.size();
139:                }
140:                return n;
141:            }
142:
143:            /**
144:             * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#addValue(double)
145:             */
146:            public void addValue(double v) {
147:                list.add(new Double(v));
148:            }
149:
150:            /**
151:             * Adds an object to this list. 
152:             * @param o Object to add to the list
153:             */
154:            public void addObject(Object o) {
155:                list.add(o);
156:            }
157:
158:            /**
159:             * Clears all statistics.
160:             * <p>
161:             * <strong>N.B.: </strong> This method has the side effect of clearing the underlying list.
162:             */
163:            public void clear() {
164:                list.clear();
165:            }
166:
167:            /**
168:             * Apply the given statistic to this univariate collection.
169:             * @param stat the statistic to apply
170:             * @return the computed value of the statistic.
171:             */
172:            public double apply(UnivariateStatistic stat) {
173:                double[] v = this .getValues();
174:
175:                if (v != null) {
176:                    return stat.evaluate(v, 0, v.length);
177:                }
178:                return Double.NaN;
179:            }
180:
181:            /**
182:             * Access the number transformer.
183:             * @return the number transformer.
184:             */
185:            public NumberTransformer getTransformer() {
186:                return transformer;
187:            }
188:
189:            /**
190:             * Modify the number transformer.
191:             * @param transformer the new number transformer.
192:             */
193:            public void setTransformer(NumberTransformer transformer) {
194:                this .transformer = transformer;
195:            }
196:
197:            /**
198:             * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#setWindowSize(int)
199:             */
200:            public synchronized void setWindowSize(int windowSize) {
201:                this .windowSize = windowSize;
202:                //Discard elements from the front of the list if the windowSize is less than 
203:                // the size of the list.
204:                int extra = list.size() - windowSize;
205:                for (int i = 0; i < extra; i++) {
206:                    list.remove(0);
207:                }
208:            }
209:
210:            /**
211:             * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getWindowSize
212:             */
213:            public int getWindowSize() {
214:                return windowSize;
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.