public class Document extends TrianaType implements AsciiComm
NOT_CONNECTED, NOT_READY, OUT_OF_RANGE
Constructor and Description |
---|
Document()
Creates a new empty Document, setting its state to false.
|
Document(java.lang.String contents)
Creates a new Document with the contents set to the specified String.
|
Document(java.lang.String contents,
FileName file)
Creates a new Document with the contents set to the specified String and with a String representing the full path
and name of the file which the Document was taken from.
|
Document(java.lang.String contents,
java.lang.String fileAndPath)
Creates a new Document with the contents set to the specified String and with a String representing the full path
and name of the file which the Document was taken from.
|
Document(java.lang.String contents,
java.lang.String file,
java.lang.String directory)
Creates a new Document with the contents set to the specified String, with the given name of the file from which
the Document was taken, and with the given directory for the Document.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String insertion)
Appends the given text to the existing Document.
|
void |
addCharGroupsLayer(java.util.ArrayList cg)
Sets a new ArrayList into the stack of ArrayLists containing interesting character groups and makes this new one
the current one, making the previous one the domain.
|
void |
addLine(java.lang.String text)
Appends the given text to the Document and appends a further line break afterwards.
|
void |
addLineNumber(int n)
Adds an interesting line number to the line number array in the right order.
|
int |
containedInCharGroup(int character)
Returns the index of the character group containing the given character position.
|
int |
containedInCharGroup(int character,
int firstGroup)
Returns the index of the character group containing the given character position, starting the search of
character groups from the given group.
|
void |
copyData(TrianaType source)
Copies the Document by value from the given source, not by reference.
|
TrianaType |
copyMe()
This is one of the most important methods of Triana data.
|
void |
copyParameters(TrianaType source)
Copies modifiable parameters from the given source.
|
int |
countLines(java.lang.String s)
Counts the number of lines in the given String.
|
java.lang.String |
cutGroupString(int index)
Removes and returns the character string denoted by the given character group index.
|
java.lang.String |
cutString(int start,
int end)
Removes and returns the character String between the two given index positions, including the two positions.
|
java.util.ArrayList |
deleteCharGroups()
Removes the current ArrayList of character groups, sets the next one in the stack equal to the current one,
resets the domain pointer to the next one beyond that.
|
void |
deleteLineNumber(int l)
Deletes the line number at the given index location.
|
void |
deleteLineNumbers(int start,
int end)
Deletes the line number range defined by the given index locations.
|
int |
domainOfCharGroup(int cg)
Returns the index of the character group in the domain ArrayList which contains the character group of the
current charGroups ArrayList corresponding to the given index.
|
boolean |
equals(java.lang.Object doc)
Returns true if the specified object doc is the same type and has the same contents as this object,
including the path name and file name.
|
boolean |
existCharGroups()
Tests whether there are non-trivial character group lists, not just the lowest one, which includes all
characters.
|
int |
findNext(java.lang.String text)
Finds the first occurence of the given String in the Document.
|
int |
findNext(java.lang.String text,
int start)
Finds the first occurence of the given String after the given character position in the Document.
|
int |
findNextInGroup(java.lang.String text,
int group)
Finds the first occurence of the given String within the given character group in the Document.
|
int |
findNextInGroup(java.lang.String text,
int group,
int start)
Finds the first occurence of the given String within the given character group after the given location in the
Document.
|
int[] |
getCharGroup(int index)
Gets the integer array for the character group denoted by the given index.
|
java.util.ArrayList |
getCharGroups()
Gets the current ArrayList of the current character groups for this Document.
|
java.util.ArrayList |
getCharGroups(int start,
int end)
Returns an ArrayList of the delimiters of the character groups that are entirely contained within the given index
values.
|
java.util.ArrayList |
getCharGroupsComplement()
Gets an ArrayList of int[2]'s containing the indices of the first and last characters in all parts of the
document text that are not contained in the current charGroups but are contained in the current domain.
|
java.util.ArrayList |
getCharGroupStack()
Gets the whole stack of ArrayLists that denote character groups and their refinements.
|
java.util.ArrayList |
getDomain()
Returns the pointer to the domain, which is the set of character groups just above the current set in the list.
|
java.lang.String |
getFile()
Returns a string representation of the complete path and file name.
|
java.lang.String |
getFileNoPath()
Returns a String representation of the filename not including any path information.
|
FileName |
getFileRef() |
int |
getFileType()
Returns the filetype i.e. LOCAL (i.e. disk file) or HTTP, (on the internet).
|
java.lang.String |
getGroupString(int group)
Returns the substring defined by the character group of the given index.
|
int |
getLineNumber(int n)
Gets the nth interesting line number held for this document.
|
int[] |
getLineNumbers()
Gets the int[] array of line numbers currently held for this Document.
|
java.lang.String |
getPath()
Returns a reference to the path for this file without its filename.
|
java.lang.String |
getString(int start,
int end)
Returns the substring denoted by the given character positions, inclusive.
|
java.lang.String |
getText() |
void |
inputFromStream(java.io.BufferedReader dis)
Used when Triana types want to be able to receive ASCII data from the output of other programs.
|
void |
insertString(java.lang.String insertion,
int location)
Inserts the given character String, starting at the given character index position.
|
void |
insertStringAsCharGroup(java.lang.String insertion,
int location)
Inserts the given character String at the given character index position and marks it as a character group.
|
boolean |
isLineNumber()
Tests whether there are interesting line numbers for this document.
|
boolean |
isTextHTML() |
int |
length() |
java.lang.String |
listCharGroups()
Returns a String containing the character group delimiters for the element of the character group stack at the
current level.
|
java.lang.String |
listCharGroups(int k)
Returns a String containing the character group delimiters for the element of the character group stack denoted
by the given index.
|
java.lang.String |
listGroupStrings()
Returns a String containing the character group delimiters and their associated group Strings at the current
level.
|
java.lang.String |
listGroupStrings(int k)
Returns a String containing the character group delimiters and their associated group Strings at the level given
by the integer argument.
|
java.lang.String |
listGroupStringsNoDelims(int k)
Returns a String containing the character group Strings at the level given by the integer argument.
|
java.lang.String |
listLineNumbers()
Returns a String containing the interesting line numbers, each on a separate line.
|
java.lang.String |
listLineNumbersAndLines()
Returns a String containing the interesting line numbers and their lines, separated by a line-separator
(carriage-return).
|
int |
nextCharGroup(int character)
Returns the index of the first character group that starts at or after the given character position.
|
int |
nextCharGroup(int character,
int firstGroup)
Returns the index of the first character group that starts at or after the given character position, starting the
search of character groups from the given group.
|
int |
nextLineNo(int n)
Returns the index of the next interesting line number held in the array lineNos that is larger than the
given line number, or -1 if there is no interesting line number larger.
|
void |
outputToStream(java.io.PrintWriter dos)
Used when Triana types want to be able to send ASCII data to other programs using strings.
|
int |
prevCharGroup(int character)
Returns the index of the first character group that ends at or before the given character position.
|
int |
prevCharGroup(int character,
int firstGroup)
Returns the index of the first character group that ends at or before the given character position, starting the
search of character groups backwards from the given group.
|
int |
remove(java.lang.String text)
Removes the first occurence of the given String from the Document.
|
int |
remove(java.lang.String text,
int start)
Removes the first occurence of the given String after the given character location in the Document.
|
void |
removeCharGroup(int index)
Deletes the entry for the character group denoted by the given index.
|
void |
removeCharGroups(int start,
int finish)
Deletes the int[2] arrays for all the character groups with index values between the two given values, inclusive.
|
int |
replaceAll(java.lang.String text,
java.lang.String newText)
Replaces all occurences of the given String text with the given String newText.
|
java.lang.String |
replaceGroupString(int index,
java.lang.String replacement)
Replaces the character group with the given index by the given String and returns the String that was removed.
|
int |
replaceNext(java.lang.String text,
java.lang.String newText)
Finds the first occurence of the given String text in the Document and replaces it with the given String
newText.
|
int |
replaceNext(java.lang.String text,
java.lang.String newText,
int start)
Finds the first occurence of the given String text after the given character location in the Document and
replaces it with the given String newText.
|
java.lang.String |
replaceString(int start,
int end,
java.lang.String replacement)
Replaces the characters between the two given positions, inclusive, by the given String and returns the String
that was replaced.
|
void |
setCharGroup(int start,
int end)
Sets a new character group into the ArrayList charGroups.
|
void |
setCharGroups(java.util.ArrayList cg)
Replaces the current ArrayList of interesting character groups with this new one.
|
void |
setFile(FileName fn)
Sets the FileName data object for this Document
|
void |
setFile(java.lang.String pn)
Sets the directory and file name from an input string containing the full path to the file.
|
void |
setLineNumbers(int[] ln)
Sets an int[] array containing interesting line numbers within the file which units can use to display the file
at the appropriate place(s).
|
void |
setText(java.lang.String newContents)
Sets the given String to be the contents of the object and eliminates any character group delimiters because they
are unlikely to be relevant to new text.
|
void |
shiftCharGroups(int shift,
int firstGroup)
Adds the given constant shift to the locations of both delimiters of all the character groups above and
including the given character group.
|
void |
shiftLineNumbers(int shift,
int index)
Adds a given constant shift to the interesting line numbers for this Document above the given index.
|
java.lang.String |
toString()
Provides the toString method for completeness.
|
protected void |
updateObsoletePointers()
Used to make the new types derived from TrianaType backward-compatible with older types.
|
containerSize, dataExists, deleteFromContainer, getDataContainer, getFromContainer, getSequenceNumber, insertIntoContainer, inspectDataContainer, setDataContainer, setSequenceNumber
public Document()
public Document(java.lang.String contents)
contents
- the String containing the contents of the Document.public Document(java.lang.String contents, java.lang.String fileAndPath)
contents
- the String containing the contents of the Document.fileAndPath
- the String containing the full pathname of the file where the Document came from.public Document(java.lang.String contents, FileName file)
contents
- the String containing the contents of the Document.file
- the FileName object containing the file where the Document came from.public Document(java.lang.String contents, java.lang.String file, java.lang.String directory)
contents
- The contents of the Document.file
- The name of the file where the Document came from.directory
- The name of the directory where the Document came from.public java.lang.String getText()
public java.util.ArrayList getCharGroupStack()
public void setText(java.lang.String newContents)
newContents
- A string of the new contentspublic java.lang.String getString(int start, int end)
start
- The location of the first character to be returnedend
- The location of the last character to be returnedpublic java.lang.String cutString(int start, int end)
start
- First character of string to be cutend
- Last character of the string to be cutpublic void insertString(java.lang.String insertion, int location)
insertion
- The character String to be insertedlocation
- Character index of the location of the insertionpublic void add(java.lang.String insertion)
insertion
- the String to be appendedpublic void addLine(java.lang.String text)
text
- the String to be appendedpublic java.lang.String replaceString(int start, int end, java.lang.String replacement)
start
- First character to be replacedend
- Last character to be replacedreplacement
- The string that is to be inserted in place of the cut stringpublic java.lang.String getFile()
public boolean isTextHTML()
public FileName getFileRef()
public java.lang.String getFileNoPath()
public java.lang.String getPath()
public void setLineNumbers(int[] ln)
ln
- the set of line numbers of interestpublic int[] getLineNumbers()
public boolean isLineNumber()
public int getLineNumber(int n)
n
- The index into the line-number arraypublic void addLineNumber(int n)
n
- The line number to be addedpublic void deleteLineNumber(int l)
l
- The index number of the line to be deletedpublic void deleteLineNumbers(int start, int end)
start
- The index number of the first line to be deletedend
- The index number of the last line to be deletedpublic int countLines(java.lang.String s)
s
- The String to be examinedpublic java.lang.String listLineNumbers()
public java.lang.String listLineNumbersAndLines()
public void shiftLineNumbers(int shift, int index)
shift
- The amount by which the line numbers are movedindex
- The first line number to be moved.public int nextLineNo(int n)
n
- The line number where the search startspublic java.util.ArrayList getCharGroups()
public int[] getCharGroup(int index)
index
- the index of the character group being soughtpublic java.util.ArrayList getCharGroups(int start, int end)
start
- The index of the first character in the search intervalend
- The index of the final character in the search intervalpublic java.util.ArrayList getCharGroupsComplement()
public void addCharGroupsLayer(java.util.ArrayList cg)
cg
- the set of integer arrays holding character rangespublic void setCharGroups(java.util.ArrayList cg)
cg
- the set of integer arrays holding character rangespublic boolean existCharGroups()
public void setCharGroup(int start, int end)
start
- the integer beginning the range for this groupend
- the integer ending the range for this grouppublic void removeCharGroup(int index)
index
- the index of the character group being deletedpublic void removeCharGroups(int start, int finish)
start
- the index of the first character group being deletedfinish
- the index of the final character group being deletedpublic java.util.ArrayList deleteCharGroups()
public java.util.ArrayList getDomain()
public void shiftCharGroups(int shift, int firstGroup)
shift
- The amount to increment delimiters of character groupsfirstGroup
- The index of the first group to be shiftedpublic int containedInCharGroup(int character, int firstGroup)
character
- The index in the document of the character being testedfirstGroup
- The index of the character group at which the search startspublic int containedInCharGroup(int character)
character
- The index in the document of the character being testedpublic int nextCharGroup(int character, int firstGroup)
character
- The index in the document of the character being testedfirstGroup
- The index of the character group at which the search startspublic int nextCharGroup(int character)
character
- The index in the document of the character being testedpublic int prevCharGroup(int character, int firstGroup)
character
- The index in the document of the character being testedfirstGroup
- The index of the character group at which the search startspublic int prevCharGroup(int character)
character
- The index in the document of the character being testedpublic int domainOfCharGroup(int cg)
cg
- The index of the character group in the current listpublic java.lang.String getGroupString(int group)
group
- Index of the group to be returnedpublic java.lang.String listCharGroups(int k)
k
- The level in the character group stack to be writtenpublic java.lang.String listCharGroups()
public java.lang.String listGroupStrings(int k)
k
- The level in the character group stack to be writtenpublic java.lang.String listGroupStringsNoDelims(int k)
k
- The level in the character group stack to be writtenpublic java.lang.String listGroupStrings()
public java.lang.String cutGroupString(int index)
index
- Index of the character group to be cutpublic void insertStringAsCharGroup(java.lang.String insertion, int location)
insertion
- The character String to be insertedlocation
- Character index of the location of the insertionpublic java.lang.String replaceGroupString(int index, java.lang.String replacement)
index
- Index of the character group to be replacedreplacement
- The string that is to be inserted in place of the cut stringpublic int getFileType()
FileName
public void setFile(FileName fn)
fn
- The full path to the given filepublic void setFile(java.lang.String pn)
pn
- The full path to the given filepublic int length()
public int findNext(java.lang.String text)
text
- The text to search forpublic int findNext(java.lang.String text, int start)
text
- The text to search forstart
- Index of first character of the searchpublic int findNextInGroup(java.lang.String text, int group)
text
- The text to search forgroup
- Index of character group of the searchpublic int findNextInGroup(java.lang.String text, int group, int start)
text
- The text to search forgroup
- Index of character group of the searchstart
- Index of the first character of the searchpublic int remove(java.lang.String text)
text
- The text to search forpublic int remove(java.lang.String text, int start)
text
- The text to search forpublic int replaceNext(java.lang.String text, java.lang.String newText)
text
- The text to search fornewText
- The text to insert in place of textpublic int replaceNext(java.lang.String text, java.lang.String newText, int start)
text
- The text to search fornewText
- The text to insert in place of textpublic int replaceAll(java.lang.String text, java.lang.String newText)
text
- The text to search fornewText
- The text to insert in place of textpublic boolean equals(java.lang.Object doc)
equals
in class java.lang.Object
public TrianaType copyMe()
To override, the programmer should not invoke the super.copyMe method. Instead, create an object of the current type and call methods copyData and copyParameters. If these have been written correctly, then they will do the copying. The code should createTool, for type YourType:
YourType y = null; try { y = (YourType)getClass().newInstance(); y.copyData( this ); y.copyParameters( this ); y.setLegend( this.getLegend() ); } catch (IllegalAccessException ee) { System.out.println("Illegal Access: " + ee.getMessage()); } catch (InstantiationException ee) { System.out.println("Couldn't be instantiated: " + ee.getMessage()); } return y;
The copied object's data should be identical to the original. The method here modifies only one item: a String indicating that the object was created as a copy is added to the description StringVector.
copyMe
in class TrianaType
public void copyData(TrianaType source)
copyData
in class TrianaType
source
- The Document object being copiedpublic void copyParameters(TrianaType source)
copyParameters
in class TrianaType
source
- The Document object being copiedpublic void outputToStream(java.io.PrintWriter dos) throws java.io.IOException
This method must be overridden in every subclass that defines new data or parameters. The overriding method should first call<
super.outputToStream(dos)to get output from superior classes, and then new parameters defined for the current subclass must be output. Moreover, subclasses that first dimension their data arrays must explicitly transfer these data arrays.
outputToStream
in interface AsciiComm
dos
- The data output streamjava.io.IOException
public void inputFromStream(java.io.BufferedReader dis) throws java.io.IOException
This method must be overridden in every subclass that defines new data or parameters. The overriding method should first call
super.inputFromStream(dis)to get input from superior classes, and then new parameters defined for the current subclass must be input. Moreover, subclasses that first dimension their data arrays must explicitly transfer these data arrays.
inputFromStream
in interface AsciiComm
dis
- The data input streamjava.io.IOException
protected void updateObsoletePointers()
super.updateObsoletePointers;
updateObsoletePointers
in class TrianaType
public java.lang.String toString()
toString
in class java.lang.Object