Skip to content

Commit

Permalink
Add overloaded version of Require.positive for double
Browse files Browse the repository at this point in the history
  • Loading branch information
raju249 committed Jan 12, 2021
1 parent ba94857 commit e8dbb31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
14 changes: 14 additions & 0 deletions java/client/src/org/openqa/selenium/internal/Require.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ public static int positive(String argName, Integer number, String message) {
return number;
}

public static double positive(String argName, Double number, String message) {
if (number == null) {
throw new IllegalArgumentException(String.format(ARG_MUST_BE_SET, argName));
}
if (number <= 0) {
if (message == null) {
throw new IllegalArgumentException(argName + " must be greater than 0");
} else {
throw new IllegalArgumentException(message);
}
}
return number;
}

public static int positive(String argName, Integer number) {
return positive(argName, number, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ java_library(
"//java/client/test/org/openqa/selenium/build:__pkg__",
"//java/client/test/org/openqa/selenium/testing/drivers:__pkg__",
"//java/client/src/org/openqa/selenium:__subpackages__",
],
deps = [
"//java/client/src/org/openqa/selenium:core",
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.openqa.selenium.printoptions.print;

import org.openqa.selenium.internal.Require;

public class PageMargin {
private double top;
private double bottom;
Expand Down Expand Up @@ -47,34 +49,18 @@ public double getRight() {
}

public void setTop(double top) {
if (top < 0) {
throw new IllegalArgumentException("Top margin value should be > 0");
}

this.top = top;
this.top = Require.positive("top", top, null);
}

public void setBottom(double bottom) {
if (bottom < 0) {
throw new IllegalArgumentException("Bottom margin value should be > 0");
}

this.bottom = bottom;
this.bottom = Require.positive("bottom", bottom, null);
}

public void setRight(double right) {
if (right < 0) {
throw new IllegalArgumentException("Right margin value should be > 0");
}

this.right = right;
this.right = Require.positive("right", right, null);
}

public void setLeft(double left) {
if (left < 0) {
throw new IllegalArgumentException("Left margin value should be > 0");
}

this.left = left;
this.left = Require.positive("left", left, null);
}
}

0 comments on commit e8dbb31

Please sign in to comment.