Skip to content

Commit f584082

Browse files
committed
Addressed review comments by updating PageSize constants for direct reference instead of method calls
1 parent bbb4bf4 commit f584082

File tree

1 file changed

+13
-56
lines changed

1 file changed

+13
-56
lines changed

Diff for: java/src/org/openqa/selenium/print/PageSize.java

+13-56
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,23 @@
2121
import java.util.Map;
2222

2323
public class PageSize {
24-
2524
private final double height;
2625
private final double width;
2726

28-
// Default Constructor (A4 by default)
29-
public PageSize() {
30-
this(PaperSize.A4); // Delegate to predefined size constructor
31-
}
27+
// Predefined constants
28+
public static final PageSize A4 = new PageSize(27.94, 21.59);
29+
public static final PageSize LEGAL = new PageSize(35.56, 21.59);
30+
public static final PageSize TABLOID = new PageSize(43.18, 27.94);
31+
public static final PageSize LETTER = new PageSize(27.94, 21.59);
3232

33-
// Custom Size Constructor
3433
public PageSize(double height, double width) {
3534
this.height = height;
3635
this.width = width;
3736
}
3837

39-
// Constructor for Predefined Sizes A4,A6,LEGAL,TABLOID using PaperSize Enum
40-
public PageSize(PaperSize paperSize) {
41-
this(paperSize.getHeight(), paperSize.getWidth()); // Delegate to custom size constructor
42-
}
43-
44-
// Factory Methods for Predefined Sizes
45-
public static PageSize A4() {
46-
return new PageSize(PaperSize.A4);
47-
}
48-
49-
public static PageSize A6() {
50-
return new PageSize(PaperSize.A6);
51-
}
52-
53-
public static PageSize LEGAL() {
54-
return new PageSize(PaperSize.LEGAL);
55-
}
56-
57-
public static PageSize TABLOID() {
58-
return new PageSize(PaperSize.TABLOID);
38+
// Default constructor (e.g., default to A4)
39+
public PageSize() {
40+
this(A4.getHeight(), A4.getWidth());
5941
}
6042

6143
// Getters for Height and Width
@@ -67,41 +49,16 @@ public double getWidth() {
6749
return width;
6850
}
6951

70-
// Convert to Map (for serialization or configuration)
7152
public Map<String, Object> toMap() {
72-
final Map<String, Object> options = new HashMap<>();
73-
options.put("height", getHeight());
74-
options.put("width", getWidth());
75-
return options;
76-
}
77-
78-
// Enum for Predefined Sizes
79-
public enum PaperSize {
80-
A4(27.94, 21.59),
81-
A6(14.8, 10.5),
82-
LEGAL(35.56, 21.59),
83-
TABLOID(43.18, 27.94);
84-
85-
private final double height;
86-
private final double width;
87-
88-
PaperSize(double height, double width) {
89-
this.height = height;
90-
this.width = width;
91-
}
92-
93-
public double getHeight() {
94-
return height;
95-
}
96-
97-
public double getWidth() {
98-
return width;
99-
}
53+
Map<String, Object> map = new HashMap<>();
54+
map.put("width", width);
55+
map.put("height", height);
56+
return map;
10057
}
10158

10259
@Override
10360
public String toString() {
104-
return String.format("PageSize[height=%.2f, width=%.2f]", height, width);
61+
return "PageSize[width=" + this.getWidth() + ", height=" + this.getHeight() + "]";
10562
}
10663

10764
}

0 commit comments

Comments
 (0)