]> source.dussan.org Git - poi.git/commitdiff
Bug 57480: Fix some unnecessary casts, generics, Eclipse warnings, ...
authorDominik Stadler <centic@apache.org>
Mon, 9 Feb 2015 22:33:24 +0000 (22:33 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 9 Feb 2015 22:33:24 +0000 (22:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1658594 13f79535-47bb-0310-9956-ffa450edef68

26 files changed:
src/java/org/apache/poi/hssf/dev/RecordLister.java
src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java
src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
src/java/org/apache/poi/hssf/model/DrawingManager.java
src/java/org/apache/poi/hssf/model/RowBlocksReader.java
src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
src/java/org/apache/poi/hssf/record/HorizontalPageBreakRecord.java
src/java/org/apache/poi/hssf/record/VerticalPageBreakRecord.java
src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java
src/java/org/apache/poi/hssf/record/chart/ChartTitleFormatRecord.java
src/java/org/apache/poi/hssf/usermodel/DummyGraphics2d.java
src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java
src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java
src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java
src/java/org/apache/poi/hssf/util/HSSFColor.java
src/java/org/apache/poi/ss/formula/functions/Code.java
src/java/org/apache/poi/ss/formula/functions/ImReal.java
src/java/org/apache/poi/ss/formula/functions/PPMT.java
src/java/org/apache/poi/ss/formula/functions/TextFunction.java
src/java/org/apache/poi/ss/usermodel/FractionFormat.java
src/java/org/apache/poi/ss/util/SheetReferences.java

index 40311678721466e3f468a84a1b24f96be243e848..28896f2a11ab9b7d4bc94178dc0b915587b76b69 100644 (file)
@@ -154,7 +154,7 @@ public class RecordLister
        return s.toString();
     }
     private static String byteToHex(byte b) {
-       int i = (int)b;
+       int i = b;
        if(i<0) {
           i += 256;
        }
index 1b36ffd76eb85cb2ccb12a1ba1e9ec2c112853ed..5d6562dd53f20f737cdb7d2f4402958a44dd178c 100644 (file)
@@ -92,11 +92,10 @@ public class HSSFRequest {
         * @throws HSSFUserException User exception condition
         */
        protected short processRecord(Record rec) throws HSSFUserException {
-               Object obj = _records.get(Short.valueOf(rec.getSid()));
+               List<HSSFListener> listeners = _records.get(Short.valueOf(rec.getSid()));
                short userCode = 0;
 
-               if (obj != null) {
-                       List listeners = (List) obj;
+               if (listeners != null) {
 
                        for (int k = 0; k < listeners.size(); k++) {
                                Object listenObj = listeners.get(k);
index 6d89a1f047d114adec55405bd1d082cb859f7437..889de20b4c5cb089d0202cbb905fba65ad50d0d6 100644 (file)
@@ -68,7 +68,6 @@ public class EventBasedExcelExtractor extends POIOLE2TextExtractor implements or
      * @deprecated Use {@link #EventBasedExcelExtractor(DirectoryNode)} instead
      */
     @Deprecated
-    @SuppressWarnings( "unused" )
     public EventBasedExcelExtractor( DirectoryNode dir, POIFSFileSystem fs )
     {
         this( dir );
index b620623595cc6847506d52b0c3a86dcfdd1ae576..57c6e01ca7520a62bf34e15acffa2a9f272390e7 100644 (file)
@@ -72,7 +72,6 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
      * @deprecated Use {@link #ExcelExtractor(DirectoryNode)} instead
      */
     @Deprecated
-    @SuppressWarnings( "unused" )
     public ExcelExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
         this( dir );
     }
@@ -241,6 +240,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
                        extractor.setIncludeBlankCells(cmdArgs.shouldShowBlankCells());
                        extractor.setIncludeHeadersFooters(cmdArgs.shouldIncludeHeadersFooters());
                        System.out.println(extractor.getText());
+                       extractor.close();
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(1);
index 5fecaaa52bb573b6df1a4fe9301c3919d393a30d..dd3a8daf82edf9919849570465c724a016391edb 100644 (file)
@@ -29,7 +29,7 @@ import java.util.HashMap;
 public class DrawingManager
 {
     EscherDggRecord dgg;
-    Map dgMap = new HashMap(); // key = Short(drawingId), value=EscherDgRecord
+    Map<Short, EscherDgRecord> dgMap = new HashMap<Short, EscherDgRecord>(); // key = Short(drawingId), value=EscherDgRecord
 
     public DrawingManager( EscherDggRecord dgg )
     {
@@ -46,7 +46,7 @@ public class DrawingManager
         dg.setLastMSOSPID( -1 );
         dgg.addCluster( dgId, 0 );
         dgg.setDrawingsSaved( dgg.getDrawingsSaved() + 1 );
-        dgMap.put( Short.valueOf( dgId ), dg );
+        dgMap.put( dgId, dg );
         return dg;
     }
 
@@ -58,7 +58,7 @@ public class DrawingManager
     public int allocateShapeId(short drawingGroupId)
     {
         // Get the last shape id for this drawing group.
-        EscherDgRecord dg = (EscherDgRecord) dgMap.get(Short.valueOf(drawingGroupId));
+        EscherDgRecord dg = dgMap.get(drawingGroupId);
         int lastShapeId = dg.getLastMSOSPID();
 
 
index 29a4ed22c1510ba3c0b69808d1f5b2b0c56f2fbc..f0b5d3107712730c0d685d48225fa9e6f395bd27 100644 (file)
@@ -36,7 +36,7 @@ import org.apache.poi.ss.util.CellReference;
  */
 public final class RowBlocksReader {
 
-       private final List _plainRecords;
+       private final List<Record> _plainRecords;
        private final SharedValueManager _sfm;
        private final MergeCellsRecord[] _mergedCellsRecords;
 
index eeddf5e21a692cb5b96353a32f42451dfde50b26..2304c047051f9aa8cbf2d3c7e753ef5949be73be 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.poi.hssf.record;
 
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.ddf.NullEscherSerializationListener;
-import org.apache.poi.util.ArrayUtil;
 import org.apache.poi.util.LittleEndian;
 
 import java.util.Iterator;
@@ -60,9 +59,9 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
         }
         byte[] buffer = new byte[getRawDataSize()];
         int pos = 0;
-        for ( Iterator iterator = getEscherRecords().iterator(); iterator.hasNext(); )
+        for ( Iterator<EscherRecord> iterator = getEscherRecords().iterator(); iterator.hasNext(); )
         {
-            EscherRecord r = (EscherRecord) iterator.next();
+            EscherRecord r = iterator.next();
             pos += r.serialize(pos, buffer, new NullEscherSerializationListener() );
         }
 
@@ -85,16 +84,16 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
     }
 
     private int getRawDataSize() {
-        List escherRecords = getEscherRecords();
+        List<EscherRecord> escherRecords = getEscherRecords();
         byte[] rawData = getRawData();
         if (escherRecords.size() == 0 && rawData != null)
         {
             return rawData.length;
         }
         int size = 0;
-        for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
+        for ( Iterator<EscherRecord> iterator = escherRecords.iterator(); iterator.hasNext(); )
         {
-            EscherRecord r = (EscherRecord) iterator.next();
+            EscherRecord r = iterator.next();
             size += r.getRecordSize();
         }
         return size;
index 63e757f8df2e97da021c01a74386b19605a6dde7..8077efe922d2cbbbf48ed970a991aa61601448e6 100644 (file)
@@ -50,9 +50,9 @@ public final class HorizontalPageBreakRecord extends PageBreakRecord {
 
        public Object clone() {
                PageBreakRecord result = new HorizontalPageBreakRecord();
-               Iterator iterator = getBreaksIterator();
+               Iterator<Break> iterator = getBreaksIterator();
                while (iterator.hasNext()) {
-                       Break original = (Break) iterator.next();
+                       Break original = iterator.next();
                        result.addBreak(original.main, original.subFrom, original.subTo);
                }
                return result;
index 3dc5348f971c83ec16dfe3fa22c1d5dc013541d1..399a96a46e2ca1edf468efc02f6bc9cf2e35d1dc 100644 (file)
@@ -49,9 +49,9 @@ public final class VerticalPageBreakRecord extends PageBreakRecord {
 
        public Object clone() {
                PageBreakRecord result = new VerticalPageBreakRecord();
-               Iterator iterator = getBreaksIterator();
+               Iterator<Break> iterator = getBreaksIterator();
                while (iterator.hasNext()) {
-                       Break original = (Break) iterator.next();
+                       Break original = iterator.next();
                        result.addBreak(original.main, original.subFrom, original.subTo);
                }
                return result;
index 588276274fd3a598c0c196672c14190d44ef5500..cc59338a5e109ff851a15bb7706568e45bf430bc 100644 (file)
@@ -32,13 +32,13 @@ import org.apache.poi.ss.util.CellRangeAddressList;
 public final class MergedCellsTable extends RecordAggregate {
        private static int MAX_MERGED_REGIONS = 1027; // enforced by the 8224 byte limit
 
-       private final List _mergedRegions;
+       private final List<CellRangeAddress> _mergedRegions;
 
        /**
         * Creates an empty aggregate
         */
        public MergedCellsTable() {
-               _mergedRegions = new ArrayList();
+               _mergedRegions = new ArrayList<CellRangeAddress>();
        }
 
        /**
@@ -46,7 +46,7 @@ public final class MergedCellsTable extends RecordAggregate {
         * @param rs
         */
        public void read(RecordStream rs) {
-               List temp = _mergedRegions;
+               List<CellRangeAddress> temp = _mergedRegions;
                while (rs.peekNextClass() == MergeCellsRecord.class) {
                        MergeCellsRecord mcr = (MergeCellsRecord) rs.getNext();
                        int nRegions = mcr.getNumAreas();
@@ -110,7 +110,7 @@ public final class MergedCellsTable extends RecordAggregate {
 
        public CellRangeAddress get(int index) {
                checkIndex(index);
-               return (CellRangeAddress) _mergedRegions.get(index);
+               return _mergedRegions.get(index);
        }
 
        public void remove(int index) {
index ac9859048a448be889eb5a61c16876b94b24f24a..f724aada3ac4570ff589ce6b10664f69518eb0bd 100644 (file)
@@ -38,11 +38,6 @@ public class ChartTitleFormatRecord extends StandardRecord {
                private int _offset;
                private int _fontIndex;
                
-               protected CTFormat(short offset,short fontIdx){
-                       _offset = offset;
-                       _fontIndex = fontIdx;
-               }
-               
                public CTFormat(RecordInputStream in) {
                        _offset = in.readShort();
                        _fontIndex = in.readShort();
index 42debc6d81f584b7d7e9dc523c47b99733480afe..beadac4646bff259e55e9b52a6ec960075980267 100644 (file)
@@ -42,7 +42,7 @@ public class DummyGraphics2d
         g2D = (Graphics2D)img.getGraphics();\r
     }\r
 \r
-    public void addRenderingHints(Map hints)\r
+    public void addRenderingHints(Map<?,?> hints)\r
     {\r
         System.out.println( "addRenderingHinds(Map):" );\r
         System.out.println( "  hints = " + hints );\r
@@ -275,7 +275,7 @@ public class DummyGraphics2d
         g2D.setRenderingHint( hintKey, hintValue );\r
     }\r
 \r
-    public void setRenderingHints(Map hints)\r
+    public void setRenderingHints(Map<?,?> hints)\r
     {\r
         System.out.println( "setRenderingHints(Map):" );\r
         System.out.println( "hints = " + hints );\r
index 4293587b38a5e29ff9cd5aa7ccab7a6255217d19..1f31e80bd67ba6544d0a44b3d9cb783731461c39 100644 (file)
@@ -431,7 +431,6 @@ public class EscherGraphics
         return null;
     }
 
-    @SuppressWarnings("deprecation")
     public Rectangle getClipRect()
     {
         return getClipBounds();
index 45306e89f0a5df9f7e668cd3f02c071d5231056f..949168aac109d6e31ae2dc12793d19bb8469d90a 100644 (file)
@@ -89,7 +89,7 @@ public final class EscherGraphics2d extends Graphics2D {
         setColor(Color.black);
     }
 
-    public void addRenderingHints(Map map)
+    public void addRenderingHints(Map<?, ?> map)
     {
         getG2D().addRenderingHints(map);
     }
@@ -514,7 +514,7 @@ public final class EscherGraphics2d extends Graphics2D {
         getG2D().setRenderingHint(key, obj);
     }
 
-    public void setRenderingHints(Map map)
+    public void setRenderingHints(Map<?, ?> map)
     {
         getG2D().setRenderingHints(map);
     }
index dc2a217330606e9e965dacaa765e862b4b01bfb7..b1cb174a99a6489095dce45ebdeb0bf0e3a6bc8f 100644 (file)
@@ -63,7 +63,6 @@ public final class HSSFDataFormat implements DataFormat {
        HSSFDataFormat(InternalWorkbook workbook) {
                _workbook = workbook;
 
-               @SuppressWarnings("unchecked")
                Iterator<FormatRecord> i = workbook.getFormats().iterator();
                while (i.hasNext()) {
                        FormatRecord r = i.next();
index 73b402facd2787affb0ddca58dd76084d5e12700..aed0c513fd0dbd524182d9c92d0d96101f92bd69 100644 (file)
@@ -309,7 +309,7 @@ public final class HSSFFont implements Font {
     {
         byte charset = font.getCharset();
         if(charset >= 0) {
-           return (int)charset;
+           return charset;
         } else {
            return charset + 256;
         }
index 96ab009748941b913001df3f07493930c73db45a..6ac5368402873b6e1727c7d7785bbbe8898b8078 100644 (file)
@@ -134,7 +134,7 @@ public final class HSSFPalette {
      *  0 and 255, so distance calculations work as expected.
      */
     private int unsignedInt(byte b) {
-       return 0xFF & ((int) b);
+       return 0xFF & b;
     }
 
     /**
index 67315f12af377efbf2dd6c5379fd02afdaf5840b..5b4a17ec855305cce771b16a78d5fed7bf0b69ae 100644 (file)
@@ -617,7 +617,7 @@ public final class HSSFRow implements Row {
      * Alias for {@link #cellIterator} to allow
      *  foreach loops
      */
-    public Iterator iterator() {
+    public Iterator<Cell> iterator() {
        return cellIterator();
     }
 
index 004b2f46069b6a1657bee960991181b619e976c1..66440005b26d059ce24f472049c8c746f6967395 100644 (file)
@@ -305,8 +305,8 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
      */
     public int countOfAllChildren() {
         int count = shapes.size();
-        for (Iterator iterator = shapes.iterator(); iterator.hasNext(); ) {
-            HSSFShape shape = (HSSFShape) iterator.next();
+        for (Iterator<HSSFShape> iterator = shapes.iterator(); iterator.hasNext(); ) {
+            HSSFShape shape = iterator.next();
             count += shape.countOfAllChildren();
         }
         return count;
index 493db7f38f7073685130f85e8cce821f55588f17..f438e1b0015d409ff512c2f527bd6bd0e1309313 100644 (file)
@@ -75,7 +75,7 @@ public class HSSFColor implements Color {
 
             Integer index1 = Integer.valueOf(color.getIndex());
             if (result.containsKey(index1)) {
-                HSSFColor prevColor = (HSSFColor)result.get(index1);
+                HSSFColor prevColor = result.get(index1);
                 throw new RuntimeException("Dup color index (" + index1
                         + ") for colors (" + prevColor.getClass().getName()
                         + "),(" + color.getClass().getName() + ")");
index c82bff7547bc8aad56f9ec79084f3d23f4b670a5..ee1622f584d2069b327670b142c42b2c4e99e6da 100644 (file)
@@ -46,7 +46,7 @@ public class Code extends Fixed1ArgFunction {
             return ErrorEval.VALUE_INVALID;\r
         }\r
 \r
-        int code = (int)text.charAt(0);\r
+        int code = text.charAt(0);\r
 \r
         return new StringEval(String.valueOf(code));\r
     }\r
index 394865fdd9677979836ce5555c95ea0472734cbf..f7c17adef1cabe6008c772df6f3bdb05d3aa061d 100644 (file)
 \r
 package org.apache.poi.ss.formula.functions;\r
 \r
-import org.apache.poi.ss.formula.OperationEvaluationContext;\r
-import org.apache.poi.ss.formula.eval.*;\r
-\r
 import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
+\r
+import org.apache.poi.ss.formula.OperationEvaluationContext;\r
+import org.apache.poi.ss.formula.eval.ErrorEval;\r
+import org.apache.poi.ss.formula.eval.EvaluationException;\r
+import org.apache.poi.ss.formula.eval.OperandResolver;\r
+import org.apache.poi.ss.formula.eval.StringEval;\r
+import org.apache.poi.ss.formula.eval.ValueEval;\r
 \r
 /**\r
  * Implementation for Excel ImReal() function.<p/>\r
index 68b86833236bb452a269654f62f0de90b3f1930f..2df2304db185993f651f7739c32d16c54750e4ac 100644 (file)
@@ -19,8 +19,6 @@
 
 package org.apache.poi.ss.formula.functions;
 
-import org.apache.poi.ss.formula.*;
-import org.apache.poi.ss.formula.functions.*;
 import org.apache.poi.ss.formula.eval.*;
 
 /**
index c09df12d1cab53758b6a59444450f594642e8b3b..ca69b27f7232940b8676d73d8deeadad27b51cf7 100644 (file)
@@ -182,7 +182,7 @@ public abstract class TextFunction implements Function {
          * @return  whether the character is printable
          */
         private boolean isPrintable(char c){
-            int charCode = (int)c ;
+            int charCode = c;
             return charCode >= 32;
         }
     };
index 43564c885499dd183476236b9b7031e9c8d3b4a5..202ccdae229dbdf1e2d33ae973e61c236a815e8d 100644 (file)
@@ -130,7 +130,7 @@ public class FractionFormat extends Format {
             if (exactDenom > 0){\r
                 fract = SimpleFraction.buildFractionExactDenominator(decPart, exactDenom);\r
             } else {\r
-                fract = SimpleFraction.buildFractionMaxDenominator((double)decPart, maxDenom);\r
+                fract = SimpleFraction.buildFractionMaxDenominator(decPart, maxDenom);\r
             }\r
         } catch (RuntimeException e){\r
             e.printStackTrace();\r
index 028538a89d792b18cd4a4b15bcbf4acf28cb04d5..a7542763dae96961c71a8cc33171a9a0f1a37eec 100644 (file)
@@ -29,17 +29,17 @@ import java.util.Map;
  */
 public class SheetReferences
 {
-    Map map;
+    Map<Integer, String> map;
     public SheetReferences()
     {
-      map = new HashMap(5);
+      map = new HashMap<Integer, String>(5);
     }
 
     public void addSheetReference(String sheetName, int number) {
-       map.put(Integer.valueOf(number), sheetName);
+       map.put(number, sheetName);
     }
 
     public String getSheetName(int number) {
-       return (String)map.get(Integer.valueOf(number));
+       return map.get(number);
     }
 }