Class XMLBranchEvent

java.lang.Object
com.topologi.diffx.event.impl.DiffXEventBase
com.topologi.diffx.event.impl.XMLBranchEvent
All Implemented Interfaces:
DiffXEvent, XMLFormattable, XMLWritable

public final class XMLBranchEvent extends DiffXEventBase implements DiffXEvent
A branch of XML data.

A branch of XML data must start and end with the same element.

Implementation note: this class wraps an array of DiffX events and does not give access to this array, so it can be considered immutable.

Version:
27 March 2010
  • Field Details

    • branch

      private final DiffXEvent[] branch
      The array of Diff-X events that make up the branch.
    • hashCode

      private final int hashCode
      Pre-calculated hashcode to speed up equal comparison.
  • Constructor Details

    • XMLBranchEvent

      public XMLBranchEvent(DiffXEvent[] events)
      Creates a new XML branch.
      Parameters:
      events - The array of events that make up the branch.
  • Method Details

    • hashCode

      public int hashCode()
      Description copied from class: DiffXEventBase
      Specified by:
      hashCode in class DiffXEventBase
    • equals

      public boolean equals(DiffXEvent e)
      Returns true if the diffX events in the branch are all equal. Indicates whether the specified event is equal to this event.
      Specified by:
      equals in interface DiffXEvent
      Specified by:
      equals in class DiffXEventBase
      Parameters:
      e - The event to compare it with thsi one.
      Returns:
      true if considered equals; false otherwise.
    • toXML

      public void toXML(XMLWriter xml) throws IOException
      Write the DiffX events in order. Writes the XML representation of the implementing instance using the specified XMLWriter.
      Specified by:
      toXML in interface XMLWritable
      Parameters:
      xml - The XMLWriter to use.
      Throws:
      IOException - IF an I/O exception occurs whilst writing.
    • toXML

      public StringBuffer toXML(StringBuffer xml) throws NullPointerException
      Description copied from interface: XMLFormattable
      Appends the XML representation of the object of the implementing class.

      Implementations must ensure that the returned string buffer is the same object as the specified string buffer.

      Specified by:
      toXML in interface XMLFormattable
      Parameters:
      xml - The string buffer to which the XML representation is appended to.
      Returns:
      The modified string buffer.
      Throws:
      NullPointerException - if the specified character sequence is null.
    • toHashCode

      private static int toHashCode(DiffXEvent[] events)
      Calculates the hashcode for this event.
      Parameters:
      events - Events to calculate the value from.
      Returns:
      a number suitable as a hashcode.