|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.esw.collection.ATransducer | +--net.sourceforge.esw.collection.AIOTransducer | +--net.sourceforge.esw.collection.DelimitedTransducer
Performs delimited transduction against a stream of data; fields, rows,
records, and other data dimensions that are indicated by embedded
String
instance or char
actors.
This transduction occurs both ways; put()
takes data
from the IMetaCollection
instance to which this
ITransducer
instance is attached and places it into the data
source represented by this ITransducer
instance. The
get()
method takes data from the data source represented by this
ITransducer
instance and places it into the
IMetaCollection
instance to which this ITransducer
instance is attached.
This IIOTransducer
implementor provides stream-based access for
stream based ITransducer
implementors. It abstracts out the
setting and getting of the streams, or the Reader
and
Writer
instances, into this interface.
A DelimitedTransducer
instance is quite flexible. It can
transduce data in any number of dimensions - e.g., a one-dimensional vector,
a 2-dimensional table, or an n-dimensional array. The size of the rows in any
given dimension can be uniform or varied, allowing, for example, uniform,
irregular, sparse, even triangular matrices. Delimiters can be simple
characters - for example, the familiar "tab-separated fields" method in which
the tab character delimits fields and the newline character delimits rows.
Delimiters are actually String
instances for maximal
flexibility. Delimiters can be set via the constructor or the
addDelimiter
or setDelimiter
methods.
Delimiters are specified in dimensional order, numbered from 0. For a three dimensional matrix, for example, the 0th delimiter would separate the columns, the 1st would separate the rows, and the 2nd delimiter would separate pages (for lack of a better term). Data varies in dimensional order: all the columns within a row, all the columns in the next row, and so on through the last row of the page, then all the columns within the first row of the next page, all the columns within the next row, etc.
Delimiters may not be null
.
Example:
IMetaCollection meta = MetaFactory.createMetaCollection(); DelimitedTransducer transducer = new DelimitedTransducer(); transducer.setReader( getMyReader() ); // for files or strings or others... transducer.addDelimiter( "," ); // commas delimit the first dimension transducer.addDelimiter( "\n" ); // newlines delimit the second dimension meta.setTransducer( transducer ); try { meta.get(); } catch ( TransducerException te ) { te.printStackTrace(); // in case something went wrong. }
Field Summary | |
protected boolean |
bWriteTrailingDelim
If put transductions with this DelimitedTransducer should
write out the trailing top level delimiter. |
protected java.util.HashMap |
delimiters
The Map of delimiters for this ITransducer
implementor, all of them with an Integer key and a
String value. |
protected int |
size
The size of the collection of delimiters, equal to the largest postion plus one. |
Fields inherited from class net.sourceforge.esw.collection.AIOTransducer |
reader, writer |
Fields inherited from class net.sourceforge.esw.collection.ATransducer |
contextFactory |
Constructor Summary | |
DelimitedTransducer()
Creates a new DelimitedTransducer instance with no delimiters. |
|
DelimitedTransducer(java.util.List aDelimiters)
Creates a new DelimitedTransducer instance with the specified
List of delimiters. |
|
DelimitedTransducer(java.lang.String[] aDelimiters)
Creates a new DelimitedTransducer instance with the specified array of delimiters. |
Method Summary | |
void |
addDelimiter(java.lang.String aDelimiter)
Adds the specified delimiter to this DelimitedTransducer
instance at the next availiable position. |
void |
get(IMetaCollection aCollection)
Gets the data source's data represented by this ITransducer
instance into the referenced IMetaCollection instance. |
java.lang.String |
getDelimiter(int aPosition)
Returns the delimiter at the specified position. |
int |
getDelimiterPosition(java.lang.String aDelimiter)
Returns the position for the specified delimiter within this DelimitedTransducer instance's List of
delimiters. |
protected java.util.ArrayList |
getNextToken(java.io.Reader myReader)
Returns the next token from the specified Reader instance. |
boolean |
getWriteTrailingDelimiter()
Returns whether this DelimitedTransducer instance will write
the trailing top level delimiter during put operations. |
boolean |
isTopDelimiter(java.lang.String aDelimiter)
Returns whether the specified delimiter is the last delimiter added to this DelimitedTransducer instance. |
void |
put(IMetaCollection aCollection)
Puts the referenced IMetaCollection instance's data into the
data source represented by this ITransducer instance. |
void |
setDelimiter(int aPosition,
java.lang.String aDelimiter)
Sets a delimiter at the specified position for this DelimitedTransducer instance. |
protected INode |
setupBasicNodeStructure()
Returns the graph from the INodeContextFactory instance. |
void |
setWriteTrailingDelimiter(boolean bWriteTrailingDelimiter)
Sets whether this DelimitedTransducer instance will write the
trailing top level delimiter during put method invocations. |
Methods inherited from class net.sourceforge.esw.collection.AIOTransducer |
getReader, getWriter, setReader, setWriter |
Methods inherited from class net.sourceforge.esw.collection.ATransducer |
getContextFactory, setContextFactory |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sourceforge.esw.collection.ITransducer |
getContextFactory, setContextFactory |
Field Detail |
protected java.util.HashMap delimiters
Map
of delimiters for this ITransducer
implementor, all of them with an Integer
key and a
String
value.protected int size
protected boolean bWriteTrailingDelim
put
transductions with this DelimitedTransducer should
write out the trailing top level delimiter. Default is true
.Constructor Detail |
public DelimitedTransducer()
DelimitedTransducer
instance with no delimiters.public DelimitedTransducer(java.lang.String[] aDelimiters)
aDelimiters
- the array of delimiters to add to this
DelimitedTransducer instance.public DelimitedTransducer(java.util.List aDelimiters)
DelimitedTransducer
instance with the specified
List
of delimiters.aDelimiters
- the List
of delimiters to add to this
DelimitedTransducer
instance.Method Detail |
public void setWriteTrailingDelimiter(boolean bWriteTrailingDelimiter)
DelimitedTransducer
instance will write the
trailing top level delimiter during put
method invocations.
Default is true
.bWriteTrailingDelimiter
- if this delimiter should write the trailing
delimitergetWriteTrailingDelimiter()
public boolean getWriteTrailingDelimiter()
DelimitedTransducer
instance will write
the trailing top level delimiter during put
operations.
Default is true
.setWriteTrailingDelimiter( boolean )
public void setDelimiter(int aPosition, java.lang.String aDelimiter)
DelimitedTransducer
instance.aPosition
- the delimiter's index position; index is 0 based.aDelimiter
- a new delimiter for this DelimitedTransducer
instance to use.java.lang.IndexOutOfBoundsException
- if the number of delimiters is less than
the requested position for the new
delimiter.addDelimiter( String )
,
getDelimiter( int )
,
getDelimiterPosition( String )
public void addDelimiter(java.lang.String aDelimiter)
DelimitedTransducer
instance at the next availiable position.aDelimiter
- a new delimiter for this DelimitedTransducer
instance to use.setDelimiter( int, String )
,
getDelimiter( int )
,
getDelimiterPosition( String )
public java.lang.String getDelimiter(int aPosition)
aPosition
- the position of the delimiter to return.null
if no delimiter
exists for that position.setDelimiter( int, String )
,
addDelimiter( String )
,
getDelimiterPosition( String )
public int getDelimiterPosition(java.lang.String aDelimiter)
DelimitedTransducer
instance's List
of
delimiters.aDelimiter
- the delimiter for which to find the position.-1
if this
delimiter was not found.setDelimiter( int, String )
,
addDelimiter( String )
,
getDelimiter( int )
public boolean isTopDelimiter(java.lang.String aDelimiter)
DelimitedTransducer
instance.aDelimiter
- the delimiter to check.true
if the specified delimiter is the top, otherwise
false
.public void get(IMetaCollection aCollection) throws TransducerException
ITransducer
instance into the referenced IMetaCollection
instance.
Data for any given dimension can be uniform or irregular. If no data is
present for a given dimension then the transducer inserts a
null
dimension into the collection to represent it.
Higher-numbered delimiters will terminate lower-numbered dimensions: for
instance, if delimiter n is encountered after parsing data of
dimension n-2, then dimensions n-2,n-1, and n
are all terminated.
aCollection
- the IMetaCollection
instance into which to
read.TransducerException
- if an error occurs during transduction.put( IMetaCollection )
public void put(IMetaCollection aCollection) throws TransducerException
IMetaCollection
instance's data into the
data source represented by this ITransducer
instance.
The output data format is well-formed: there are no missing delimiters.
aCollection
- the IMetaCollection
instance from which to
take data.TransducerException
- if an error occurs during transduction.get( IMetaCollection )
protected java.util.ArrayList getNextToken(java.io.Reader myReader) throws java.text.ParseException, java.io.IOException
Reader
instance.myReader
- The Reader
instance to use to get the next
token.protected INode setupBasicNodeStructure()
INodeContextFactory
instance. If
the graph doesn't contain enough depth to support the current number of
delimiters, builds the structure up until the depth of the graph is equal
to the number of delimiters.INodeContextFactory
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |