com.topologi.diffx.sequence
Class SequenceSlicer

java.lang.Object
  extended by com.topologi.diffx.sequence.SequenceSlicer

public final class SequenceSlicer
extends Object

The slicer takes two sequences and removes the common elements from the beginning and the end of the chain so that only the smallest sequences are passed to the DiffXAlgorithmBase.

The slice does modify the original sequences.

Note: Using this class may lead to problems in the execution of the Diff-X algorithm and incorrect results, because it could potentially take off some parts that helps the Diff-X algorithm ensuring that the XML is well-formed.

Version:
15 January 2007
Author:
Christophe Lauret

Constructor Summary
SequenceSlicer(EventSequence seq0, EventSequence seq1)
          Creates a new sequence slicer.
 
Method Summary
 void formatEnd(DiffXFormatter formatter)
          Formats the end subsequence that has been buffered by this class.
 void formatStart(DiffXFormatter formatter)
          Formats the start subsequence that has been buffered by this class.
 EventSequence getEnd()
          Returns the current end sequence buffer.
 EventSequence getStart()
          Returns the current start sequence buffer.
 void slice()
          Slices the start and end of both sequences.
 int sliceEnd()
          Slices the end of both sequences.
 int sliceStart()
          Slices the start of both sequences.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceSlicer

public SequenceSlicer(EventSequence seq0,
                      EventSequence seq1)
Creates a new sequence slicer.

Parameters:
seq0 - The first sequence to slice.
seq1 - The second sequence to slice.
Method Detail

slice

public void slice()
           throws IllegalStateException
Slices the start and end of both sequences.

Equivalent to successive calls to sliceStart() and sliceEnd().

Throws:
IllegalStateException - If the start buffer is not empty.

sliceStart

public int sliceStart()
               throws IllegalStateException
Slices the start of both sequences.

The common start sequence will be stored in the class until the next formatStart(DiffXFormatter) is called.

Returns:
The number of common elements at the start of the sequences.
Throws:
IllegalStateException - If the start buffer is not empty.

sliceEnd

public int sliceEnd()
             throws IllegalStateException
Slices the end of both sequences.

The common end sequence will be stored in the class until the next formatEnd(DiffXFormatter) is called.

Returns:
The number of common elements at the end of the sequences.
Throws:
IllegalStateException - If the end buffer is not empty.

formatStart

public void formatStart(DiffXFormatter formatter)
                 throws NullPointerException,
                        IOException
Formats the start subsequence that has been buffered by this class.

This method will clear the buffer, but will do nothing if the start buffer is null.

Parameters:
formatter - The formatter that will handle the output.
Throws:
NullPointerException - If the specified formatter is null.
IOException - If an error occurs whilst writing with the formatter.

formatEnd

public void formatEnd(DiffXFormatter formatter)
               throws NullPointerException,
                      IOException
Formats the end subsequence that has been buffered by this class.

This method will clear the buffer, but will do nothing if the end buffer is null.

Parameters:
formatter - The formatter that will handle the output.
Throws:
NullPointerException - If the specified formatter is null.
IOException - If an error occurs whilst writing with the formatter.

getStart

public EventSequence getStart()
Returns the current start sequence buffer.

Returns:
The current start sequence buffer or null if none.

getEnd

public EventSequence getEnd()
Returns the current end sequence buffer.

Returns:
The current end sequence buffer or null if none.