Source Code Cross Referenced for PyObjectArray.java in  » Scripting » jython » org » python » core » 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 » Scripting » jython » org.python.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //Copyright (c) Corporation for National Research Initiatives
002:        package org.python.core;
003:
004:        /**
005:         * Provides mutable behavior on a PyObject array.  Supports operations for
006:         * implementing  <CODE>java.util.List</CODE>.
007:         * @author Clark Updike
008:         */
009:        public class PyObjectArray extends AbstractArray {
010:
011:            public void remove(int start, int stop) {
012:                super .remove(start, stop);
013:            }
014:
015:            /**
016:             * The underlying array used for storing the data.
017:             */
018:            protected PyObject[] baseArray;
019:
020:            /**
021:             * Create the array with the specified size.
022:             */
023:            public PyObjectArray() {
024:                super (PyObject.class);
025:            }
026:
027:            public PyObjectArray(PyObject[] rawArray) {
028:                super (rawArray == null ? 0 : rawArray.length);
029:                baseArray = (rawArray == null) ? new PyObject[] {} : rawArray;
030:            }
031:
032:            /**
033:             * Create the array with the specified size.
034:             * @param size number of int values initially allowed in array
035:             */
036:            public PyObjectArray(int size) {
037:                super (PyObject.class, size);
038:            }
039:
040:            /**
041:             * @param toCopy
042:             */
043:            public PyObjectArray(PyObjectArray toCopy) {
044:
045:                super (toCopy);
046:                this .baseArray = (PyObject[]) toCopy.copyArray();
047:            }
048:
049:            /**
050:             * Add a value at a specified index in the array.
051:             * <P><CODE>AbstractList</CODE> subclasses should update their
052:             * <CODE>modCount</CODE> after calling this method.
053:             *
054:             * @param index index position at which to insert element
055:             * @param value value to be inserted into array
056:             */
057:            public void add(int index, PyObject value) {
058:                makeInsertSpace(index);
059:                baseArray[index] = value;
060:            }
061:
062:            /**
063:             * Add a value to the array, appending it after the current values.
064:             * <P><CODE>AbstractList</CODE> subclasses should update their
065:             * <CODE>modCount</CODE> after calling this method.
066:             *
067:             * @param value value to be added
068:             * @return index number of added element
069:             */
070:            public int add(PyObject value) {
071:                int index = getAddIndex();
072:                baseArray[index] = value;
073:                return index;
074:            }
075:
076:            /**
077:             * Duplicates the object with the generic call.
078:             *
079:             * @return a copy of the object
080:             */
081:            public Object clone() {
082:                return new PyObjectArray(this );
083:            }
084:
085:            public boolean equals(Object o) {
086:                if (o instanceof  PyObjectArray) {
087:                    PyObjectArray arr = (PyObjectArray) o;
088:                    if (size != arr.size)
089:                        return false;
090:                    for (int i = 0; i < size; i++) {
091:                        PyObject this Elem = baseArray[i];
092:                        PyObject otherElem = arr.baseArray[i];
093:                        if (this Elem == null) {
094:                            if (otherElem == null)
095:                                continue;
096:                            return false;
097:                        }
098:                        if (!this Elem.equals(otherElem))
099:                            return false;
100:                    }
101:                    return true;
102:                }
103:                return false;
104:            }
105:
106:            public int hashCode() {
107:                int x, y;
108:                int len = size;
109:                x = 0x345678;
110:
111:                for (len--; len >= 0; len--) {
112:                    y = baseArray[len].hashCode();
113:                    x = (x + x + x) ^ y;
114:                }
115:                x ^= size;
116:                return x;
117:            }
118:
119:            /**
120:             * Discards values for a range of indices from the array. For the array of
121:             * <code>int</code> values, just sets the values to null.
122:             *
123:             * @param from index of first value to be discarded
124:             * @param to index past last value to be discarded
125:             */
126:            protected void discardValues(int from, int to) {
127:                for (int i = from; i < to; i++) {
128:                    baseArray[i] = null;
129:                }
130:            }
131:
132:            /**
133:             * Retrieve the value present at an index position in the array.
134:             *
135:             * @param index index position for value to be retrieved
136:             * @return value from position in the array
137:             */
138:            public PyObject get(int index) {
139:
140:                if (index >= 0 && index < size) {
141:                    return baseArray[index];
142:                }
143:
144:                String message = (size == 0) ? "No data was added, unable to get entry at "
145:                        + index
146:                        : "Index must be between " + 0 + " and " + (size - 1)
147:                                + ", but was " + index;
148:                throw new ArrayIndexOutOfBoundsException(message);
149:
150:            }
151:
152:            /**
153:             * Get the backing array. This method is used by the type-agnostic base
154:             * class code to access the array used for type-specific storage.  The array
155:             * should generally not be modified.  To get a copy of the array, see
156:             * {@link #toArray()} which returns a copy.  Note that 
157:             * <CODE>getSize()</CODE> should be used to determine the number of elements
158:             * in the array, not the array's length (which may reflect excess capacity).
159:             * <CODE>toArray()</CODE> returns an array whose length equals the value
160:             * returned by <CODE>getSize()</CODE>.
161:             *
162:             * @return backing array object
163:             */
164:            public Object getArray() {
165:                return baseArray;
166:            }
167:
168:            /**
169:             * Set the value at an index position in the array.
170:             *
171:             * @param index index position to be set
172:             * @param value value to be set
173:             */
174:            public PyObject set(int index, PyObject value) {
175:                if (index >= 0 && index < size) {
176:                    PyObject existing = baseArray[index];
177:                    baseArray[index] = value;
178:                    return existing;
179:                }
180:                throw new ArrayIndexOutOfBoundsException(
181:                        "Index must be between " + 0 + " and " + (size - 1)
182:                                + ", but was " + index);
183:            }
184:
185:            /**
186:             * Set the backing array. This method is used by the type-agnostic base
187:             * class code to set the array used for type-specific storage.
188:             *
189:             * @param array the backing array object
190:             */
191:            protected void setArray(Object array) {
192:                baseArray = (PyObject[]) array;
193:            }
194:
195:            /**
196:             * Constructs and returns a simple array containing the same data as held
197:             * in this growable array.  The array's length matches the value returned
198:             * by <CODE>getSize()</CODE>
199:             *
200:             * @return array containing a copy of the data
201:             */
202:            public PyObject[] toArray() {
203:                return (PyObject[]) copyArray();
204:            }
205:
206:            public void ensureCapacity(int minCapacity) {
207:                super.ensureCapacity(minCapacity);
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.