com.topologi.diffx.event.impl
Class CharactersEventBase

java.lang.Object
  extended by com.topologi.diffx.event.impl.CharactersEventBase
All Implemented Interfaces:
DiffXEvent, TextEvent, XMLFormattable, XMLWritable
Direct Known Subclasses:
CharactersEvent, SpaceEvent, WordEvent

public abstract class CharactersEventBase
extends Object
implements TextEvent

A base class for all the characters events "characters" SAX event.

Version:
28 March 2010
Author:
Christophe Lauret

Constructor Summary
CharactersEventBase(CharSequence seq)
          Creates a new characters event.
 
Method Summary
 boolean equals(DiffXEvent e)
          Returns true if the event is a character event and its content is equivalent.
 boolean equals(Object o)
          Invokes the DiffXEvent.equals(DiffXEvent) method if the specified object if not null and is an instance of DiffXEvent.
 String getCharacters()
          Returns the characters that this event represents.
 int getWeight()
          Returns the weight of this event.
 int hashCode()
          
 void setWeight(int weight)
          Sets the weight of this event.
 String toXML()
          Returns a xml representation of the object of the implementing class.
 StringBuffer toXML(StringBuffer xml)
          Appends the XML representation of the object of the implementing class.
 void toXML(XMLWriter xml)
          Writes the XML representation of the implementing instance using the specified XMLWriter.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.topologi.diffx.event.DiffXEvent
getWeight, setWeight
 
Methods inherited from interface com.topologi.diffx.xml.XMLFormattable
toXML
 

Constructor Detail

CharactersEventBase

public CharactersEventBase(CharSequence seq)
                    throws NullPointerException
Creates a new characters event.

Parameters:
seq - The char sequence.
Throws:
NullPointerException - If the given String is null.
Method Detail

hashCode

public final int hashCode()


equals

public final boolean equals(DiffXEvent e)
Returns true if the event is a character event and its content is equivalent.

Specified by:
equals in interface DiffXEvent
Parameters:
e - The event to compare with this event.
Returns:
true if considered equal; false otherwise.

getCharacters

public final String getCharacters()
Returns the characters that this event represents.

Note: this method will return the characters as used by Java (ie. Unicode), they may not be suitable for writing to an XML string.

Specified by:
getCharacters in interface TextEvent
Returns:
The characters that this event represents.

toXML

public final void toXML(XMLWriter xml)
                 throws IOException
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 final StringBuffer toXML(StringBuffer xml)
                         throws NullPointerException
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.

equals

public final boolean equals(Object o)
Invokes the DiffXEvent.equals(DiffXEvent) method if the specified object if not null and is an instance of DiffXEvent.

Overrides:
equals in class Object
Parameters:
o - The object to compare.
Returns:
true if the specified object is equal; false otherwise.

toXML

public String toXML()
Description copied from interface: XMLFormattable

Returns a xml representation of the object of the implementing class.

Most implementation should use the following code to ensure consistent data with the other toXML method:

return this.toXML(new StringBuffer()).toString();

Specified by:
toXML in interface XMLFormattable
Returns:
a XML representation of the object of the implementing class.

getWeight

public int getWeight()
Description copied from interface: DiffXEvent
Returns the weight of this event.

The default weight should be 1.

Specified by:
getWeight in interface DiffXEvent
Returns:
The weight of this event.

setWeight

public void setWeight(int weight)
Description copied from interface: DiffXEvent
Sets the weight of this event.

This method is intended for use by algorithms, optimisers and loaders in order to adjust the importance of an event.

Specified by:
setWeight in interface DiffXEvent
Parameters:
weight - The weight of this event.