org.apache.commons.jrcs.rcs
Class Node

java.lang.Object
  extended by org.apache.commons.jrcs.util.ToString
      extended by org.apache.commons.jrcs.rcs.Node
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
BranchNode, TrunkNode

public abstract class Node
extends ToString
implements java.lang.Comparable

Ancestor to all nodes in a version control Archive.

Nodes store the deltas between two revisions of the text.

This class is NOT thread safe.

Version:
$Id: Node.java,v 1.5 2003/10/13 07:59:46 rdonkin Exp $
Author:
Juanco Anez
See Also:
TrunkNode, BranchNode, Archive

Field Summary
protected  java.lang.String author
           
protected  java.util.TreeMap branches
           
protected  Node child
           
protected  java.util.Date date
           
protected static java.text.DateFormat dateFormat
           
protected static java.text.DateFormat dateFormat2K
           
protected static java.text.Format dateFormatter
           
protected  boolean endWithNewLine
           
protected  java.lang.String locker
           
protected  java.lang.String log
           
protected  Node parent
           
protected  Phrases phrases
           
protected  Node rcsnext
           
protected  java.lang.String state
           
protected  java.lang.Object[] text
           
protected  Version version
          The version number for this node.
 
Constructor Summary
protected Node(Node other)
          Creates a copy of a node.
protected Node(Version vernum, Node rcsnext)
          Creates a node with the given version number.
 
Method Summary
 void addBranch(BranchNode node)
          Adds a branch node to the current node.
 int compareTo(java.lang.Object other)
          Compares the version number of this node to that of another node.
abstract  Node deltaRevision()
          Returns the Node with the version number that corresponds to the revision to be obtained after the deltas in the current node are applied.
 java.lang.String getAuthor()
           
 BranchNode getBranch(int no)
          Retrieve the branch node identified with the given numer.
 java.util.TreeMap getBranches()
           
 Node getChild()
           
 java.util.Date getDate()
           
 java.lang.String getLocker()
           
 java.lang.String getLog()
           
 Node getParent()
           
 Phrases getPhrases()
           
 Node getRCSNext()
          Return the next node in the RCS logical hierarchy.
 java.lang.String getState()
           
 java.lang.Object[] getText()
           
 java.util.List getTextLines()
          Return a list with the lines of the node's text.
 java.util.List getTextLines(int from, int to)
          Return a list with a subset of the lines of the node's text.
 java.util.List getTextLines(java.util.List lines)
          Add a subset of the lines of the node's text to the given list.
 java.util.List getTextLines(java.util.List lines, int from, int to)
          Add a subset of the lines of the node's text to the given list.
 Version getVersion()
           
 boolean isGhost()
          Returns true if the node is a "ghost" node.
 Version newBranchVersion()
          Returns the version number that should correspond to a newly created branch of this node.
(package private) static Node newNode(Version vernum)
          Creates a new node of the adequate type for the given version number.
(package private) static Node newNode(Version vernum, Node rcsnext)
          Creates a new node of the adequate type for the given version number.
(package private)  void newpatch(java.util.List original, boolean annotate, Node root)
           
abstract  Node nextInPathTo(Version vernum, boolean soft)
          Returns the next node in the path from the current node to the node identified by the given version.
 Version nextVersion()
          Returns the version number that should correspond to the revision folowing this node.
 void patch(java.util.List original)
          Apply the deltas in the current node to the given text.
 void patch(java.util.List original, boolean annotate)
          Apply the deltas in the current node to the given text.
 Path pathTo(Version vernum)
          Returns the path from the current node to the node identified by the given version.
 Path pathTo(Version vernum, boolean soft)
          Returns the path from the current node to the node identified by the given version.
 Node root()
          Return the root node of the node hierarchy.
 void setAuthor(java.lang.String user)
          Set the author of the node's revision.
 void setDate(int[] value)
          Set the date of the node's revision.
 void setLocker(java.lang.String user)
          Set the locker.
 void setLog(java.lang.String value)
          Sets the log message for the node's revision.
 void setRCSNext(Node node)
          Sets the next node in the RCS logical hierarchy.
 void setState(java.lang.String value)
          Sets the state of the node's revision.
 void setText(java.lang.Object[] value)
          Sets the text for the node's revision.
 void setText(java.lang.String value)
          Sets the text for the node's revision.
 void toString(java.lang.StringBuffer s)
          Conver the current node and all of its branches to their RCS string representation and add it to the given StringBuffer.
 void toString(java.lang.StringBuffer s, java.lang.String EOL)
          Conver the current node and all of its branches to their RCS string representation and add it to the given StringBuffer using the given marker as line separator.
 java.lang.String toText()
          Conver the urrent node to its RCS string representation.
 void toText(java.lang.StringBuffer s, java.lang.String EOL)
          Conver the urrent node to its RCS string representation and add it to the given StringBuffer using the given marker as line separator.
 
Methods inherited from class org.apache.commons.jrcs.util.ToString
arrayToString, arrayToString, stringToArray, stringToArraya, stringToArrayold, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

