Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This file is part of the DiffX library.
   *
   * For licensing information please see the file license.txt included in the release.
   * A copy of this licence can also be found at
   *   http://www.opensource.org/licenses/artistic-license-2.0.php
   */
  package com.topologi.diffx.config;

The configuration to use with a DiffX operation.

This class acts as a container for a set of properties that can be applied to the main components of Diff-X such as the:

In order to produce the correct results, the configuration must be applied throughout the three steps of processing.

There is an illegal state in this configuration, if the the diffx is not namespace aware it cannot not report the differences in the prefixes. Therefore it is impossible to set both flags to false.

The set methods for those flags will ensure that this situation does not occur. The general rule is that the flag being set takes precedence.

Note that it simply mimics SAX2 which cannot have the features http://xml.org/sax/features/namespaces and http://xml.org/sax/features/namespace-prefixes both set to false.

 
 public final class DiffXConfig {

  
Indicates whether the namespaces should be handled or ignored.
 
   private boolean isNamespaceAware = true;

  
Indicates whether difference in prefixes should be reported.
 
   private boolean reportPrefixDifferences = false;

  
Defines the whitespace for this configuration.
 
Required for backward compatibility only.
 
   private boolean preserveWhiteSpace = true;

  
Defines the text granularity for this configuration.
 
Creates a new configuration for Diff-X.
 
   public DiffXConfig() {
   }

  
Creates a new configuration for Diff-X.

Parameters:
granularity The granularity of text diffing.
 
   public DiffXConfig(TextGranularity granularity) {
     if (granularity == null)
       throw new NullPointerException("The granularity cannot be configured to be not be null.");
     this. = granularity;
   }

  
Creates a new configuration for Diff-X.

Parameters:
whitespace How whitespace should be processed.
granularity The granularity of text diffing.
 
   public DiffXConfig(WhiteSpaceProcessing whitespaceTextGranularity granularity) {
     if (granularity == null)
       throw new NullPointerException("The granularity cannot be configured to be not be null.");
     if (whitespace == null)
       throw new NullPointerException("The whitespace processing cannot be configured to be not be null.");
     this. = granularity;
     this. = whitespace;
  }
  // methods ----------------------------------------------------------------------------------------

  
Sets the granularity of text diffing for this configuration.

Parameters:
granularity the text granularity of text diffing for this configuration.
  public void setGranularity(TextGranularity granularity) {
    if (granularity == null)
      throw new NullPointerException("The granularity cannot be configured to be not be null.");
    this. = granularity;
  }

  
Sets the white space processing for this configuration.

Parameters:
whitespace the white space processing for this configuration.
  public void setWhiteSpaceProcessing(WhiteSpaceProcessing whitespace) {
    if (whitespace == null)
      throw new NullPointerException("The whitespace cannot be configured to be not be null.");
    this. = whitespace;
  }

  
Sets whether Diff-X should take namespaces into account.

It is more efficient to disable namespace processing when the XML to compare are not expected to use any namespace.

In order to avoid an illegal state, if this flag is set to false and the differences in prefixes will be automatically reported.

Parameters:
aware true to preserve the white spaces; false otherwise.
  public void setNamespaceAware(boolean aware) {
    this. = aware;
    if (!aware) {
      this. = true;
    }
  }

  
Sets whether the Diff-X should report differences in prefixes.

In order to avoid an illegal state, if this flag is set to false and then the processor becomes namespace aware.

Parameters:
report true to report differences in prefixes; false to ignore them.
  public void setReportPrefixDifferences(boolean report) {
    this. = report;
    if (!report) {
      this. = true;
    }
  }

  
Indicates whether the Diff-X takes namespaces into account.

Returns:
true to preserve the white spaces; false otherwise.
  public boolean isNamespaceAware() {
    return this.;
  }

  
Returns whether the differences in prefixes are reported.

Returns:
true to report differences in prefixes; false to ignore them.
  public boolean isReportPrefixDifferences() {
    return this.;
  }

  
Returns the granularity of text diffing for this configuration.

Returns:
the text granularity of text diffing for this configuration.
    return this.;
  }

  
Returns the granularity of text diffing for this configuration.

Returns:
the text granularity of text diffing for this configuration.
    return this.;
  }

  
Indicates whether the differences in white spaces should be ignored or not.

Returns:
true to ignore differences in white spaces; false otherwise.
  public boolean isIgnoreWhiteSpace() {
    return this. != .;
  }

  
Indicates whether the white spaces are preserved or not.

Returns:
true to preserve the white spaces; false otherwise.
  public boolean isPreserveWhiteSpace() {
    return this.;
  }
  // deprecated methods ---------------------------------------------------------------------------

  
Sets whether the differences in white spaces should be ignored or not.

Deprecated:
use setWhiteSpaceProcessing instead
Parameters:
ignore true to ignore differences in white spaces; false otherwise.
  public void setIgnoreWhiteSpace(boolean ignore) {
    // COMPARE  <-> ignore = false, preserve = true/false
    // PRESERVE <-> ignore = true, preserve = true
    // IGNORE   <-> ignore = true, preserve = false
    if (!ignore) {
    } else {
    }
  }

  
Sets whether the white spaces should be preserved or not.

Deprecated:
use setWhiteSpaceProcessing instead
Parameters:
preserve true to preserve the white spaces; false otherwise.
  public void setPreserveWhiteSpace(boolean preserve) {
    // COMPARE  <-> ignore = false, preserve = true/false
    // PRESERVE <-> ignore = true, preserve = true
    // IGNORE   <-> ignore = true, preserve = false
    this. = preserve;
    if (this. != .) {
    }
  }
New to GrepCode? Check out our FAQ X