Java Doc for LineFormat.java in  » GIS » GeoTools-2.4.1 » org » geotools » io » 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.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.text.Format
      org.geotools.io.LineFormat

LineFormat
public class LineFormat extends Format (Code)
Parses a line of text data. This class is mostly used for parsing lines in a matrix or a table. Each column may contains numbers, dates, or other objects parseable by some Format implementations. The example below reads dates in the first column and numbers in all remaining columns.
 final LineParser parser = new LineFormat(new Format[] {
java.text.DateFormat.getDateTimeInstance ,
java.text.NumberFormat.getNumberInstance });
 
LineFormat may be used for reading a matrix with an unknow number of columns, while requiring that all lines have the same number of columns. The example below gets the number of columns while reading the first line, and ensure that all subsequent lines have the same number of columns. If one line violate this condition, then a ParseException will be thrown. The check if performed by the getValues(double[]) method when the data array is non-nul.
  double[] data=null;
  final 
java.io.BufferedReader  in = new 
java.io.BufferedReader (new 
java.io.FileReader ("MATRIX.TXT"));
  for (
String  line; (line=in.readLine()) != null;) {
      parser.setLine(line);
      data = parser.getValues(data);
      // ... process 'data' here ...
  });
 
This code can work as well with dates instead of numbers. In this case, the values returned will be microseconds ellapsed since January 1st, 1970.

A ParseException may be thrown because a string can't be parsed, because an object can't be converted into a number or because a line don't have the expected number of columns. In all case, it is possible to gets the index of the first problem found using ParseException.getErrorOffset .
since:
   2.0
version:
   $Id: LineFormat.java 25467 2007-05-08 16:30:30Z desruisseaux $
author:
   Martin Desruisseaux




Constructor Summary
public  LineFormat()
     Constructs a new line parser for the default locale.
public  LineFormat(Locale locale)
     Constructs a new line parser for the specified locale.
public  LineFormat(Format format)
     Constructs a new line parser using the specified format for every columns.
public  LineFormat(Format[] formats)
     Constructs a new line parser using the specified format objects.

Method Summary
public  voidclear()
     Clear this parser.
public  Objectclone()
     Returns a clone of this parser.
public  StringBufferformat(Object values, StringBuffer toAppendTo, FieldPosition position)
     Formats an object and appends the resulting text to a given string buffer. This method invokes (values), then formats all columns using the Format object specified at construction time.
public  ObjectgetValue(int index)
     Returns the value at the specified index.
public  intgetValueCount()
     Returns the number of elements found in the last line parsed by LineFormat.setLine(String) .
public  double[]getValues(double[] array)
     Copies all values to the specified array.
public  float[]getValues(float[] array)
     Copies all values to the specified array.
public  long[]getValues(long[] array)
     Copies all values to the specified array.
public  int[]getValues(int[] array)
     Copies all values to the specified array.
public  short[]getValues(short[] array)
     Copies all values to the specified array.
public  byte[]getValues(byte[] array)
     Copies all values to the specified array.
public  ObjectparseObject(String source, ParsePosition position)
     Parses text from a string to produce an object.
public  ObjectparseObject(String source)
     Parses text from the beginning of the given string to produce an object.
public  intsetLine(String line)
     Parse the specified line.
public  intsetLine(String line, int lower, int upper)
     Parse a substring of the specified line.
public  voidsetValue(int index, Object value)
     Set or add a value to current line.
public  voidsetValues(Object values)
     Set all values in the current line.
public  StringtoString()
     Returns a string representation of current line.


Constructor Detail
LineFormat
public LineFormat()(Code)
Constructs a new line parser for the default locale.



LineFormat
public LineFormat(Locale locale)(Code)
Constructs a new line parser for the specified locale. For example Locale.US may be used for reading numbers using the dot as decimal separator.



LineFormat
public LineFormat(Format format) throws IllegalArgumentException(Code)
Constructs a new line parser using the specified format for every columns.
Parameters:
  format - The format to use.
throws:
  IllegalArgumentException - if format is null.



LineFormat
public LineFormat(Format[] formats) throws IllegalArgumentException(Code)
Constructs a new line parser using the specified format objects. For example the first column will be parsed using formats[0] ; the second column will be parsed using formats[1] , etc. If there is more columns than formats, then the last format object is reused for all remaining columns.
Parameters:
  formats - The formats to use for parsing.
throws:
  IllegalArgumentException - if formats is null or an element of format is null.




Method Detail
clear
public void clear()(Code)
Clear this parser. Next call to LineFormat.getValueCount will returns 0.



clone
public Object clone()(Code)
Returns a clone of this parser. In current implementation, this clone is not for usage in concurrent thread.



format
public StringBuffer format(Object values, StringBuffer toAppendTo, FieldPosition position)(Code)
Formats an object and appends the resulting text to a given string buffer. This method invokes (values), then formats all columns using the Format object specified at construction time. Columns are separated by tabulation.
since:
   2.4



getValue
public Object getValue(int index) throws ArrayIndexOutOfBoundsException(Code)
Returns the value at the specified index. The index should be in the range 0 inclusively to LineFormat.getValueCount exclusively.
Parameters:
  index - Index of the value to fetch. The value at the specified index.
throws:
  ArrayIndexOutOfBoundsException - If the index is outside the expected range.



getValueCount
public int getValueCount()(Code)
Returns the number of elements found in the last line parsed by LineFormat.setLine(String) .