version

protected final Version version
The version number for this node.


date

protected java.util.Date date

author

protected java.lang.String author

state

protected java.lang.String state

log

protected java.lang.String log

locker

protected java.lang.String locker

text

protected java.lang.Object[] text

rcsnext

protected Node rcsnext

parent

protected Node parent

child

protected Node child

branches

protected java.util.TreeMap branches

phrases

protected Phrases phrases

endWithNewLine

protected boolean endWithNewLine

dateFormatter

protected static final java.text.Format dateFormatter

dateFormat

protected static final java.text.DateFormat dateFormat

dateFormat2K

protected static final java.text.DateFormat dateFormat2K
Constructor Detail

Node

protected Node(Node other)
Creates a copy of a node. Only used internally.

Parameters:
other - The node to copy.

Node

protected Node(Version vernum,
               Node rcsnext)
Creates a node with the given version number.

Parameters:
vernum - The version number for the node.
rcsnext - The next node in the RCS logical hierarchy.
Method Detail

newNode

static Node newNode(Version vernum,
                    Node rcsnext)
             throws InvalidVersionNumberException
Creates a new node of the adequate type for the given version number.

Parameters:
vernum - The version number for the node.
rcsnext - The next node in the RCS logical hierarchy.
Returns:
The newly created node.
Throws:
InvalidVersionNumberException

newNode

static Node newNode(Version vernum)
             throws InvalidVersionNumberException
Creates a new node of the adequate type for the given version number.

Parameters:
vernum - The version number for the node.
Returns:
The newly created node.
Throws:
InvalidVersionNumberException

compareTo

public int compareTo(java.lang.Object other)
Compares the version number of this node to that of another node.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - The node to compare two.
Returns:
0 if versions are equal, 1 if this version greather than the other, and -1 otherwise.

isGhost

public boolean isGhost()
Returns true if the node is a "ghost" node. Ghost nodes have no associated text ot deltas. CVS uses them to mark certain points in the node hierarchy.


getBranch

public BranchNode getBranch(int no)
Retrieve the branch node identified with the given numer.

Parameters:
no - The branch number.
Returns:
The branch node.
See Also:
BranchNode

root

public Node root()
Return the root node of the node hierarchy.

Returns:
The root node.

setLocker

public void setLocker(java.lang.String user)
Set the locker.

Parameters:
user - A symbol that identifies the locker.

setAuthor

public void setAuthor(java.lang.String user)
Set the author of the node's revision.

Parameters:
user - A symbol that identifies the author.

setDate

public void setDate(int[] value)
Set the date of the node's revision.

Parameters:
value - an array of 6 integers, corresponding to the year, month, day, hour, minute, and second of this revision.
If the year has two digits, it is interpreted as belonging to the 20th century.
The month is a number from 1 to 12.

setState

public void setState(java.lang.String value)
Sets the state of the node's revision.

Parameters:
value - A symbol that identifies the state. The most commonly used value is Exp.

setRCSNext

public void setRCSNext(Node node)
Sets the next node in the RCS logical hierarchy. In the RCS hierarchy, a TrunkNode points to the previous revision, while a BranchNode points to the next revision.

Parameters:
node - The next node in the RCS logical hierarchy.

setLog

public void setLog(java.lang.String value)
Sets the log message for the node's revision. The log message is usually used to explain why the revision took place.

Parameters:
value - The message.

setText

public void setText(java.lang.String value)
Sets the text for the node's revision.

For archives containing binary information, the text is an image of the revision contents.

For ASCII archives, the text contains the delta between the current revision and the next revision in the RCS logical hierarchy. The deltas are codified in a format similar to the one used by Unix diff.

The passed string is converted to an array of objects befored being stored as the revision's text

Parameters:
value - The revision's text.
See Also:
ArchiveParser

setText

public void setText(java.lang.Object[] value)
Sets the text for the node's revision.

For archives containing binary information, the text is an image of the revision contents.

For ASCII archives, the text contains the delta between the current revision and the next revision in the RCS logical hierarchy. The deltas are codified in a format similar to the one used by Unix diff.

Parameters:
value - The revision's text.
See Also:
ArchiveParser

addBranch

public void addBranch(BranchNode node)
               throws InvalidVersionNumberException
Adds a branch node to the current node.

Parameters:
node - The branch node.
Throws:
InvalidVersionNumberException - if the version number is not a valid branch version number for the current node

nextVersion

public Version nextVersion()
Returns the version number that should correspond to the revision folowing this node.

Returns:
The next version number.

newBranchVersion

public Version newBranchVersion()
Returns the version number that should correspond to a newly created branch of this node.

Returns:
the new branch's version number.

getRCSNext

public Node getRCSNext()
Return the next node in the RCS logical hierarchy.

Returns:
the next node

pathTo

public Path pathTo(Version vernum)
            throws NodeNotFoundException
Returns the path from the current node to the node identified by the given version.

