// // Set a change event on the root //
MyListener l = new MyListener(book);
book.addPropertyChangeListener(l);
setTest("simple change event on the root");
l.reset();
String s = "This book is about how to raise the event familly"; // Change a property on the root - this should raises an event
book.setSummary(s); // Check the received event
check(l.oldValue() == null, "(old value)");
check(l.newValue().equals(s), "(new value)");
setTest("change the same property on the root");
l.reset();
String s2 = "This book is about nothing at all"; // Change a property on the root - this should raises an event
book.setSummary(s2); // Check the received event
check(l.oldValue().equals(s), "(old value)");
check(l.newValue().equals(s2), "(new value)");
setTest("remove this same property");
l.reset(); // Change a property on the root - this should raises an event
book.setSummary(null); // Check the received event
check(l.oldValue().equals(s2), "(old value)");
check(l.newValue() == null, "(new value)");
// // Keep the same event on the root, but change a property of another // property (not a direct property of the root) //
setTest("propagation of the event");
Chapter c = book.getChapter(0);
l.reset();
s = c.getComment();
s2 = "Comment on the first chapter";
c.setComment(s2);
check(l.oldValue.equals(s), "(oldvalue)");
check(l.newValue.equals(s2), "(newvalue)");
// Add three paragraphs
setTest("event on indexed property - add new");
l.reset();
s = "This is a new paragraph"; int i = c.addParagraph(s);
check(l.oldValue == null, "(no old value - new element)");
check(l.newValue.equals(s), "(new value)");
check(l.index == i, "(correct index)");
setTest("event on indexed property - add new");
l.reset();
s2 = "This is another paragraph"; int j = c.addParagraph(s2);
check(l.oldValue == null, "(no old value - new element)");
check(l.newValue.equals(s2), "(new value)");
check(l.index == j, "(correct index)");
setTest("event on indexed property - add new");
l.reset();
s2 = "This is yet another paragraph";
j = c.addParagraph(s2);
check(l.oldValue == null, "(no old element - new element)");
check(l.newValue.equals(s2), "(new value)");
check(l.index == j, "(correct index)");
// Remove the first added
setTest("event on indexed property - remove index");
l.reset();
c.setParagraph(i, null);
check(l.oldValue.equals(s), "(old value)");
check(l.newValue == null, "(no new value)");
check(l.index == i, "(correct index)");
setTest("event on indexed property - reset new");
l.reset();
c.setParagraph(i, s);
check(l.oldValue == null, "(old value)");
check(l.newValue.equals(s), "(no new value)");
check(l.index == i, "(correct index)");
// // Add another listener on an intermediate node and on a leaf //
Chapter c2 = book.getChapter(1);
MyListener l2 = new MyListener(c2);
// Get the events only for Paragraph changes
c2.addPropertyChangeListener("Paragraph", l2);
// Check that we receive the event twice
setTest("two listeners - both receiving");
l2.reset();
l.reset();
s = "This is a brand new one";
c2.addParagraph(s);
check(l.oldValue == null, "(no old value)");
check(l.newValue.equals(s), "(new value)");
check(l.oldValue == l2.oldValue, "(same old value - both listeners)");
check(l.newValue.equals(l2.newValue), "(same new value - both listeners)");
check(l.index == l2.index, "(same index - both listeners)");
check(l.source == l2.source, "(same source - both listeners)");
// Check that modifying the comment won't notify the Paragraph listener
setTest("two listeners - one receiving");
l2.reset();
l.reset();
s = "That's a new comment value";
c2.setComment(s);
check(l.newValue.equals(s), "(root listener: yep)");
check(l2.newValue == null, "(chapter listener: noop)");
// Remove the book listener
book.removePropertyChangeListener(l);
setTest("one listener - no receiving");
l2.reset();
l.reset();
s = "That's another new comment value";
c2.setComment(s);
check(l.newValue == null, "(root listener: noop)");
check(l2.newValue == null, "(chapter listener: noop)");
setTest("one listener - one receiving");
l2.reset();
l.reset();
s = "That's a brand new paragraph";
c2.addParagraph(s);
check(l.newValue == null, "(root listener: noop)");
check(l2.newValue.equals(s), "(chapter listener: yep)");
setTest("no listener - no receiving");
c2.removePropertyChangeListener("Paragraph", l2);
l2.reset();
l.reset();
s = "That's yet another brand new paragraph";
c2.addParagraph(s);
check(l.newValue == null, "(root listener: noop)");
check(l2.newValue == null, "(chapter listener: noop)");
// Register again the listeners
book.addPropertyChangeListener(l);
c2.addPropertyChangeListener("Paragraph", l2);
l.removeMode();
l2.removeMode();
l2.reset();
l.reset();
book.removeChapter(c2);
out("should have received paragraph events on Chapter and Chapter event on Book");
// // Make sure that the event is triggered after the property // has changed. //
c = new Chapter();
c.addParagraph("1. this is a paragraph");
c.addParagraph("2. this is a paragraph");
c.addParagraph("3. this is a paragraph");
c.addParagraph("4. this is a paragraph");
out("should receive Chapter event and get 4 strings from the event");
l.traceParagraphs(c);
book.addChapter(c);
String[] pp = c.getParagraph();
String[] pp2 = new String[3];
pp2[0] = pp[0];
pp2[1] = pp[3];
pp2[2] = pp[2];
out("should receive Chapter event and get 3 strings from the event (1, 4, 3)");
c.setParagraph(pp2);
l.traceParagraphs(null);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.