mjc

org.multijava.util.testing
Class Diff

java.lang.Object
  extended byorg.multijava.util.testing.Diff

public class Diff
extends Object

Class for calculating a (somewhat) detailed comparison of two strings.

Version:
$Revision: 1.9 $
Author:
Curtis Clifton

Field Summary
private  boolean areDifferent
           
private static String DELIM
           
private  Pattern equivChars
           
private  String equivReplaceChar
           
private static String IGNORED_CHARS_FILLER
           
private static String NEW_CH
           
private static String NEWLINE
           
private  String newText
           
private static String OLD_CH
           
private  String oldText
           
private  Pattern regExpr
           
private  String result
           
 
Constructor Summary
Diff(String oldTextLabel, String oldText, String newTextLabel, String newText)
          Calculate a difference between the given strings.
Diff(String oldTextLabel, String oldText, String newTextLabel, String newText, Pattern regExpr)
          Calculate a difference between the given strings ignoring the portions of each line that match the given regular expression pattern.
Diff(String oldTextLabel, String oldText, String newTextLabel, String newText, Pattern regExpr, String equivChars)
          Calculate a difference between the given strings ignoring the portions of each line that match the given regular expression pattern, and treating any character from the equivChars String as equal.
 
Method Summary
 boolean areDifferent()
          Returns true if strings on which this was constructed are different.
private  boolean areSame(String a, String b)
           
private  void calculate(String oldTextLabel, String newTextLabel)
           
private  String replaceChars(String s)
           
 String result()
          Returns the differences between the given strings.
private  String[] splitByLine(String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oldText

private final String oldText

newText

private final String newText

regExpr

private final Pattern regExpr

equivChars

private final Pattern equivChars

equivReplaceChar

private final String equivReplaceChar

areDifferent

private boolean areDifferent

result

private String result

DELIM

private static final String DELIM

NEWLINE

private static final String NEWLINE

OLD_CH

private static final String OLD_CH

NEW_CH

private static final String NEW_CH

IGNORED_CHARS_FILLER

private static final String IGNORED_CHARS_FILLER
Constructor Detail

Diff

public Diff(String oldTextLabel,
            String oldText,
            String newTextLabel,
            String newText)
Calculate a difference between the given strings.

Parameters:
oldTextLabel - a label for the oldText parameter
oldText - a value to be compared
newTextLabel - a label for the newText parameter
newText - a value to be compared

Diff

public Diff(String oldTextLabel,
            String oldText,
            String newTextLabel,
            String newText,
            Pattern regExpr)
Calculate a difference between the given strings ignoring the portions of each line that match the given regular expression pattern.

Parameters:
oldTextLabel - a label for the oldText parameter
oldText - a value to be compared
newTextLabel - a label for the newText parameter
newText - a value to be compared
regExpr - a regular expression, matches of which are removed from lines before comparison

Diff

public Diff(String oldTextLabel,
            String oldText,
            String newTextLabel,
            String newText,
            Pattern regExpr,
            String equivChars)
Calculate a difference between the given strings ignoring the portions of each line that match the given regular expression pattern, and treating any character from the equivChars String as equal.

Parameters:
oldTextLabel - a label for the oldText parameter
oldText - a value to be compared
newTextLabel - a label for the newText parameter
newText - a value to be compared
regExpr - a regular expression, matches of which are removed from lines before comparison
equivChars - a string whose characters are considered equivalent for comparison purposes
Method Detail

areSame

private boolean areSame(String a,
                        String b)

replaceChars

private String replaceChars(String s)

calculate

private void calculate(String oldTextLabel,
                       String newTextLabel)

splitByLine

private String[] splitByLine(String text)

areDifferent

public boolean areDifferent()
Returns true if strings on which this was constructed are different.


result

public String result()
Returns the differences between the given strings.


 ensures !areDifferent() <==> \result.equals( "" );
 


mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.