getValues
public double[] getValues(double[] array) throws ParseException(Code)
Copies all values to the specified array. This method is typically invoked after LineFormat.setLine(String) for fetching the values just parsed. If array is null, this method creates and returns a new array with a length equals to number of elements parsed. If array is not null, then this method will thrown an exception if the array length is not exactly equals to the number of elements parsed.
Parameters:
  array - The array to copy values into. array if it was not null, or a new array otherwise.
throws:
  ParseException - If array was not null and its length is not equals tothe number of elements parsed, or if at least one element can't be parsed.



getValues
public float[] getValues(float[] array) throws ParseException(Code)
Copies all values to the specified array. This method is typically invoked after LineFormat.setLine(String) for fetching the values just parsed. If array is null, this method creates and returns a new array with a length equals to number of elements parsed. If array is not null, then this method will thrown an exception if the array length is not exactly equals to the number of elements parsed.
Parameters:
  array - The array to copy values into. array if it was not null, or a new array otherwise.
throws:
  ParseException - If array was not null and its length is not equals tothe number of elements parsed, or if at least one element can't be parsed.



getValues
public long[] getValues(long[] array) throws ParseException(Code)
Copies all values to the specified array. This method is typically invoked after LineFormat.setLine(String) for fetching the values just parsed. If array is null, this method creates and returns a new array with a length equals to number of elements parsed. If array is not null, then this method will thrown an exception if the array length is not exactly equals to the number of elements parsed.
Parameters:
  array - The array to copy values into. array if it was not null, or a new array otherwise.
throws:
  ParseException - If array was not null and its length is not equals tothe number of elements parsed, or if at least one element can't be parsed.



getValues
public int[] getValues(int[] array) throws ParseException(Code)
Copies all values to the specified array. This method is typically invoked after LineFormat.setLine(String) for fetching the values just parsed. If array is null, this method creates and returns a new array with a length equals to number of elements parsed. If array is not null, then this method will thrown an exception if the array length is not exactly equals to the number of elements parsed.
Parameters:
  array - The array to copy values into. array if it was not null, or a new array otherwise.
throws:
  ParseException - If array was not null and its length is not equals tothe number of elements parsed, or if at least one element can't be parsed.



getValues
public short[] getValues(short[] array) throws ParseException(Code)
Copies all values to the specified array. This method is typically invoked after LineFormat.setLine(String) for fetching the values just parsed. If array is null, this method creates and returns a new array with a length equals to number of elements parsed. If array is not null, then this method will thrown an exception if the array length is not exactly equals to the number of elements parsed.
Parameters:
  array - The array to copy values into. array if it was not null, or a new array otherwise.
throws:
  ParseException - If array was not null and its length is not equals tothe number of elements parsed, or if at least one element can't be parsed.



getValues
public byte[] getValues(byte[] array) throws ParseException(Code)
Copies all values to the specified array. This method is typically invoked after LineFormat.setLine(String) for fetching the values just parsed. If array is null, this method creates and returns a new array with a length equals to number of elements parsed. If array is not null, then this method will thrown an exception if the array length is not exactly equals to the number of elements parsed.
Parameters:
  array - The array to copy values into. array if it was not null, or a new array otherwise.
throws:
  ParseException - If array was not null and its length is not equals tothe number of elements parsed, or if at least one element can't be parsed.



parseObject
public Object parseObject(String source, ParsePosition position)(Code)
Parses text from a string to produce an object.
since:
   2.4



parseObject
public Object parseObject(String source) throws ParseException(Code)
Parses text from the beginning of the given string to produce an object.
since:
   2.4



setLine
public int setLine(String line) throws ParseException(Code)
Parse the specified line. The content is immediately parsed and values can be obtained using one of the getValues(...) method.
Parameters:
  line - The line to parse. The number of elements parsed in the specified line.The same information can be obtained with LineFormat.getValueCount.
throws:
  ParseException - If at least one column can't be parsed.



setLine
public int setLine(String line, int lower, int upper) throws ParseException(Code)
Parse a substring of the specified line. The content is immediately parsed and values can be obtained using one of the getValues(...) method.
Parameters:
  line - The line to parse.
Parameters:
  lower - Index of the first character in line to parse.
Parameters:
  upper - Index after the last character in line to parse. The number of elements parsed in the specified line.The same information can be obtained with LineFormat.getValueCount.
throws:
  ParseException - If at least one column can't be parsed.



setValue
public void setValue(int index, Object value) throws ArrayIndexOutOfBoundsException(Code)
Set or add a value to current line. The index should be in the range 0 to LineFormat.getValueCount inclusively. If the index is equals to LineFormat.getValueCount , then value will be appended as a new column after existing data.
Parameters:
  index - Index of the value to add or modify.
Parameters:
  value - The new value.
throws:
  ArrayIndexOutOfBoundsException - If the index is outside the expected range.



setValues
public void setValues(Object values) throws IllegalArgumentException(Code)
Set all values in the current line. The values argument must be an array, which may be of primitive type.
Parameters:
  values - The array to set as values.
throws:
  IllegalArgumentException - if values is not an array.
since:
   2.4



toString
public String toString()(Code)
Returns a string representation of current line. All columns are formatted using the Format object specified at construction time. Columns are separated by tabulation.



Methods inherited from java.text.Format
public Object clone()(Code)(Java Doc)
final public String format(Object obj)(Code)(Java Doc)
abstract public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
public AttributedCharacterIterator formatToCharacterIterator(Object obj)(Code)(Java Doc)
abstract public Object parseObject(String source, ParsePosition pos)(Code)(Java Doc)
public Object parseObject(String source) throws ParseException(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.