Skip to content

Commit ab899bc

Browse files
Fix some Java warnings detected by IntelliJ.
1 parent d27b86d commit ab899bc

4 files changed

Lines changed: 22 additions & 40 deletions

File tree

openpdf-html/src/main/java/org/openpdf/css/style/derived/LengthValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public static float calcFloatProportionalValue(CalculatedStyle style,
183183
"'" + ValueConstants.stringForSACPrimitiveType(primitiveType) + "' "
184184
+ primitiveType + "(" + stringValue + ")");
185185
}
186-
//assert (new Float(absVal).intValue() >= 0);
187186

188187
if (XRLog.isLoggingEnabled()) {
189188
if (cssName == CSSName.FONT_SIZE) {

openpdf-renderer/src/main/java/org/openpdf/renderer/PDFObject.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public class PDFObject {
123123
* for dereferencing. This may be null.
124124
* @param type the type of object
125125
* @param value the value. For DICTIONARY, this is a HashMap.
126-
* for ARRAY it's an ArrayList. For NUMBER, it's a Double.
126+
* for ARRAY, it's an ArrayList. For NUMBER, it's a Double.
127127
* for BOOLEAN, it's Boolean.TRUE or Boolean.FALSE. For
128128
* everything else, it's a String.
129129
*/
@@ -173,12 +173,11 @@ public PDFObject(Object obj) throws PDFParseException {
173173
this.type = DICTIONARY;
174174
} else if (obj instanceof Boolean) {
175175
this.type = BOOLEAN;
176-
} else if (obj instanceof PDFParser.Tok) {
177-
PDFParser.Tok tok = (PDFParser.Tok) obj;
178-
if (tok!=null && tok.name!=null && tok.name.equals("true")) {
176+
} else if (obj instanceof PDFParser.Tok tok) {
177+
if (tok.name != null && tok.name.equals("true")) {
179178
this.value = Boolean.TRUE;
180179
this.type = BOOLEAN;
181-
} else if (tok!=null && tok.name!=null && tok.name.equals("false")) {
180+
} else if (tok.name != null && tok.name.equals("false")) {
182181
this.value = Boolean.FALSE;
183182
this.type = BOOLEAN;
184183
} else {
@@ -341,7 +340,6 @@ public Object getCache() throws IOException {
341340
public void setCache(Object obj) throws IOException {
342341
if (type == INDIRECT) {
343342
dereference().setCache(obj);
344-
return;
345343
} else {
346344
cache = new SoftReference<Object>(obj);
347345
}
@@ -352,12 +350,11 @@ public byte[] getStream(Set<String> filterLimits) throws IOException
352350
if (type == INDIRECT) {
353351
return dereference().getStream(filterLimits);
354352
} else if (type == STREAM && stream != null) {
355-
byte[] data = null;
353+
byte[] data;
356354

357355
synchronized (stream) {
358356
// decode
359357
ByteBuffer streamBuf = decodeStream(filterLimits);
360-
// ByteBuffer streamBuf = stream;
361358

362359
// First try to use the array with no copying. This can only
363360
// be done if the buffer has a backing array, and is not a slice
@@ -443,8 +440,8 @@ private ByteBuffer decodeStream(Set<String> filterLimits) throws IOException {
443440
if (outStream == null) {
444441
stream.rewind();
445442
outStream = PDFDecoder.decodeStream(this, stream, filterLimits);
446-
decodedStreamFilterLimits = new HashSet<String>(filterLimits);
447-
decodedStream = new SoftReference(outStream);
443+
decodedStreamFilterLimits = new HashSet<>(filterLimits);
444+
decodedStream = new SoftReference<>(outStream);
448445
}
449446

450447
return outStream;
@@ -520,7 +517,7 @@ public String getStringValue() throws IOException {
520517

521518
/**
522519
* Get the value as a text string; i.e., a string encoded in UTF-16BE
523-
* or PDFDocEncoding. Simple latin alpha-numeric characters are preserved in
520+
* or PDFDocEncoding. Simple latin alphanumeric characters are preserved in
524521
* both these encodings.
525522
* @return the text string value
526523
* @throws IOException
@@ -538,8 +535,7 @@ public PDFObject[] getArray() throws IOException {
538535
if (type == INDIRECT) {
539536
return dereference().getArray();
540537
} else if (type == ARRAY) {
541-
PDFObject[] ary = (PDFObject[]) value;
542-
return ary;
538+
return (PDFObject[]) value;
543539
} else {
544540
PDFObject[] ary = new PDFObject[1];
545541
ary[0] = this;
@@ -592,7 +588,7 @@ public Iterator getDictKeys() throws IOException {
592588
}
593589

594590
// wrong type
595-
return new ArrayList().iterator();
591+
return Collections.emptyIterator();
596592
}
597593

598594
/**
@@ -607,7 +603,7 @@ public HashMap<String,PDFObject> getDictionary() throws IOException {
607603
}
608604

609605
// wrong type
610-
return new HashMap<String,PDFObject>();
606+
return new HashMap<>();
611607
}
612608

613609
/**
@@ -621,8 +617,7 @@ public PDFObject getDictRef(String key) throws IOException {
621617
} else if (type == DICTIONARY || type == STREAM) {
622618
key = key.intern();
623619
HashMap h = (HashMap) value;
624-
PDFObject obj = (PDFObject) h.get(key.intern());
625-
return obj;
620+
return (PDFObject) h.get(key.intern());
626621
}
627622

628623
// wrong type
@@ -711,7 +706,7 @@ public String toString() {
711706
try {
712707
str.append("\n" + dereference().toString());
713708
} catch (Throwable t) {
714-
str.append(t.toString());
709+
str.append(t);
715710
}
716711
return str.toString();
717712
} else if (type == BOOLEAN) {
@@ -753,21 +748,11 @@ public String toString() {
753748
if (st == null) {
754749
return "Broken stream";
755750
}
756-
return "Stream: [[" + new String(st, 0, st.length > 30 ? 30 : st.length) + "]]";
751+
return "Stream: [[" + new String(st, 0, Math.min(st.length, 30)) + "]]";
757752
} else if (type == NULL) {
758753
return "Null";
759754
} else if (type == KEYWORD) {
760755
return "Keyword: " + getStringValue();
761-
/* } else if (type==IMAGE) {
762-
StringBuffer sb= new StringBuffer();
763-
java.awt.Image im= (java.awt.Image)stream;
764-
sb.append("Image ("+im.getWidth(null)+"x"+im.getHeight(null)+", with keys:");
765-
HashMap hm= (HashMap)value;
766-
Iterator it= hm.keySet().iterator();
767-
while(it.hasNext()) {
768-
sb.append(" "+(String)it.next());
769-
}
770-
return sb.toString();*/
771756
} else {
772757
return "Whoops! big error! Unknown type";
773758
}
@@ -796,7 +781,7 @@ public PDFObject dereference() throws IOException {
796781

797782
obj = owner.dereference((PDFXref)value, getDecrypter());
798783

799-
cache = new SoftReference<PDFObject>(obj);
784+
cache = new SoftReference<>(obj);
800785
}
801786

802787
return obj;
@@ -824,9 +809,8 @@ public boolean equals(Object o) {
824809
if (super.equals(o)) {
825810
// they are the same object
826811
return true;
827-
} else if (type == INDIRECT && o instanceof PDFObject) {
812+
} else if (type == INDIRECT && o instanceof PDFObject obj) {
828813
// they are both PDFObjects. Check type and xref.
829-
PDFObject obj = (PDFObject) o;
830814

831815
if (obj.type == INDIRECT) {
832816
PDFXref lXref = (PDFXref) value;
@@ -842,7 +826,6 @@ public boolean equals(Object o) {
842826

843827
/**
844828
* Returns the root of this object.
845-
* @return
846829
*/
847830
public PDFObject getRoot() {
848831
return owner.getRoot();

openpdf-renderer/src/main/java/org/openpdf/renderer/font/CIDFontType2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void parseWidths(PDFObject fontObj)
125125

126126
// value is width / default width
127127
float value = entries[c].getIntValue();
128-
this.widths.put(key, new Float(value));
128+
this.widths.put(key, value);
129129
}
130130
// all done
131131
entryIdx = -1;
@@ -138,7 +138,7 @@ private void parseWidths(PDFObject fontObj)
138138

139139
// set the range
140140
for (int c = first; c <= last; c++) {
141-
this.widths.put(Character.valueOf((char) c), new Float(value));
141+
this.widths.put(Character.valueOf((char) c), Float.valueOf(value));
142142
}
143143

144144
// all done
@@ -188,7 +188,7 @@ private void parseWidths(PDFObject fontObj)
188188

189189
// value is width / default width
190190
float value = entries[c].getIntValue();
191-
this.widthsVertical.put(key, new Float(value));
191+
this.widthsVertical.put(key, value);
192192
}
193193
// all done
194194
entryIdx = -1;
@@ -201,7 +201,7 @@ private void parseWidths(PDFObject fontObj)
201201

202202
// set the range
203203
for (int c = first; c <= last; c++) {
204-
this.widthsVertical.put(Character.valueOf((char) c), new Float(value));
204+
this.widthsVertical.put(Character.valueOf((char) c), Float.valueOf(value));
205205
}
206206

207207
// all done

openpdf-renderer/src/main/java/org/openpdf/renderer/function/FunctionType4.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ private void prepareResult(float[] outputs, int outputOffset) {
101101
************************************************************************/
102102

103103
private void prepareInitialStack(float[] inputs, int inputOffset) {
104-
this.stack = new Stack<Object>();
104+
this.stack = new Stack<>();
105105
for (int i = inputOffset; i < inputs.length; i++) {
106-
this.stack.push(new Double(inputs[i]));
106+
this.stack.push(inputs[i]);
107107
}
108108
}
109109

0 commit comments

Comments
 (0)