Skip to content

Commit 4cdd12a

Browse files
committed
Add overloaded version of Require.positive for double
1 parent 201c619 commit 4cdd12a

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

java/client/src/org/openqa/selenium/internal/Require.java

+14
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ public static int positive(String argName, Integer number, String message) {
159159
return number;
160160
}
161161

162+
public static double positive(String argName, Double number, String message) {
163+
if (number == null) {
164+
throw new IllegalArgumentException(String.format(ARG_MUST_BE_SET, argName));
165+
}
166+
if (number <= 0) {
167+
if (message == null) {
168+
throw new IllegalArgumentException(argName + " must be greater than 0");
169+
} else {
170+
throw new IllegalArgumentException(message);
171+
}
172+
}
173+
return number;
174+
}
175+
162176
public static int positive(String argName, Integer number) {
163177
return positive(argName, number, null);
164178
}

java/client/src/org/openqa/selenium/printoptions/print/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ java_library(
1111
"//java/client/test/org/openqa/selenium/build:__pkg__",
1212
"//java/client/test/org/openqa/selenium/testing/drivers:__pkg__",
1313
"//java/client/src/org/openqa/selenium:__subpackages__",
14+
],
15+
deps = [
16+
"//java/client/src/org/openqa/selenium:core",
1417
]
1518
)

java/client/src/org/openqa/selenium/printoptions/print/PageMargin.java

+6-20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.openqa.selenium.printoptions.print;
1919

20+
import org.openqa.selenium.internal.Require;
21+
2022
public class PageMargin {
2123
private double top;
2224
private double bottom;
@@ -47,34 +49,18 @@ public double getRight() {
4749
}
4850

4951
public void setTop(double top) {
50-
if (top < 0) {
51-
throw new IllegalArgumentException("Top margin value should be > 0");
52-
}
53-
54-
this.top = top;
52+
this.top = Require.positive("top", top, null);
5553
}
5654

5755
public void setBottom(double bottom) {
58-
if (bottom < 0) {
59-
throw new IllegalArgumentException("Bottom margin value should be > 0");
60-
}
61-
62-
this.bottom = bottom;
56+
this.bottom = Require.positive("bottom", bottom, null);
6357
}
6458

6559
public void setRight(double right) {
66-
if (right < 0) {
67-
throw new IllegalArgumentException("Right margin value should be > 0");
68-
}
69-
70-
this.right = right;
60+
this.right = Require.positive("right", right, null);
7161
}
7262

7363
public void setLeft(double left) {
74-
if (left < 0) {
75-
throw new IllegalArgumentException("Left margin value should be > 0");
76-
}
77-
78-
this.left = left;
64+
this.left = Require.positive("left", left, null);
7965
}
8066
}

0 commit comments

Comments
 (0)