Skip to content

Commit

Permalink
Addressed review comments by updating PageSize constants for direct r…
Browse files Browse the repository at this point in the history
…eference instead of method calls
  • Loading branch information
yvsvarma committed Jan 11, 2025
1 parent bbb4bf4 commit f584082
Showing 1 changed file with 13 additions and 56 deletions.
69 changes: 13 additions & 56 deletions java/src/org/openqa/selenium/print/PageSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,23 @@
import java.util.Map;

public class PageSize {

private final double height;
private final double width;

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

// Custom Size Constructor
public PageSize(double height, double width) {
this.height = height;
this.width = width;
}

// Constructor for Predefined Sizes A4,A6,LEGAL,TABLOID using PaperSize Enum
public PageSize(PaperSize paperSize) {
this(paperSize.getHeight(), paperSize.getWidth()); // Delegate to custom size constructor
}

// Factory Methods for Predefined Sizes
public static PageSize A4() {
return new PageSize(PaperSize.A4);
}

public static PageSize A6() {
return new PageSize(PaperSize.A6);
}

public static PageSize LEGAL() {
return new PageSize(PaperSize.LEGAL);
}

public static PageSize TABLOID() {
return new PageSize(PaperSize.TABLOID);
// Default constructor (e.g., default to A4)
public PageSize() {
this(A4.getHeight(), A4.getWidth());
}

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

// Convert to Map (for serialization or configuration)
public Map<String, Object> toMap() {
final Map<String, Object> options = new HashMap<>();
options.put("height", getHeight());
options.put("width", getWidth());
return options;
}

// Enum for Predefined Sizes
public enum PaperSize {
A4(27.94, 21.59),
A6(14.8, 10.5),
LEGAL(35.56, 21.59),
TABLOID(43.18, 27.94);

private final double height;
private final double width;

PaperSize(double height, double width) {
this.height = height;
this.width = width;
}

public double getHeight() {
return height;
}

public double getWidth() {
return width;
}
Map<String, Object> map = new HashMap<>();
map.put("width", width);
map.put("height", height);
return map;
}

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

}

0 comments on commit f584082

Please sign in to comment.