harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r479418 [25/43] - in /harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common: javax/swing/ javax/swing/border/ javax/swing/colorchooser/ javax/swing/event/ javax/swing/filechooser/ javax/swing/plaf/ javax/swing/plaf/basic/ j...
Date Sun, 26 Nov 2006 20:15:55 GMT
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java Sun Nov 26 12:15:43 2006
@@ -21,7 +21,6 @@
 package javax.swing.text;
 
 import java.util.List;
-
 import javax.swing.event.DocumentEvent.ElementChange;
 import javax.swing.event.DocumentEvent.EventType;
 import javax.swing.text.AbstractDocument.BranchElement;
@@ -29,7 +28,6 @@
 import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
 import javax.swing.text.DefaultStyledDocument.ElementBuffer;
 import javax.swing.text.DefaultStyledDocument.ElementSpec;
-
 import junit.framework.TestCase;
 
 /**
@@ -38,23 +36,30 @@
  * The text contains only new line character.
  *
  */
-public class DefaultStyledDocument_ElementBuffer_InsertNewLineTest
-    extends TestCase {
-
+public class DefaultStyledDocument_ElementBuffer_InsertNewLineTest extends TestCase {
     private DefaultStyledDocument doc;
+
     private ElementBuffer buf;
+
     private Element root;
+
     private Element paragraph;
+
     private int insertOffset;
+
     private Content content;
+
     private DefaultDocumentEvent event;
 
     private static final AttributeSet bold = DefStyledDoc_Helpers.bold;
+
     private static final AttributeSet italic = DefStyledDoc_Helpers.italic;
 
     private static final String newLine = "\n";
+
     private static final int newLineLen = newLine.length();
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefaultStyledDocument();
@@ -62,37 +67,30 @@
         buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
         doc.buffer = buf;
         paragraph = root.getElement(0);
-
         content = doc.getContent();
-
         content.insertString(0, "plainbolditalic\ntext");
         // Create the structure equivalent to this sequence:
         //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
         //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
         //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
         //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
-
         doc.writeLock(); // Write lock needed to modify document structure
-
         Element[] leaves = new Element[4];
         leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
         leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
         leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
         leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
-        ((BranchElement)paragraph).replace(0, 1, leaves);
-
-        BranchElement branch = (BranchElement)doc.createBranchElement(root,
-                                                                      null);
+        ((BranchElement) paragraph).replace(0, 1, leaves);
+        BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
         leaves = new Element[1];
         leaves[0] = doc.createLeafElement(branch, null, 16, 21);
         branch.replace(0, 0, leaves);
-
         // Add this branch to the root
-        ((BranchElement)root).replace(1, 0, new Element[] {branch});
-
+        ((BranchElement) root).replace(1, 0, new Element[] { branch });
         insertOffset = 5 + 2;
     }
 
+    @Override
     protected void tearDown() throws Exception {
         super.tearDown();
         doc.writeUnlock();
@@ -110,35 +108,23 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, newLine, null);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {0, 6, 6, 10, 10, 16, 16, 17},
-                     new int[] {0, 1});
-        assertChange(edits.get(1), new int[] {}, new int[] {1, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 1},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1),
-                       new int[] {1, 6, 6, 10, 10, 16, 16, 17},
-                       new AttributeSet[] {null, bold, italic, null});
-
+        assertChange(edits.get(0), new int[] { 0, 6, 6, 10, 10, 16, 16, 17 },
+                new int[] { 0, 1 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 1, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 1, 6, 6, 10, 10, 16, 16, 17 },
+                new AttributeSet[] { null, bold, italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -153,34 +139,22 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, newLine, italic);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {0, 6, 6, 10, 10, 16, 16, 17},
-                     new int[] {0, 1});
-        assertChange(edits.get(1), new int[] {}, new int[] {1, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 1},
-                       new AttributeSet[] {italic});
-        assertChildren(root.getElement(1),
-                       new int[] {1, 6, 6, 10, 10, 16, 16, 17},
-                       new AttributeSet[] {null, bold, italic, null});
-
+        assertChange(edits.get(0), new int[] { 0, 6, 6, 10, 10, 16, 16, 17 },
+                new int[] { 0, 1 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 1, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { italic });
+        assertChildren(root.getElement(1), new int[] { 1, 6, 6, 10, 10, 16, 16, 17 },
+                new AttributeSet[] { null, bold, italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -194,34 +168,23 @@
     public void testInsertSameAttrsMiddle() throws Exception {
         // doc.insertString(insertOffset, newLine, bold);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {5, 10, 10, 16, 16, 17},
-                     new int[] {5, 8});
-        assertChange(edits.get(1), new int[] {}, new int[] {8, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 5, 5, 8},
-                       new AttributeSet[] {null, bold});
-        assertChildren(root.getElement(1), new int[] {8, 10, 10, 16, 16, 17},
-                       new AttributeSet[] {bold, italic, null});
-
+        assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 }, new int[] { 5, 8 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 8 }, new AttributeSet[] { null,
+                bold });
+        assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
+                new AttributeSet[] { bold, italic, null });
         assertEquals("bo\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("ld", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
+        assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -236,36 +199,25 @@
         insertOffset += 2;
         // doc.insertString(insertOffset, newLine, bold);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
         // Spec [0] has wrong attributes (should be bold) but everything works
         // the way it supposed to.
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {10, 16, 16, 17},
-                     new int[] {});
-        assertChange(edits.get(1), new int[] {}, new int[] {10, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 5, 5, 10},
-                       new AttributeSet[] {null, bold});
-        assertChildren(root.getElement(1), new int[] {10, 16, 16, 17},
-                       new AttributeSet[] {italic, null});
-
+        assertChange(edits.get(0), new int[] { 10, 16, 16, 17 }, new int[] {});
+        assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 10 }, new AttributeSet[] {
+                null, bold });
+        assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
+                italic, null });
         assertEquals("bold\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("italic", getText(doc.getCharacterElement(insertOffset
-                                                               + newLineLen)));
+        assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -279,33 +231,23 @@
     public void testInsertDiffAttrsMiddle() throws Exception {
         // doc.insertString(insertOffset, newLine, null);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {5, 10, 10, 16, 16, 17},
-                     new int[] {5, 7, 7, 8});
-        assertChange(edits.get(1), new int[] {}, new int[] {8, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 5, 5, 7, 7, 8},
-                       new AttributeSet[] {null, bold, null});
-        assertChildren(root.getElement(1), new int[] {8, 10, 10, 16, 16, 17},
-                       new AttributeSet[] {bold, italic, null});
-
+        assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
+                new int[] { 5, 7, 7, 8 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 7, 7, 8 }, new AttributeSet[] {
+                null, bold, null });
+        assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
+                new AttributeSet[] { bold, italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("ld", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
+        assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -320,33 +262,23 @@
         insertOffset += 2;
         // doc.insertString(insertOffset, newLine, null);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {5, 10, 10, 16, 16, 17},
-                     new int[] {5, 9, 9, 10});
-        assertChange(edits.get(1), new int[] {}, new int[] {10, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 5, 5, 9, 9, 10},
-                       new AttributeSet[] {null, bold, null});
-        assertChildren(root.getElement(1), new int[] {10, 16, 16, 17},
-                       new AttributeSet[] {italic, null});
-
+        assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
+                new int[] { 5, 9, 9, 10 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
+                null, bold, null });
+        assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
+                italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("italic", getText(doc.getCharacterElement(insertOffset
-                                                               + newLineLen)));
+        assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -362,33 +294,23 @@
         insertOffset += 2;
         // doc.insertString(insertOffset, newLine, italic);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {5, 10, 10, 16, 16, 17},
