Source Code Cross Referenced for DataDefinition.java in  » GIS » GeoTools-2.4.1 » org » geotools » index » 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 » GIS » GeoTools 2.4.1 » org.geotools.index 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005:         * 
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.index;
017:
018:        import java.nio.charset.Charset;
019:        import java.util.ArrayList;
020:
021:        /**
022:         * DOCUMENT ME!
023:         *
024:         * @author Tommaso Nolli
025:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/index/DataDefinition.java $
026:         */
027:        public class DataDefinition {
028:            private Charset charset;
029:            private ArrayList fields;
030:
031:            public DataDefinition(String charset) {
032:                fields = new ArrayList();
033:                this .charset = Charset.forName(charset);
034:            }
035:
036:            public final boolean isValid() {
037:                return (this .charset != null) && !this .charset.equals("")
038:                        && (this .fields.size() > 0);
039:            }
040:
041:            public int getFieldsCount() {
042:                return this .fields.size();
043:            }
044:
045:            public Field getField(int i) {
046:                return (Field) this .fields.get(i);
047:            }
048:
049:            /**
050:             * Well known classes
051:             * 
052:             * <ul>
053:             * <li>
054:             * Short
055:             * </li>
056:             * <li>
057:             * Integer
058:             * </li>
059:             * <li>
060:             * Long
061:             * </li>
062:             * <li>
063:             * Float
064:             * </li>
065:             * <li>
066:             * Double
067:             * </li>
068:             * <li>
069:             * Date
070:             * </li>
071:             * </ul>
072:             * 
073:             *
074:             * @param clazz
075:             *
076:             * @throws TreeException DOCUMENT ME!
077:             */
078:            public void addField(Class clazz) {
079:                if (clazz.isAssignableFrom(Short.class)) {
080:                    this .fields.add(new Field(clazz, 2));
081:                } else if (clazz.isAssignableFrom(Integer.class)) {
082:                    this .fields.add(new Field(clazz, 4));
083:                } else if (clazz.isAssignableFrom(Long.class)) {
084:                    this .fields.add(new Field(clazz, 8));
085:                } else if (clazz.isAssignableFrom(Float.class)) {
086:                    // TODO: Are you sure of 4 bytes?
087:                    this .fields.add(new Field(clazz, 4));
088:                } else if (clazz.isAssignableFrom(Double.class)) {
089:                    this .fields.add(new Field(clazz, 8));
090:                } else {
091:                    throw new IllegalArgumentException("Unknow len of class "
092:                            + clazz + "use addField(int)");
093:                }
094:            }
095:
096:            /**
097:             * For classes with unknown length; this values will be threated as
098:             * <code>String</code>s and truncated at the specified len
099:             *
100:             * @param len
101:             */
102:            public void addField(int len) {
103:                this .fields.add(new Field(String.class, len));
104:            }
105:
106:            /**
107:             * DOCUMENT ME!
108:             *
109:             */
110:            public Charset getCharset() {
111:                return charset;
112:            }
113:
114:            /**
115:             * Gets the max len of the data
116:             *
117:             */
118:            public int getLen() {
119:                int len = 0;
120:
121:                Field field = null;
122:
123:                for (int i = 0; i < this .fields.size(); i++) {
124:                    field = (Field) this .fields.get(i);
125:                    len += field.getLen();
126:                }
127:
128:                return len;
129:            }
130:
131:            /**
132:             * Gets the len of this field after the encoding, this method may be
133:             * different from getLen() only if exists strings in the definition
134:             *
135:             */
136:            public int getEncodedLen() {
137:                int len = 0;
138:
139:                Field field = null;
140:
141:                for (int i = 0; i < this .fields.size(); i++) {
142:                    field = (Field) this .fields.get(i);
143:                    len += field.getEncodedLen();
144:                }
145:
146:                return len;
147:            }
148:
149:            /**
150:             * Inner class for Data fields
151:             *
152:             * @author Tommaso Nolli
153:             */
154:            public class Field {
155:                private Class clazz;
156:                private int len;
157:
158:                public Field(Class clazz, int len) {
159:                    this .clazz = clazz;
160:                    this .len = len;
161:                }
162:
163:                /**
164:                 * DOCUMENT ME!
165:                 *
166:                 */
167:                public Class getFieldClass() {
168:                    return clazz;
169:                }
170:
171:                /**
172:                 * DOCUMENT ME!
173:                 *
174:                 */
175:                public int getLen() {
176:                    return len;
177:                }
178:
179:                /**
180:                 * DOCUMENT ME!
181:                 *
182:                 */
183:                public int getEncodedLen() {
184:                    int ret = this .len;
185:
186:                    if (this .clazz.equals(String.class)) {
187:                        ret = (int) charset.newEncoder().maxBytesPerChar()
188:                                * this.len;
189:                    }
190:
191:                    return ret;
192:                }
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.