]> source.dussan.org Git - poi.git/commitdiff
hwpf.usermodel.Range: use generics & remove redundant type casts
authorMaxim Valyanskiy <maxcom@apache.org>
Wed, 7 Jul 2010 10:57:14 +0000 (10:57 +0000)
committerMaxim Valyanskiy <maxcom@apache.org>
Wed, 7 Jul 2010 10:57:14 +0000 (10:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@961347 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java

index 86f8bb54fa63e21b6a33aa95882e9c17472d0550..d2f9332a50118b31384b6e06086565ea4cdf1956 100644 (file)
@@ -22,11 +22,6 @@ import org.apache.poi.util.LittleEndian;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFDocumentCore;
 
-import org.apache.poi.hwpf.usermodel.CharacterRun;
-import org.apache.poi.hwpf.usermodel.Paragraph;
-import org.apache.poi.hwpf.usermodel.ParagraphProperties;
-import org.apache.poi.hwpf.usermodel.Section;
-
 import org.apache.poi.hwpf.model.CPSplitCalculator;
 import org.apache.poi.hwpf.model.FileInformationBlock;
 import org.apache.poi.hwpf.model.PropertyNode;
@@ -84,7 +79,7 @@ public class Range { // TODO -instantiable superclass
        boolean _sectionRangeFound;
 
        /** All sections that belong to the document this Range belongs to. */
-       protected List _sections;
+       protected List<SEPX> _sections;
 
        /** The start index in the sections list for this Range */
        protected int _sectionStart;
@@ -96,7 +91,7 @@ public class Range { // TODO -instantiable superclass
        protected boolean _parRangeFound;
 
        /** All paragraphs that belong to the document this Range belongs to. */
-       protected List _paragraphs;
+       protected List<PAPX> _paragraphs;
 
        /** The start index in the paragraphs list for this Range */
        protected int _parStart;
@@ -108,7 +103,7 @@ public class Range { // TODO -instantiable superclass
        protected boolean _charRangeFound;
 
        /** All CharacterRuns that belong to the document this Range belongs to. */
-       protected List _characters;
+       protected List<CHPX> _characters;
 
        /** The start index in the characterRuns list for this Range */
        protected int _charStart;
@@ -120,7 +115,7 @@ public class Range { // TODO -instantiable superclass
        protected boolean _textRangeFound;
 
        /** All text pieces that belong to the document this Range belongs to. */
-       protected List _text;
+       protected List<TextPiece> _text;
 
        /** The start index in the text list for this Range. */
        protected int _textStart;
@@ -206,29 +201,29 @@ public class Range { // TODO -instantiable superclass
                        case TYPE_PARAGRAPH:
                                _parStart = parent._parStart + startIdx;
                                _parEnd = parent._parStart + endIdx;
-                               _start = ((PropertyNode) _paragraphs.get(_parStart)).getStart();
-                               _end = ((PropertyNode) _paragraphs.get(_parEnd)).getEnd();
+                               _start = _paragraphs.get(_parStart).getStart();
+                               _end = _paragraphs.get(_parEnd).getEnd();
                                _parRangeFound = true;
                                break;
                        case TYPE_CHARACTER:
                                _charStart = parent._charStart + startIdx;
                                _charEnd = parent._charStart + endIdx;
-                               _start = ((PropertyNode) _characters.get(_charStart)).getStart();
-                               _end = ((PropertyNode) _characters.get(_charEnd)).getEnd();
+                               _start = _characters.get(_charStart).getStart();
+                               _end = _characters.get(_charEnd).getEnd();
                                _charRangeFound = true;
                                break;
                        case TYPE_SECTION:
                                _sectionStart = parent._sectionStart + startIdx;
                                _sectionEnd = parent._sectionStart + endIdx;
-                               _start = ((PropertyNode) _sections.get(_sectionStart)).getStart();
-                               _end = ((PropertyNode) _sections.get(_sectionEnd)).getEnd();
+                               _start = _sections.get(_sectionStart).getStart();
+                               _end = _sections.get(_sectionEnd).getEnd();
                                _sectionRangeFound = true;
                                break;
                        case TYPE_TEXT:
                                _textStart = parent._textStart + startIdx;
                                _textEnd = parent._textStart + endIdx;
-                               _start = ((PropertyNode) _text.get(_textStart)).getStart();
-                               _end = ((PropertyNode) _text.get(_textEnd)).getEnd();
+                               _start = _text.get(_textStart).getStart();
+                               _end = _text.get(_textEnd).getEnd();
                                _textRangeFound = true;
                                break;
                }
@@ -260,7 +255,7 @@ public class Range { // TODO -instantiable superclass
                initText();
 
                for (int i = _textStart; i < _textEnd; i++) {
-                       TextPiece piece = (TextPiece) _text.get(i);
+                       TextPiece piece = _text.get(i);
                        if (piece.isUnicode())
                                return true;
                }
@@ -279,7 +274,7 @@ public class Range { // TODO -instantiable superclass
                StringBuffer sb = new StringBuffer();
 
                for (int x = _textStart; x < _textEnd; x++) {
-                       TextPiece piece = (TextPiece) _text.get(x);
+                       TextPiece piece = _text.get(x);
 
                        // Figure out where in this piece the text
                        // we're after lives
@@ -396,7 +391,7 @@ public class Range { // TODO -instantiable superclass
        {
                initAll();
 
-               TextPiece tp = (TextPiece) _text.get(_textStart);
+               TextPiece tp = _text.get(_textStart);
                StringBuffer sb = tp.getStringBuffer();
 
                // Since this is the first item in our list, it is safe to assume that
@@ -427,7 +422,7 @@ public class Range { // TODO -instantiable superclass
                initAll();
 
                int listIndex = _textEnd - 1;
-               TextPiece tp = (TextPiece) _text.get(listIndex);
+               TextPiece tp = _text.get(listIndex);
                StringBuffer sb = tp.getStringBuffer();
 
                int insertIndex = _end - tp.getStart();
@@ -461,7 +456,7 @@ public class Range { // TODO -instantiable superclass
        // throws UnsupportedEncodingException
        {
                initAll();
-               PAPX papx = (PAPX) _paragraphs.get(_parStart);
+               PAPX papx = _paragraphs.get(_parStart);
                short istd = papx.getIstd();
 
                StyleSheet ss = _doc.getStyleSheet();
@@ -488,7 +483,7 @@ public class Range { // TODO -instantiable superclass
        // throws UnsupportedEncodingException
        {
                initAll();
-               PAPX papx = (PAPX) _paragraphs.get(_parEnd - 1);
+               PAPX papx = _paragraphs.get(_parEnd - 1);
                short istd = papx.getIstd();
 
                StyleSheet ss = _doc.getStyleSheet();
@@ -610,12 +605,12 @@ public class Range { // TODO -instantiable superclass
                int numTextPieces = _text.size();
 
                for (int x = _charStart; x < numRuns; x++) {
-                       CHPX chpx = (CHPX) _characters.get(x);
+                       CHPX chpx = _characters.get(x);
                        chpx.adjustForDelete(_start, _end - _start);
                }
 
                for (int x = _parStart; x < numParagraphs; x++) {
-                       PAPX papx = (PAPX) _paragraphs.get(x);
+                       PAPX papx = _paragraphs.get(x);
                        // System.err.println("Paragraph " + x + " was " + papx.getStart() +
                        // " -> " + papx.getEnd());
                        papx.adjustForDelete(_start, _end - _start);
@@ -624,7 +619,7 @@ public class Range { // TODO -instantiable superclass
                }
 
                for (int x = _sectionStart; x < numSections; x++) {
-                       SEPX sepx = (SEPX) _sections.get(x);
+                       SEPX sepx = _sections.get(x);
                        // System.err.println("Section " + x + " was " + sepx.getStart() +
                        // " -> " + sepx.getEnd());
                        sepx.adjustForDelete(_start, _end - _start);
@@ -633,7 +628,7 @@ public class Range { // TODO -instantiable superclass
                }
 
                for (int x = _textStart; x < numTextPieces; x++) {
-                       TextPiece piece = (TextPiece) _text.get(x);
+                       TextPiece piece = _text.get(x);
                        piece.adjustForDelete(_start, _end - _start);
                }
 
@@ -788,11 +783,11 @@ public class Range { // TODO -instantiable superclass
         */
        public CharacterRun getCharacterRun(int index) {
                initCharacterRuns();
-               CHPX chpx = (CHPX) _characters.get(index + _charStart);
+               CHPX chpx = _characters.get(index + _charStart);
 
                int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start), chpx
                                .getEnd());
-               PAPX papx = (PAPX) _paragraphs.get(point[0]);
+               PAPX papx = _paragraphs.get(point[0]);
                short istd = papx.getIstd();
 
                CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
@@ -809,7 +804,7 @@ public class Range { // TODO -instantiable superclass
         */
        public Section getSection(int index) {
                initSections();
-               SEPX sepx = (SEPX) _sections.get(index + _sectionStart);
+               SEPX sepx = _sections.get(index + _sectionStart);
                Section sep = new Section(sepx, this);
                return sep;
        }
@@ -824,7 +819,7 @@ public class Range { // TODO -instantiable superclass
 
        public Paragraph getParagraph(int index) {
                initParagraphs();
-               PAPX papx = (PAPX) _paragraphs.get(index + _parStart);
+               PAPX papx = _paragraphs.get(index + _parStart);
 
                ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
                Paragraph pap = null;
@@ -1060,17 +1055,14 @@ public class Range { // TODO -instantiable superclass
        }
 
        public int getStartOffset() {
-
                return _start;
        }
 
        public int getEndOffset() {
-
                return _end;
        }
 
        protected HWPFDocumentCore getDocument() {
-
                return _doc;
        }
 }