-                     new int[] {5, 9, 9, 10});
-        assertChange(edits.get(1), new int[] {}, new int[] {10, 17});
-
-        assertChildren(root.getElement(0), new int[] {0, 5, 5, 9, 9, 10},
-                       new AttributeSet[] {null, bold, italic});
-        assertChildren(root.getElement(1), new int[] {10, 16, 16, 17},
-                       new AttributeSet[] {italic, null});
-
+        assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
+                new int[] { 5, 9, 9, 10 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
+                null, bold, italic });
+        assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
+                italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("italic", getText(doc.getCharacterElement(insertOffset
-                                                               + newLineLen)));
+        assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -402,42 +324,25 @@
         insertOffset = paragraph.getEndOffset();
         // doc.insertString(insertOffset, newLine, null);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[4].setDirection(ElementSpec.JoinNextDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(3, edits.size());
-        assertChange(edits.get(0), new int[] {15, 17},
-                     new int[] {15, 16});
-        assertChange(edits.get(1), new int[] {},
-                     new int[] {16, 17});
-        assertChange(edits.get(2), new int[] {},
-                     new int[] {16, 17});
-
-        assertChildren(root.getElement(0),
-                       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
-        assertChildren(root.getElement(1),
-                       new int[] {16, 17},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2),
-                       new int[] {17, 22},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(0), new int[] { 15, 17 }, new int[] { 15, 16 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 16, 17 });
+        assertChange(edits.get(2), new int[] {}, new int[] { 16, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 15, 15, 16 },
+                new AttributeSet[] { null, bold, italic, null });
+        assertChildren(root.getElement(1), new int[] { 16, 17 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 17, 22 }, new AttributeSet[] { null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("text\n", getText(doc.getCharacterElement(insertOffset
-                                                               + newLineLen)));
+        assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -451,41 +356,25 @@
         insertOffset = paragraph.getEndOffset();
         // doc.insertString(insertOffset, newLine, italic);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[4].setDirection(ElementSpec.JoinNextDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(3, edits.size());
-        assertChange(edits.get(0), new int[] {15, 17},
-                     new int[] {15, 16});
-        assertChange(edits.get(1), new int[] {},
-                     new int[] {16, 17});
-        assertChange(edits.get(2), new int[] {},
-                     new int[] {16, 17});
-
-        assertChildren(root.getElement(0),
-                       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
-        assertChildren(root.getElement(1),
-                       new int[] {16, 17},
-                       new AttributeSet[] {italic});
-        assertChildren(root.getElement(2),
-                       new int[] {17, 22},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(0), new int[] { 15, 17 }, new int[] { 15, 16 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 16, 17 });
+        assertChange(edits.get(2), new int[] {}, new int[] { 16, 17 });
+        assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 15, 15, 16 },
+                new AttributeSet[] { null, bold, italic, null });
+        assertChildren(root.getElement(1), new int[] { 16, 17 }, new AttributeSet[] { italic });
+        assertChildren(root.getElement(2), new int[] { 17, 22 }, new AttributeSet[] { null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("text\n", getText(doc.getCharacterElement(insertOffset
-                                                               + newLineLen)));
+        assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -499,35 +388,21 @@
         insertOffset = doc.getLength();
         // doc.insertString(insertOffset, newLine, null);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {16, 22},
-                     new int[] {16, 21});
-        assertChange(edits.get(1), new int[] {}, new int[] {21, 22});
-
-        assertChildren(root.getElement(1), new int[] {16, 21},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2),
-                       new int[] {21, 22},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(0), new int[] { 16, 22 }, new int[] { 16, 21 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 21, 22 });
+        assertChildren(root.getElement(1), new int[] { 16, 21 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 21, 22 }, new AttributeSet[] { null });
         assertEquals("text\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("\n", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
+        assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
     /**
@@ -541,96 +416,76 @@
         insertOffset = doc.getLength();
         // doc.insertString(insertOffset, newLine, italic);
         content.insertString(insertOffset, newLine);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[2].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLineLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-
-        assertChange(edits.get(0), new int[] {16, 22},
-                     new int[] {16, 20, 20, 21});
-        assertChange(edits.get(1), new int[] {}, new int[] {21, 22});
-
-        assertChildren(root.getElement(1), new int[] {16, 20, 20, 21},
-                       new AttributeSet[] {null, italic});
-        assertChildren(root.getElement(2),
-                       new int[] {21, 22},
-                       new AttributeSet[] {null});
-
-        assertEquals("text", getText(doc.getCharacterElement(insertOffset
-                                                             - 1)));
+        assertChange(edits.get(0), new int[] { 16, 22 }, new int[] { 16, 20, 20, 21 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 21, 22 });
+        assertChildren(root.getElement(1), new int[] { 16, 20, 20, 21 }, new AttributeSet[] {
+                null, italic });
+        assertChildren(root.getElement(2), new int[] { 21, 22 }, new AttributeSet[] { null });
+        assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("\n", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
+        assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
     }
 
-    private String getText(final int offset, final int length)
-        throws BadLocationException {
-
+    private String getText(final int offset, final int length) throws BadLocationException {
         return doc.getText(offset, length);
     }
 
     private String getText(final Element element) throws BadLocationException {
-        return getText(element.getStartOffset(),
-                       element.getEndOffset() - element.getStartOffset());
+        return getText(element.getStartOffset(), element.getEndOffset()
+                - element.getStartOffset());
     }
 
-    private static void assertChange(final Object change,
-                                     final int[] removedOffsets,
-                                     final int[] addedOffsets) {
-        DefStyledDoc_Helpers.assertChange((ElementChange)change,
-                                          removedOffsets, addedOffsets);
+    private static void assertChange(final Object change, final int[] removedOffsets,
+            final int[] addedOffsets) {
+        DefStyledDoc_Helpers.assertChange((ElementChange) change, removedOffsets, addedOffsets);
     }
 
-    private static void assertChildren(final Element element,
-                                       final int[] offsets,
-                                       final AttributeSet[] attributes) {
+    private static void assertChildren(final Element element, final int[] offsets,
+            final AttributeSet[] attributes) {
         DefStyledDoc_Helpers.assertChildren(element, offsets, attributes);
     }
 
-    private static List getEdits(final DefaultDocumentEvent event) {
+    private static List<?> getEdits(final DefaultDocumentEvent event) {
         return DefStyledDoc_Helpers.getEdits(event);
     }
-
 }
 /*
-The dump of the document after the initial set up.
+ The dump of the document after the initial set up.
 
-<section>
-  <paragraph
-    resolver=NamedStyle:default {name=default,}
-  >
-    <content>
-      [0,5][plain]
-    <content
-      bold=true
-    >
-      [5,9][bold]
-    <content
-      italic=true
-    >
-      [9,15][italic]
-    <content>
-      [15,16][
-]
-  <paragraph>
-    <content>
-      [16,21][text
-]
-<bidi root>
-  <bidi level
-    bidiLevel=0
-  >
-    [0,21][plainbolditalic
-text
-]
-*/
\ No newline at end of file
+ <section>
+ <paragraph
+ resolver=NamedStyle:default {name=default,}
+ >
+ <content>
+ [0,5][plain]
+ <content
+ bold=true
+ >
+ [5,9][bold]
+ <content
+ italic=true
+ >
+ [9,15][italic]
+ <content>
+ [15,16][
+ ]
+ <paragraph>
+ <content>
+ [16,21][text
+ ]
+ <bidi root>
+ <bidi level
+ bidiLevel=0
+ >
+ [0,21][plainbolditalic
+ text
+ ]
+ */
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest.java Sun Nov 26 12:15:43 2006
@@ -21,7 +21,6 @@
 package javax.swing.text;
 
 import java.util.List;
-
 import javax.swing.event.DocumentEvent.ElementChange;
 import javax.swing.event.DocumentEvent.EventType;
 import javax.swing.text.AbstractDocument.AbstractElement;
@@ -30,7 +29,6 @@
 import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
 import javax.swing.text.DefaultStyledDocument.ElementBuffer;
 import javax.swing.text.DefaultStyledDocument.ElementSpec;
-
 import junit.framework.TestCase;
 
 /**
@@ -40,31 +38,42 @@
  * too.
  *
  */
-public class DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest
-    extends TestCase {
-
+public class DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest extends TestCase {
     private DefaultStyledDocument doc;
+
     private ElementBuffer buf;
+
     private Element root;
+
     private Element paragraph;
+
     private int insertOffset;
+
     private Content content;
+
     private DefaultDocumentEvent event;
 
     private static final AttributeSet bold = DefStyledDoc_Helpers.bold;
+
     private static final AttributeSet italic = DefStyledDoc_Helpers.italic;
 
     private static final String newLine = "\n";
+
     private static final int newLineLen = newLine.length();
 
     private static final String newLines2 = "\n\n";
+
     private static final int newLines2Len = newLines2.length();
+
     private static final String newLines3 = "\n\n\n";
+
     private static final int newLines3Len = newLines3.length();
 
     private static final String newLines2Text = "0\n1\n";
+
     private static final String newLines3Text = "0\n1\n2\n";
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefaultStyledDocument();
@@ -72,38 +81,31 @@
         buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
         doc.buffer = buf;
         paragraph = root.getElement(0);
-
         content = doc.getContent();
         paragraph = root.getElement(0);
-
         content.insertString(0, "plainbolditalic\ntext");
         // Create the structure equivalent to this sequence:
         //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
         //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
         //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
         //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
-
         doc.writeLock(); // Write lock needed to modify document structure
-
         Element[] leaves = new Element[4];
         leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
         leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
         leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
         leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
-        ((BranchElement)paragraph).replace(0, 1, leaves);
-
-        BranchElement branch = (BranchElement)doc.createBranchElement(root,
-                                                                      null);
+        ((BranchElement) paragraph).replace(0, 1, leaves);
+        BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
         leaves = new Element[1];
         leaves[0] = doc.createLeafElement(branch, null, 16, 21);
         branch.replace(0, 0, leaves);
-
         // Add this branch to the root
-        ((BranchElement)root).replace(1, 0, new Element[] {branch});
-
+        ((BranchElement) root).replace(1, 0, new Element[] { branch });
         insertOffset = 5 + 2;
     }
 
+    @Override
     protected void tearDown() throws Exception {
         super.tearDown();
         doc.writeUnlock();
@@ -121,44 +123,29 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, newLines2, null);
         content.insertString(insertOffset, newLines2);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLines2Len,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLines2Len, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLines2Len, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(3, edits.size());
-
-        assertChange(edits.get(0), 0, new int[] {0, 7, 7, 11, 11, 17, 17, 18},
-                     new int[] {0, 1});
-        assertChange(edits.get(1), 0, new int[] {}, new int[] {1, 2});
-        assertChange(edits.get(2), 1, new int[] {}, new int[] {1, 2, 2, 18});
-
-        assertChildren(root.getElement(0), new int[] {0, 1},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1),
-                       new int[] {1, 2},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2),
-                       new int[] {2, 7, 7, 11, 11, 17, 17, 18},
-                       new AttributeSet[] {null, bold, italic, null});
-
+        assertChange(edits.get(0), 0, new int[] { 0, 7, 7, 11, 11, 17, 17, 18 }, new int[] { 0,
+                1 });
+        assertChange(edits.get(1), 0, new int[] {}, new int[] { 1, 2 });
+        assertChange(edits.get(2), 1, new int[] {}, new int[] { 1, 2, 2, 18 });
+        assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 1, 2 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 2, 7, 7, 11, 11, 17, 17, 18 },
+                new AttributeSet[] { null, bold, italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("\n", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                              + newLines2Len)));
+        assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLines2Len)));
     }
 
     /**
@@ -173,54 +160,35 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, newLines3, null);
         content.insertString(insertOffset, newLines3);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLines3Len,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLines3Len, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLines3Len, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(4, edits.size());
-
-        assertChange(edits.get(0), 0, new int[] {0, 8, 8, 12, 12, 18, 18, 19},
-                     new int[] {0, 1});
-        assertChange(edits.get(1), 0, new int[] {}, new int[] {1, 2});
-        assertChange(edits.get(2), 0, new int[] {}, new int[] {2, 3});
-        assertChange(edits.get(3), 1, new int[] {},
-                     new int[] {1, 2, 2, 3, 3, 19});
-
-        assertChildren(root.getElement(0), new int[] {0, 1},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1),
-                       new int[] {1, 2},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2),
-                       new int[] {2, 3},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(3),
-                       new int[] {3, 8, 8, 12, 12, 18, 18, 19},
-                       new AttributeSet[] {null, bold, italic, null});
-
+        assertChange(edits.get(0), 0, new int[] { 0, 8, 8, 12, 12, 18, 18, 19 }, new int[] { 0,
+                1 });
+        assertChange(edits.get(1), 0, new int[] {}, new int[] { 1, 2 });
+        assertChange(edits.get(2), 0, new int[] {}, new int[] { 2, 3 });
+        assertChange(edits.get(3), 1, new int[] {}, new int[] { 1, 2, 2, 3, 3, 19 });
+        assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 1, 2 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 2, 3 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(3), new int[] { 3, 8, 8, 12, 12, 18, 18, 19 },
+                new AttributeSet[] { null, bold, italic, null });
         assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("\n", getText(doc.getCharacterElement(insertOffset
-                                                           + newLineLen)));
-        assertEquals("\n", getText(doc.getCharacterElement(insertOffset
-                                                           + newLines2Len)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                              + newLines3Len)));
+        assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
+        assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLines2Len)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLines3Len)));
     }
 
     /**
@@ -236,45 +204,29 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, newLines2Text, null);
         content.insertString(insertOffset, newLines2Text);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLines2Len * 2,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLines2Len * 2, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinFractureDirection);
-
         buf.insert(insertOffset, newLines2Len * 2, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(3, edits.size());
-
-        assertChange(edits.get(0), 0, new int[] {0, 9, 9, 13, 13, 19, 19, 20},
-                     new int[] {0, 2});
-        assertChange(edits.get(1), 0, new int[] {}, new int[] {2, 4});
-        assertChange(edits.get(2), 1, new int[] {}, new int[] {2, 4, 4, 20});
-
-        assertChildren(root.getElement(0), new int[] {0, 2},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1),
-                       new int[] {2, 4},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2),
-                       new int[] {4, 9, 9, 13, 13, 19, 19, 20},
-                       new AttributeSet[] {null, bold, italic, null});
-
+        assertChange(edits.get(0), 0, new int[] { 0, 9, 9, 13, 13, 19, 19, 20 }, new int[] { 0,
+                2 });
+        assertChange(edits.get(1), 0, new int[] {}, new int[] { 2, 4 });
+        assertChange(edits.get(2), 1, new int[] {}, new int[] { 2, 4, 4, 20 });
+        assertChildren(root.getElement(0), new int[] { 0, 2 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 2, 4 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 4, 9, 9, 13, 13, 19, 19, 20 },
+                new AttributeSet[] { null, bold, italic, null });
         assertEquals("0\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("1\n", getText(doc.getCharacterElement(insertOffset
-                                                            + newLineLen * 2)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                              + newLines2Len
-                                                                * 2)));
+        assertEquals("1\n", getText(doc.getCharacterElement(insertOffset + newLineLen * 2)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLines2Len * 2)));
     }
 
     /**
@@ -290,109 +242,75 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, newLines3Text, null);
         content.insertString(insertOffset, newLines3Text);
-        event = doc.new DefaultDocumentEvent(insertOffset, newLines3Len * 2,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(bold, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(italic, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(italic, ElementSpec.StartTagType)
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, newLines3Len * 2, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(bold, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(italic, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, newLineLen * 2),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(italic, ElementSpec.StartTagType) };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinFractureDirection);
-
-        ((AbstractElement)root.getElement(0)).addAttributes(bold);
-        ((AbstractElement)root.getElement(0)).addAttributes(italic);
-
+        ((AbstractElement) root.getElement(0)).addAttributes(bold);
+        ((AbstractElement) root.getElement(0)).addAttributes(italic);
         buf.insert(insertOffset, newLines3Len * 2, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(4, edits.size());
-
-        assertChange(edits.get(0), 0, new int[] {0, 11, 11, 15, 15, 21, 21, 22},
-                     new int[] {0, 2});
-        assertChange(edits.get(1), 0, new int[] {}, new int[] {2, 4});
-        assertChange(edits.get(2), 0, new int[] {}, new int[] {4, 6});
-        assertChange(edits.get(3), 1, new int[] {},
-                     new int[] {2, 4, 4, 6, 6, 22});
-
-        assertChildren(root.getElement(0), new int[] {0, 2},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1),
-                       new int[] {2, 4},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2),
-                       new int[] {4, 6},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(3),
-                       new int[] {6, 11, 11, 15, 15, 21, 21, 22},
-                       new AttributeSet[] {null, bold, italic, null});
-
+        assertChange(edits.get(0), 0, new int[] { 0, 11, 11, 15, 15, 21, 21, 22 }, new int[] {
+                0, 2 });
+        assertChange(edits.get(1), 0, new int[] {}, new int[] { 2, 4 });
+        assertChange(edits.get(2), 0, new int[] {}, new int[] { 4, 6 });
+        assertChange(edits.get(3), 1, new int[] {}, new int[] { 2, 4, 4, 6, 6, 22 });
+        assertChildren(root.getElement(0), new int[] { 0, 2 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 2, 4 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 4, 6 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(3), new int[] { 6, 11, 11, 15, 15, 21, 21, 22 },
+                new AttributeSet[] { null, bold, italic, null });
         // Assert attributes of the paragraph
         Element paragraph = root.getElement(0);
         assertEquals(3, paragraph.getAttributes().getAttributeCount());
-        assertTrue(paragraph.getAttributes()
-                   .isDefined(AttributeSet.ResolveAttribute));
+        assertTrue(paragraph.getAttributes().isDefined(AttributeSet.ResolveAttribute));
         assertTrue(paragraph.getAttributes().containsAttributes(bold));
         assertTrue(paragraph.getAttributes().containsAttributes(italic));
-
         paragraph = root.getElement(1);
         assertTrue(paragraph.getAttributes().isEqual(bold));
         paragraph = root.getElement(2);
         assertTrue(paragraph.getAttributes().isEqual(italic));
-
         paragraph = root.getElement(3);
         assertEquals(3, paragraph.getAttributes().getAttributeCount());
-        assertTrue(paragraph.getAttributes()
-                   .isDefined(AttributeSet.ResolveAttribute));
+        assertTrue(paragraph.getAttributes().isDefined(AttributeSet.ResolveAttribute));
         assertTrue(paragraph.getAttributes().containsAttributes(bold));
         assertTrue(paragraph.getAttributes().containsAttributes(italic));
-
         assertEquals("0\n", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("1\n", getText(doc.getCharacterElement(insertOffset
-                                                            + newLineLen * 2)));
-        assertEquals("2\n", getText(doc.getCharacterElement(insertOffset
-                                                            + newLines2Len
-                                                              * 2)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                              + newLines3Len
-                                                                * 2)));
+        assertEquals("1\n", getText(doc.getCharacterElement(insertOffset + newLineLen * 2)));
+        assertEquals("2\n", getText(doc.getCharacterElement(insertOffset + newLines2Len * 2)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLines3Len * 2)));
     }
 
-    private String getText(final int offset, final int length)
-        throws BadLocationException {
-
+    private String getText(final int offset, final int length) throws BadLocationException {
         return doc.getText(offset, length);
     }
 
     private String getText(final Element element) throws BadLocationException {
-        return getText(element.getStartOffset(),
-                       element.getEndOffset() - element.getStartOffset());
+        return getText(element.getStartOffset(), element.getEndOffset()
+                - element.getStartOffset());
     }
 
-    private static void assertChange(final Object change,
-                                     final int index,
-                                     final int[] removedOffsets,
-                                     final int[] addedOffsets) {
-        assertEquals("Change index", index, ((ElementChange)change).getIndex());
-        DefStyledDoc_Helpers.assertChange((ElementChange)change,
-                                          removedOffsets, addedOffsets);
-    }
-
-    private static void assertChildren(final Element element,
-                                       final int[] offsets,
-                                       final AttributeSet[] attributes) {
+    private static void assertChange(final Object change, final int index,
+            final int[] removedOffsets, final int[] addedOffsets) {
+        assertEquals("Change index", index, ((ElementChange) change).getIndex());
+        DefStyledDoc_Helpers.assertChange((ElementChange) change, removedOffsets, addedOffsets);
+    }
+
+    private static void assertChildren(final Element element, final int[] offsets,
+            final AttributeSet[] attributes) {
         DefStyledDoc_Helpers.assertChildren(element, offsets, attributes);
     }
 
-    private static List getEdits(final DefaultDocumentEvent event) {
+    private static List<?> getEdits(final DefaultDocumentEvent event) {
         return DefStyledDoc_Helpers.getEdits(event);
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertTextTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertTextTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertTextTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertTextTest.java Sun Nov 26 12:15:43 2006
@@ -21,7 +21,6 @@
 package javax.swing.text;
 
 import java.util.List;
-
 import javax.swing.event.DocumentEvent.ElementChange;
 import javax.swing.event.DocumentEvent.EventType;
 import javax.swing.text.AbstractDocument.BranchElement;
@@ -29,7 +28,6 @@
 import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
 import javax.swing.text.DefaultStyledDocument.ElementBuffer;
 import javax.swing.text.DefaultStyledDocument.ElementSpec;
-
 import junit.framework.TestCase;
 
 /**
@@ -38,23 +36,30 @@
  * The text contains no new line characters.
  *
  */
