Skip to content

Commit 6af81c0

Browse files
committed
Add generic type arguments to CSS packages.
Also, IDE fixes, such as removing unneeded casts and adding override annotation. In preparation of working on #423
1 parent 73a26c9 commit 6af81c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+502
-295
lines changed

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/CSSName.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ private CSSName(
18341834
*
18351835
* @return a string representation of the object.
18361836
*/
1837+
@Override
18371838
public String toString() {
18381839
return this.propName;
18391840
}
@@ -1921,7 +1922,7 @@ private static synchronized CSSName addProperty(
19211922
* Adds a feature to the Property attribute of the CSSName class
19221923
*
19231924
* @param propName The feature to be added to the Property attribute
1924-
* @param type
1925+
* @param type
19251926
* @param initialValue
19261927
* @param inherit
19271928
* @param implemented
@@ -1959,6 +1960,7 @@ private static synchronized CSSName addProperty(
19591960

19601961
static {
19611962
CSSParser parser = new CSSParser(new CSSErrorHandler() {
1963+
@Override
19621964
public void error(String uri, String message) {
19631965
XRLog.cssParse("(" + uri + ") " + message);
19641966
}

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/IdentValue.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ private final static IdentValue addValue(String ident) {
323323
* Most of these throw exceptions--makes use of the interface easier in CS (avoids casting)
324324
*/
325325

326+
@Override
326327
public boolean isDeclaredInherit() {
327328
return this == INHERIT;
328329
}
@@ -331,42 +332,51 @@ public FSDerivedValue computedValue() {
331332
return this;
332333
}
333334

335+
@Override
334336
public float asFloat() {
335337
throw new XRRuntimeException("Ident value is never a float; wrong class used for derived value.");
336338
}
337339

340+
@Override
338341
public FSColor asColor() {
339342
throw new XRRuntimeException("Ident value is never a color; wrong class used for derived value.");
340343
}
341344

345+
@Override
342346
public float getFloatProportionalTo(CSSName cssName,
343347
float baseValue,
344348
CssContext ctx) {
345349
throw new XRRuntimeException("Ident value (" + toString() + ") is never a length; wrong class used for derived value.");
346350
}
347351

352+
@Override
348353
public String asString() {
349354
return toString();
350355
}
351356

357+
@Override
352358
public String[] asStringArray() {
353359
throw new XRRuntimeException("Ident value is never a string array; wrong class used for derived value.");
354360
}
355361

362+
@Override
356363
public IdentValue asIdentValue() {
357364
return this;
358365
}
359366

367+
@Override
360368
public boolean hasAbsoluteUnit() {
361369
// log and return false
362370
throw new XRRuntimeException("Ident value is never an absolute unit; wrong class used for derived value; this " +
363371
"ident value is a " + this.asString());
364372
}
365373

374+
@Override
366375
public boolean isIdent() {
367376
return true;
368377
}
369378

379+
@Override
370380
public boolean isDependentOnFontSize() {
371381
return false;
372382
}

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/Idents.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,44 +82,44 @@ public final class Idents {
8282
/**
8383
* Description of the Field
8484
*/
85-
private final static Map COLOR_MAP;
85+
private final static Map<String, String> COLOR_MAP;
8686
/**
8787
* Description of the Field
8888
*/
89-
private final static Map FONT_SIZES;
89+
private final static Map<String, String> FONT_SIZES;
9090
/**
9191
* Description of the Field
9292
*/
93-
private final static Map FONT_WEIGHTS;
93+
private final static Map<String, String> FONT_WEIGHTS;
9494
/**
9595
* Description of the Field
9696
*/
97-
private final static Map BORDER_WIDTHS;
97+
private final static Map<String, String> BORDER_WIDTHS;
9898
/**
9999
* Description of the Field
100100
*/
101-
private final static Map BACKGROUND_POSITIONS;
101+
private final static Map<String, String> BACKGROUND_POSITIONS;
102102
/**
103103
* Description of the Field
104104
*/
105-
private final static List BACKGROUND_REPEATS;
105+
private final static List<String> BACKGROUND_REPEATS;
106106
/**
107107
* Description of the Field
108108
*/
109-
private final static List BORDER_STYLES;
109+
private final static List<String> BORDER_STYLES;
110110
/**
111111
* Description of the Field
112112
*/
113-
private final static List LIST_TYPES;
113+
private final static List<String> LIST_TYPES;
114114
/**
115115
* Description of the Field
116116
*/
117-
private final static List FONT_STYLES;
117+
private final static List<String> FONT_STYLES;
118118

119119
/**
120120
* Description of the Field
121121
*/
122-
private final static List BACKGROUND_POSITIONS_IDENTS;
122+
private final static List<String> BACKGROUND_POSITIONS_IDENTS;
123123

124124
/**
125125
* Description of the Method
@@ -136,13 +136,13 @@ public static String convertIdent(CSSName cssName, String ident) {
136136
String val = ident;
137137

138138
if (cssName == CSSName.FONT_SIZE) {
139-
String size = (String) FONT_SIZES.get(ident);
139+
String size = FONT_SIZES.get(ident);
140140
val = (size == null ? ident : size);
141141
} else if (cssName == CSSName.FONT_WEIGHT) {
142-
String size = (String) FONT_WEIGHTS.get(ident);
142+
String size = FONT_WEIGHTS.get(ident);
143143
val = (size == null ? ident : size);
144144
} else if (cssName == CSSName.BACKGROUND_POSITION) {
145-
String pos = (String) BACKGROUND_POSITIONS.get(ident);
145+
String pos = BACKGROUND_POSITIONS.get(ident);
146146
val = (pos == null ? ident : pos);
147147
} else if (
148148
cssName == CSSName.BORDER_BOTTOM_WIDTH ||
@@ -151,7 +151,7 @@ public static String convertIdent(CSSName cssName, String ident) {
151151
cssName == CSSName.BORDER_WIDTH_SHORTHAND ||
152152
cssName == CSSName.BORDER_TOP_WIDTH) {
153153

154-
String size = (String) BORDER_WIDTHS.get(ident);
154+
String size = BORDER_WIDTHS.get(ident);
155155
val = (size == null ? ident : size);
156156
} else if (
157157
cssName == CSSName.BORDER_BOTTOM_COLOR ||
@@ -350,7 +350,7 @@ public static String getColorHex(String value) {
350350
if (value == null) {
351351
throw new XRRuntimeException("value is null on getColorHex()");
352352
}
353-
String retval = (String) COLOR_MAP.get(value.toLowerCase());
353+
String retval = COLOR_MAP.get(value.toLowerCase());
354354
if (retval == null) {
355355
if (value.trim().startsWith("rgb(")) {
356356
retval = value;
@@ -365,7 +365,7 @@ public static String getColorHex(String value) {
365365
}
366366

367367
static {
368-
COLOR_MAP = new HashMap();
368+
COLOR_MAP = new HashMap<>();
369369
/* From CSS 2.1- 4.3.6: Colors
370370
aqua #00ffff
371371
black #000000
@@ -405,7 +405,7 @@ public static String getColorHex(String value) {
405405
COLOR_MAP.put("yellow", "#ffff00");
406406

407407
//TODO: FONT_SIZES should be determined by the User Interface!
408-
FONT_SIZES = new HashMap();
408+
FONT_SIZES = new HashMap<>();
409409
FONT_SIZES.put("xx-small", "6.9pt");
410410
FONT_SIZES.put("x-small", "8.3pt");
411411
FONT_SIZES.put("small", "10pt");
@@ -418,7 +418,7 @@ public static String getColorHex(String value) {
418418
FONT_SIZES.put("smaller", "0.8em");
419419
FONT_SIZES.put("larger", "1.2em");
420420

421-
FONT_WEIGHTS = new HashMap();
421+
FONT_WEIGHTS = new HashMap<>();
422422
FONT_WEIGHTS.put("normal", "400");
423423
FONT_WEIGHTS.put("bold", "700");
424424
FONT_WEIGHTS.put("100", "100");
@@ -434,18 +434,18 @@ public static String getColorHex(String value) {
434434
FONT_WEIGHTS.put("lighter", "lighter");
435435
// NOTE: 'bolder' and 'lighter' need to be handled programmatically
436436

437-
BORDER_WIDTHS = new HashMap();
437+
BORDER_WIDTHS = new HashMap<>();
438438
BORDER_WIDTHS.put("thin", "1px");
439439
BORDER_WIDTHS.put("medium", "2px");
440440
BORDER_WIDTHS.put("thick", "3px");
441441

442-
BACKGROUND_POSITIONS_IDENTS = new ArrayList();
442+
BACKGROUND_POSITIONS_IDENTS = new ArrayList<>();
443443
BACKGROUND_POSITIONS_IDENTS.add("top");
444444
BACKGROUND_POSITIONS_IDENTS.add("center");
445445
BACKGROUND_POSITIONS_IDENTS.add("bottom");
446446
BACKGROUND_POSITIONS_IDENTS.add("right");
447447
BACKGROUND_POSITIONS_IDENTS.add("left");
448-
BACKGROUND_POSITIONS = new HashMap();
448+
BACKGROUND_POSITIONS = new HashMap<>();
449449

450450
// NOTE: combinations of idents for background-positions, are specified in the CSS
451451
// spec; some are disallowed, for example, there is no "top" all by itself. Check
@@ -478,13 +478,13 @@ public static String getColorHex(String value) {
478478
BACKGROUND_POSITIONS.put("bottom right", "100% 100%");
479479
BACKGROUND_POSITIONS.put("right bottom", "100% 100%");
480480

481-
BACKGROUND_REPEATS = new ArrayList();
481+
BACKGROUND_REPEATS = new ArrayList<>();
482482
BACKGROUND_REPEATS.add("repeat");
483483
BACKGROUND_REPEATS.add("repeat-x");
484484
BACKGROUND_REPEATS.add("repeat-y");
485485
BACKGROUND_REPEATS.add("no-repeat");
486486

487-
BORDER_STYLES = new ArrayList();
487+
BORDER_STYLES = new ArrayList<>();
488488
BORDER_STYLES.add("none");
489489
BORDER_STYLES.add("hidden");
490490
BORDER_STYLES.add("dotted");
@@ -496,7 +496,7 @@ public static String getColorHex(String value) {
496496
BORDER_STYLES.add("inset");
497497
BORDER_STYLES.add("outset");
498498

499-
LIST_TYPES = new ArrayList();
499+
LIST_TYPES = new ArrayList<>();
500500
LIST_TYPES.add("disc");
501501
LIST_TYPES.add("circle");
502502
LIST_TYPES.add("square");
@@ -519,7 +519,7 @@ public static String getColorHex(String value) {
519519
LIST_TYPES.add("katakana-iroha");
520520
LIST_TYPES.add("none");
521521

522-
FONT_STYLES = new ArrayList();
522+
FONT_STYLES = new ArrayList<>();
523523
FONT_STYLES.add("normal");
524524
FONT_STYLES.add("italic");
525525
FONT_STYLES.add("oblique");

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/MarginBoxName.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Map;
2424

2525
public class MarginBoxName {
26-
private static final Map ALL = new HashMap();
26+
private static final Map<String, MarginBoxName> ALL = new HashMap<>();
2727
private static int _maxAssigned = 0;
2828

2929
public final int FS_ID;
@@ -68,18 +68,21 @@ private final static MarginBoxName addValue(String ident, IdentValue textAlign,
6868
return val;
6969
}
7070

71+
@Override
7172
public String toString() {
7273
return _ident;
7374
}
7475

7576
public static MarginBoxName valueOf(String ident) {
76-
return (MarginBoxName)ALL.get(ident);
77+
return ALL.get(ident);
7778
}
7879

80+
@Override
7981
public int hashCode() {
8082
return FS_ID;
8183
}
8284

85+
@Override
8386
public boolean equals(Object o) {
8487
if (o == null || ! (o instanceof MarginBoxName)) {
8588
return false;

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/PageElementPosition.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Map;
2424

2525
public class PageElementPosition {
26-
private static final Map ALL = new HashMap();
26+
private static final Map<String, PageElementPosition> ALL = new HashMap<>();
2727
private static int _maxAssigned = 0;
2828

2929
public final int FS_ID;
@@ -46,18 +46,21 @@ private final static PageElementPosition addValue(String ident) {
4646
return val;
4747
}
4848

49+
@Override
4950
public String toString() {
5051
return _ident;
5152
}
5253

5354
public static PageElementPosition valueOf(String ident) {
54-
return (PageElementPosition)ALL.get(ident);
55+
return ALL.get(ident);
5556
}
5657

58+
@Override
5759
public int hashCode() {
5860
return FS_ID;
5961
}
6062

63+
@Override
6164
public boolean equals(Object o) {
6265
if (o == null || ! (o instanceof PageElementPosition)) {
6366
return false;

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/ValueConstants.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public final class ValueConstants {
4242
* Type descriptions--a crude approximation taken by scanning CSSValue
4343
* statics
4444
*/
45-
private final static List TYPE_DESCRIPTIONS;
45+
private final static List<String> TYPE_DESCRIPTIONS;
4646
/**
4747
* Description of the Field
4848
*/
49-
private final static Map sacTypesStrings;
49+
private final static Map<Short, String> sacTypesStrings;
5050

5151
/**
5252
* A text representation of the CSS type for this value.
@@ -61,7 +61,7 @@ public static String cssType(int cssType, int primitiveValueType) {
6161
if (primitiveValueType >= TYPE_DESCRIPTIONS.size()) {
6262
desc = "{unknown: " + primitiveValueType + "}";
6363
} else {
64-
desc = (String) TYPE_DESCRIPTIONS.get(primitiveValueType);
64+
desc = TYPE_DESCRIPTIONS.get(primitiveValueType);
6565
if (desc == null) {
6666
desc = "{UNKNOWN VALUE TYPE}";
6767
}
@@ -112,7 +112,7 @@ public static short sacPrimitiveTypeForString(String type) {
112112
* @return Returns
113113
*/
114114
public static String stringForSACPrimitiveType(short type) {
115-
return (String) sacTypesStrings.get(new Short(type));
115+
return sacTypesStrings.get(new Short(type));
116116
}
117117

118118
/**
@@ -127,7 +127,7 @@ public static String stringForSACPrimitiveType(short type) {
127127
//TODO: method may be unnecessary (tobe)
128128
public static boolean isAbsoluteUnit(CSSPrimitiveValue primitive) {
129129
short type = 0;
130-
type = ((CSSPrimitiveValue) primitive).getPrimitiveType();
130+
type = primitive.getPrimitiveType();
131131
return isAbsoluteUnit(type);
132132
}
133133

@@ -253,8 +253,8 @@ public static boolean isNumber(short cssPrimitiveType) {
253253
}
254254

255255
static {
256-
SortedMap map = new TreeMap();
257-
TYPE_DESCRIPTIONS = new ArrayList();
256+
SortedMap<Short, String> map = new TreeMap<>();
257+
TYPE_DESCRIPTIONS = new ArrayList<>();
258258
try {
259259
Field fields[] = CSSPrimitiveValue.class.getFields();
260260
for (int i = 0; i < fields.length; i++) {
@@ -278,13 +278,13 @@ public static boolean isNumber(short cssPrimitiveType) {
278278
}
279279
}
280280
// now sort by the key--the short constant for the public fields
281-
List keys = new ArrayList(map.keySet());
281+
List<Short> keys = new ArrayList<>(map.keySet());
282282
Collections.sort(keys);
283283

284284
// then add to our static list, in the order the keys appear. this means
285285
// list.get(index) will return the item at index, which should be the description
286286
// for that constant
287-
Iterator iter = keys.iterator();
287+
Iterator<Short> iter = keys.iterator();
288288
while (iter.hasNext()) {
289289
TYPE_DESCRIPTIONS.add(map.get(iter.next()));
290290
}
@@ -293,7 +293,7 @@ public static boolean isNumber(short cssPrimitiveType) {
293293
}
294294

295295
// HACK: this is a quick way to perform the lookup, but dumb if the short assigned are > 100; but the compiler will tell us that (PWW 21-01-05)
296-
sacTypesStrings = new HashMap(25);
296+
sacTypesStrings = new HashMap<>(25);
297297
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_EMS), "em");
298298
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_EXS), "ex");
299299
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PX), "px");

0 commit comments

Comments
 (0)