Package org.apache.wicket.util.diff
Class Diff
- java.lang.Object
-
- org.apache.wicket.util.diff.ToString
-
- org.apache.wicket.util.diff.Diff
-
public class Diff extends ToString
Implements a differencing engine that works on arrays ofObject.Within this library, the word text means a unit of information subject to version control.
Text is represented as
Object[]because the diff engine is capable of handling more than plain ascci. In fact, arrays of any type that implementshashCode()andequals()correctly can be subject to differencing using this library.This library provides a framework in which different differencing algorithms may be used. If no algorithm is specified, a default algorithm is used.
- Version:
- $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
- Author:
- Juanco Anez
- See Also:
Delta,modifications: 27 Apr 2003 bwm Added some comments whilst trying to figure out the algorithm 03 May 2003 bwm Factored out the algorithm implementation into a separate difference algorithm class to allow pluggable algorithms.
-
-
Constructor Summary
Constructors Constructor Description Diff(Object[] original)Create a differencing object using the default algorithmDiff(Object[] original, DiffAlgorithm algorithm)Create a differencing object using the given algorithm
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringarrayToString(Object[] o)static booleancompare(Object[] orig, Object[] rev)Compares the two input sequences.protected DiffAlgorithmdefaultAlgorithm()Revisiondiff(Object[] rev)compute the difference between the original and a revision.static Revisiondiff(Object[] orig, Object[] rev)compute the difference between an original and a revision.static Revisiondiff(Object[] orig, Object[] rev, DiffAlgorithm algorithm)compute the difference between an original and a revision.static Object[]editAll(Object[] text)Edits all of the items in the input sequence.static Object[]randomEdit(Object[] text)Performs random edits on the input sequence.static Object[]randomEdit(Object[] text, long seed)Performs random edits on the input sequence.static Object[]randomSequence(int size)Generate a random sequence of the given size.static Object[]randomSequence(int size, long seed)Generate a random sequence of the given size.static Object[]shuffle(Object[] text)Shuffles around the items in the input sequence.static Object[]shuffle(Object[] text, long seed)Shuffles around the items in the input sequence.-
Methods inherited from class org.apache.wicket.util.diff.ToString
arrayToString, stringToArray, toString, toString
-
-
-
-
Field Detail
-
RCS_EOL
public static final String RCS_EOL
The line separator to use in RCS format output.- See Also:
- Constant Field Values
-
algorithm
protected DiffAlgorithm algorithm
The differencing algorithm to use.
-
-
Constructor Detail
-
Diff
public Diff(Object[] original)
Create a differencing object using the default algorithm- Parameters:
original- the original text that will be compared
-
Diff
public Diff(Object[] original, DiffAlgorithm algorithm)
Create a differencing object using the given algorithm- Parameters:
original- the original text that will be comparedalgorithm- the difference algorithm to use.
-
-
Method Detail
-
defaultAlgorithm
protected DiffAlgorithm defaultAlgorithm()
-
diff
public static Revision diff(Object[] orig, Object[] rev) throws DifferentiationFailedException
compute the difference between an original and a revision.- Parameters:
orig- the originalrev- the revision to compare with the original.- Returns:
- a Revision describing the differences
- Throws:
DifferentiationFailedException
-
diff
public static Revision diff(Object[] orig, Object[] rev, DiffAlgorithm algorithm) throws DifferentiationFailedException
compute the difference between an original and a revision.- Parameters:
orig- the originalrev- the revision to compare with the original.algorithm- the difference algorithm to use- Returns:
- a Revision describing the differences
- Throws:
DifferentiationFailedException
-
diff
public Revision diff(Object[] rev) throws DifferentiationFailedException
compute the difference between the original and a revision.- Parameters:
rev- the revision to compare with the original.- Returns:
- a Revision describing the differences
- Throws:
DifferentiationFailedException
-
compare
public static boolean compare(Object[] orig, Object[] rev)
Compares the two input sequences.- Parameters:
orig- The original sequence.rev- The revised sequence.- Returns:
- true if the sequences are identical. False otherwise.
-
arrayToString
public static String arrayToString(Object[] o)
- Parameters:
o- the array of objects.- Returns:
- String
-
editAll
public static Object[] editAll(Object[] text)
Edits all of the items in the input sequence.- Parameters:
text- The input sequence.- Returns:
- A sequence of the same length with all the lines differing from the corresponding ones in the input.
-
randomEdit
public static Object[] randomEdit(Object[] text)
Performs random edits on the input sequence. Useful for testing.- Parameters:
text- The input sequence.- Returns:
- The sequence with random edits performed.
-
randomEdit
public static Object[] randomEdit(Object[] text, long seed)
Performs random edits on the input sequence. Useful for testing.- Parameters:
text- The input sequence.seed- A seed value for the randomizer.- Returns:
- The sequence with random edits performed.
-
shuffle
public static Object[] shuffle(Object[] text)
Shuffles around the items in the input sequence.- Parameters:
text- the input sequence.- Returns:
- The shuffled sequence.
-
shuffle
public static Object[] shuffle(Object[] text, long seed)
Shuffles around the items in the input sequence.- Parameters:
text- the input sequence.seed- a seed value for randomizing the generation.- Returns:
- The shuffled sequence.
-
randomSequence
public static Object[] randomSequence(int size)
Generate a random sequence of the given size.- Parameters:
size- the size of the sequence to generate.- Returns:
- The generated sequence.
-
randomSequence
public static Object[] randomSequence(int size, long seed)
Generate a random sequence of the given size.- Parameters:
size- the size of the sequence to generate.seed- a seed value for randomizing the generation.- Returns:
- The generated sequence.
-
-