-public class DefaultStyledDocument_ElementBuffer_InsertTextTest
-    extends TestCase {
-
+public class DefaultStyledDocument_ElementBuffer_InsertTextTest extends TestCase {
     private DefaultStyledDocument doc;
+
     private ElementBuffer buf;
+
     private Element root;
+
     private Element paragraph;
+
     private int insertOffset;
+
     private Content content;
+
     private DefaultDocumentEvent event;
 
     private static final AttributeSet bold = DefStyledDoc_Helpers.bold;
+
     private static final AttributeSet italic = DefStyledDoc_Helpers.italic;
 
     private static final String caps = "^^^";
+
     private static final int capsLen = caps.length();
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefaultStyledDocument();
@@ -62,38 +67,31 @@
         buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
         doc.buffer = buf;
         paragraph = root.getElement(0);
-
         content = doc.getContent();
         paragraph = root.getElement(0);
-
         content.insertString(0, "plainbolditalic\ntext");
         // Create the structure equivalent to this sequence:
         //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
         //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
         //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
         //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
-
         doc.writeLock(); // Write lock needed to modify document structure
-
         Element[] leaves = new Element[4];
         leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
         leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
         leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
         leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
-        ((BranchElement)paragraph).replace(0, 1, leaves);
-
-        BranchElement branch = (BranchElement)doc.createBranchElement(root,
-                                                                      null);
+        ((BranchElement) paragraph).replace(0, 1, leaves);
+        BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
         leaves = new Element[1];
         leaves[0] = doc.createLeafElement(branch, null, 16, 21);
         branch.replace(0, 0, leaves);
-
         // Add this branch to the root
-        ((BranchElement)root).replace(1, 0, new Element[] {branch});
-
+        ((BranchElement) root).replace(1, 0, new Element[] { branch });
         insertOffset = 5 + 2;
     }
 
+    @Override
     protected void tearDown() throws Exception {
         super.tearDown();
         doc.writeUnlock();
@@ -111,20 +109,13 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, caps, null);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
         spec.setDirection(ElementSpec.JoinPreviousDirection);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(0, edits.size());
-
-        assertEquals("^^^plain",
-                     getText(doc.getCharacterElement(insertOffset)));
+        assertEquals("^^^plain", getText(doc.getCharacterElement(insertOffset)));
     }
 
     /**
@@ -139,22 +130,14 @@
         insertOffset = 0;
         // doc.insertString(insertOffset, caps, italic);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), new int[] {0, 8},
-                     new int[] {0, 3, 3, 8});
-
+        assertChange(edits.get(0), new int[] { 0, 8 }, new int[] { 0, 3, 3, 8 });
         assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("plain", getText(doc.getCharacterElement(insertOffset
-                                                              + capsLen)));
+        assertEquals("plain", getText(doc.getCharacterElement(insertOffset + capsLen)));
     }
 
     /**
@@ -168,18 +151,12 @@
     public void testInsertSameAttrsMiddle() throws Exception {
         // doc.insertString(insertOffset, caps, bold);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
         spec.setDirection(ElementSpec.JoinPreviousDirection);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(0, edits.size());
-
         assertEquals("bo^^^ld", getText(doc.getCharacterElement(insertOffset)));
     }
 
@@ -195,18 +172,12 @@
         insertOffset += 2;
         // doc.insertString(insertOffset, caps, bold);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
         spec.setDirection(ElementSpec.JoinPreviousDirection);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(0, edits.size());
-
         assertEquals("bold^^^", getText(doc.getCharacterElement(insertOffset)));
     }
 
@@ -221,23 +192,15 @@
     public void testInsertDiffAttrsMiddle() throws Exception {
         // doc.insertString(insertOffset, caps, null);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), new int[] {5, 12},
-                     new int[] {5, 7, 7, 10, 10, 12});
-
+        assertChange(edits.get(0), new int[] { 5, 12 }, new int[] { 5, 7, 7, 10, 10, 12 });
         assertEquals("bo", getText(doc.getCharacterElement(insertOffset - 1)));
         assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("ld", getText(doc.getCharacterElement(insertOffset
-                                                           + capsLen)));
+        assertEquals("ld", getText(doc.getCharacterElement(insertOffset + capsLen)));
     }
 
     /**
@@ -252,24 +215,15 @@
         insertOffset += 2;
         // doc.insertString(insertOffset, caps, null);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), new int[] {5, 12},
-                     new int[] {5, 9, 9, 12});
-
-        assertEquals("bold", getText(doc.getCharacterElement(insertOffset
-                                                             - 1)));
+        assertChange(edits.get(0), new int[] { 5, 12 }, new int[] { 5, 9, 9, 12 });
+        assertEquals("bold", getText(doc.getCharacterElement(insertOffset - 1)));
         assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("italic", getText(doc.getCharacterElement(insertOffset
-                                                               + capsLen)));
+        assertEquals("italic", getText(doc.getCharacterElement(insertOffset + capsLen)));
     }
 
     /**
@@ -285,24 +239,15 @@
         insertOffset += 2;
         // doc.insertString(insertOffset, caps, italic);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(italic, ElementSpec.ContentType,
-                                           capsLen);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(italic, ElementSpec.ContentType, capsLen);
         spec.setDirection(ElementSpec.JoinNextDirection);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), new int[] {5, 12, 12, 18},
-                     new int[] {5, 9, 9, 18});
-
-        assertEquals("bold", getText(doc.getCharacterElement(insertOffset
-                                                             - 1)));
-        assertEquals("^^^italic",
-                     getText(doc.getCharacterElement(insertOffset)));
+        assertChange(edits.get(0), new int[] { 5, 12, 12, 18 }, new int[] { 5, 9, 9, 18 });
+        assertEquals("bold", getText(doc.getCharacterElement(insertOffset - 1)));
+        assertEquals("^^^italic", getText(doc.getCharacterElement(insertOffset)));
     }
 
     /**
@@ -316,35 +261,21 @@
         insertOffset = paragraph.getEndOffset();
         // doc.insertString(insertOffset, caps, null);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, capsLen),
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, capsLen), };
         specs[1].setDirection(ElementSpec.JoinNextDirection);
         specs[2].setDirection(ElementSpec.JoinNextDirection);
-
         buf.insert(insertOffset, capsLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-        assertChange(edits.get(0), new int[] {15, 19},
-                     new int[] {15, 16});
-        assertChange(edits.get(1), new int[] {19, 24},
-                     new int[] {16, 24});
-
-        assertChildren(paragraph,
-                       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
-        assertChildren(root.getElement(1),
-                       new int[] {16, 24},
-                       new AttributeSet[] {null});
-
-        assertEquals("^^^text\n",
-                     getText(doc.getCharacterElement(insertOffset)));
+        assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
+        assertChange(edits.get(1), new int[] { 19, 24 }, new int[] { 16, 24 });
+        assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
+                null, bold, italic, null });
+        assertChildren(root.getElement(1), new int[] { 16, 24 }, new AttributeSet[] { null });
+        assertEquals("^^^text\n", getText(doc.getCharacterElement(insertOffset)));
     }
 
     /**
@@ -358,35 +289,22 @@
         insertOffset = paragraph.getEndOffset();
         // doc.insertString(insertOffset, caps, italic);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(italic, ElementSpec.ContentType, capsLen),
-        };
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(italic, ElementSpec.ContentType, capsLen), };
         specs[1].setDirection(ElementSpec.JoinNextDirection);
-
         buf.insert(insertOffset, capsLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-        assertChange(edits.get(0), new int[] {15, 19},
-                     new int[] {15, 16});
-        assertChange(edits.get(1), new int[] {},
-                     new int[] {16, 19});
-
-        assertChildren(paragraph,
-                       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
-        assertChildren(root.getElement(1),
-                       new int[] {16, 19, 19, 24},
-                       new AttributeSet[] {italic, null});
-
+        assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
+        assertChange(edits.get(1), new int[] {}, new int[] { 16, 19 });
+        assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
+                null, bold, italic, null });
+        assertChildren(root.getElement(1), new int[] { 16, 19, 19, 24 }, new AttributeSet[] {
+                italic, null });
         assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("text\n", getText(doc.getCharacterElement(insertOffset
-                                                               + capsLen)));
+        assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
     }
 
     /**
@@ -400,24 +318,14 @@
         insertOffset = doc.getLength();
         // doc.insertString(insertOffset, caps, null);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType,
-                                           capsLen);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(null, ElementSpec.ContentType, capsLen);
         spec.setDirection(ElementSpec.JoinPreviousDirection);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(0, edits.size());
-
-        assertChildren(root.getElement(1),
-                       new int[] {16, 24},
-                       new AttributeSet[] {null});
-
-        assertEquals("text^^^\n",
-                     getText(doc.getCharacterElement(insertOffset)));
+        assertChildren(root.getElement(1), new int[] { 16, 24 }, new AttributeSet[] { null });
+        assertEquals("text^^^\n", getText(doc.getCharacterElement(insertOffset)));
     }
 
     /**
@@ -431,87 +339,71 @@
         insertOffset = doc.getLength();
         // doc.insertString(insertOffset, caps, italic);
         content.insertString(insertOffset, caps);
-        event = doc.new DefaultDocumentEvent(insertOffset, capsLen,
-                                             EventType.INSERT);
-
-        ElementSpec spec = new ElementSpec(italic, ElementSpec.ContentType,
-                                           capsLen);
-
-        buf.insert(insertOffset, capsLen, new ElementSpec[] {spec}, event);
-
-        List edits = getEdits(event);
+        event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
+        ElementSpec spec = new ElementSpec(italic, ElementSpec.ContentType, capsLen);
+        buf.insert(insertOffset, capsLen, new ElementSpec[] { spec }, event);
+        List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), new int[] {16, 24},
-                     new int[] {16, 20, 20, 23, 23, 24});
-
-        assertChildren(root.getElement(1),
-                       new int[] {16, 20, 20, 23, 23, 24},
-                       new AttributeSet[] {null, italic, null});
-
-        assertEquals("text", getText(doc.getCharacterElement(insertOffset
-                                                               - 1)));
+        assertChange(edits.get(0), new int[] { 16, 24 }, new int[] { 16, 20, 20, 23, 23, 24 });
+        assertChildren(root.getElement(1), new int[] { 16, 20, 20, 23, 23, 24 },
+                new AttributeSet[] { null, italic, null });
+        assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
         assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
-        assertEquals("\n", getText(doc.getCharacterElement(insertOffset
-                                                           + capsLen)));
+        assertEquals("\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
     }
 
-    private String getText(final int offset, final int length)
-        throws BadLocationException {
-
+    private String getText(final int offset, final int length) throws BadLocationException {
         return doc.getText(offset, length);
     }
 
     private String getText(final Element element) throws BadLocationException {
-        return getText(element.getStartOffset(),
-                       element.getEndOffset() - element.getStartOffset());
+        return getText(element.getStartOffset(), element.getEndOffset()
+                - element.getStartOffset());
     }
 
-    private static void assertChange(final Object change,
-                                     final int[] removedOffsets,
-                                     final int[] addedOffsets) {
-        DefStyledDoc_Helpers.assertChange((ElementChange)change,
-                                          removedOffsets, addedOffsets);
+    private static void assertChange(final Object change, final int[] removedOffsets,
+            final int[] addedOffsets) {
+        DefStyledDoc_Helpers.assertChange((ElementChange) change, removedOffsets, addedOffsets);
     }
 
-    private static void assertChildren(final Element element,
-                                       final int[] offsets,
-                                       final AttributeSet[] attributes) {
+    private static void assertChildren(final Element element, final int[] offsets,
+            final AttributeSet[] attributes) {
         DefStyledDoc_Helpers.assertChildren(element, offsets, attributes);
     }
 
-    private static List getEdits(final DefaultDocumentEvent event) {
+    private static List<?> getEdits(final DefaultDocumentEvent event) {
         return DefStyledDoc_Helpers.getEdits(event);
     }
 }
 /*
-The dump of the document after the initial set up.
+ The dump of the document after the initial set up.
 
-<section>
-  <paragraph
-    resolver=NamedStyle:default {name=default,}
-  >
-    <content>
-      [0,5][plain]
-    <content
-      bold=true
-    >
-      [5,9][bold]
-    <content
-      italic=true
-    >
-      [9,15][italic]
-    <content>
-      [15,16][
-]
-  <paragraph>
-    <content>
-      [16,21][text
-]
-<bidi root>
-  <bidi level
-    bidiLevel=0
-  >
-    [0,21][plainbolditalic
-text
-]
-*/
\ No newline at end of file
+ <section>
+ <paragraph
+ resolver=NamedStyle:default {name=default,}
+ >
+ <content>
+ [0,5][plain]
+ <content
+ bold=true
+ >
+ [5,9][bold]
+ <content
+ italic=true
+ >
+ [9,15][italic]
+ <content>
+ [15,16][
+ ]
+ <paragraph>
+ <content>
+ [16,21][text
+ ]
+ <bidi root>
+ <bidi level
+ bidiLevel=0
+ >
+ [0,21][plainbolditalic
+ text
+ ]
+ */
\ No newline at end of file



Mime
View raw message