Parameters:
vernum - The version number of the last node in the path.
Returns:
The path
Throws:
NodeNotFoundException - if a node with the given version number doesn't exist, or is not reachable following the RCS-next chain from this node.
See Also:
Path

pathTo

public Path pathTo(Version vernum,
                   boolean soft)
            throws NodeNotFoundException
Returns the path from the current node to the node identified by the given version.

Parameters:
vernum - The version number of the last node in the path.
soft - If true, no error is thrown if a node with the given version doesn't exist. Use soft=true to find a apth to where a new node should be added.
Returns:
The path
Throws:
NodeNotFoundException - if a node with the given version number is not reachable following the RCS-next chain from this node. If soft=false the exception is also thrown if a node with the given version number doesn't exist.
See Also:
Path

nextInPathTo

public abstract Node nextInPathTo(Version vernum,
                                  boolean soft)
                           throws NodeNotFoundException
Returns the next node in the path from the current node to the node identified by the given version.

Parameters:
vernum - The version number of the last node in the path.
soft - If true, no error is thrown if a node with the given version doesn't exist. Use soft=true to find a apth to where a new node should be added.
Returns:
The path
Throws:
NodeNotFoundException - if a node with the given version number is not reachable following the RCS-next chain from this node. If soft=false the exception is also thrown if a node with the given version number doesn't exist.
See Also:
Path

deltaRevision

public abstract Node deltaRevision()
Returns the Node with the version number that corresponds to the revision to be obtained after the deltas in the current node are applied.

For a BranchNode the deltaRevision is the current revision; that is, after the deltas are applied, the text for the current revision is obtained.

For a TrunkNode the deltaRevision is the next revision; that is, after the deltas are applied, the text obtained corresponds to the next revision in the chain.

Returns:
The node for the delta revision.

patch

public void patch(java.util.List original)
           throws InvalidFileFormatException,
                  PatchFailedException
Apply the deltas in the current node to the given text.

Parameters:
original - the text to be patched
Throws:
InvalidFileFormatException - if the deltas cannot be parsed.
PatchFailedException - if the diff engine determines that the deltas cannot apply to the given text.

patch

public void patch(java.util.List original,
                  boolean annotate)
           throws InvalidFileFormatException,
                  PatchFailedException
Apply the deltas in the current node to the given text.

Parameters:
original - the text to be patched
annotate - set to true to have each text line be a Line object that identifies the revision in which the line was changed or added.
Throws:
InvalidFileFormatException - if the deltas cannot be parsed.
PatchFailedException - if the diff engine determines that the deltas cannot apply to the given text.

newpatch

void newpatch(java.util.List original,
              boolean annotate,
              Node root)
        throws InvalidFileFormatException
Throws:
InvalidFileFormatException

toString

public void toString(java.lang.StringBuffer s)
Conver the current node and all of its branches to their RCS string representation and add it to the given StringBuffer.

Overrides:
toString in class ToString
Parameters:
s - The string buffer to add the node's image to.

toString

public void toString(java.lang.StringBuffer s,
                     java.lang.String EOL)
Conver the current node and all of its branches to their RCS string representation and add it to the given StringBuffer using the given marker as line separator.

Parameters:
s - The string buffer to add the node's image to.
EOL - The line separator to use.

toText

public java.lang.String toText()
Conver the urrent node to its RCS string representation.

Returns:
The string representation

toText

public void toText(java.lang.StringBuffer s,
                   java.lang.String EOL)
Conver the urrent node to its RCS string representation and add it to the given StringBuffer using the given marker as line separator.

Parameters:
s - The string buffer to add the node's image to.
EOL - The line separator to use.

getTextLines

public java.util.List getTextLines()
Return a list with the lines of the node's text.

Returns:
The list

getTextLines

public java.util.List getTextLines(int from,
                                   int to)
Return a list with a subset of the lines of the node's text.

Parameters:
from - The offset of the first line to retrieve.
to - The offset of the line after the last one to retrieve.
Returns:
The list

getTextLines

public java.util.List getTextLines(java.util.List lines)
Add a subset of the lines of the node's text to the given list.

Returns:
The given list after the additions have been made.

getTextLines

public java.util.List getTextLines(java.util.List lines,
                                   int from,
                                   int to)
Add a subset of the lines of the node's text to the given list.

Parameters:
from - The offset of the first line to retrieve.
to - The offset of the line after the last one to retrieve.
Returns:
The given list after the additions have been made.

getDate

public final java.util.Date getDate()

getAuthor

public final java.lang.String getAuthor()

getState

public final java.lang.String getState()

getLog

public final java.lang.String getLog()

getLocker

public final java.lang.String getLocker()

getText

public final java.lang.Object[] getText()

getChild

public final Node getChild()

getBranches

public final java.util.TreeMap getBranches()

getParent

public final Node getParent()

getVersion

public final Version getVersion()

getPhrases

public Phrases getPhrases()


Copyright 2002 the Apache Software Foundation
Copyright ? 1999-2001 Juancarlo A?ez, Caracas, Venezuela.
All rights reserved
. http://www.suigeneris.org/jrcs