Skip to content

Commit

Permalink
Merge pull request #280 from dmlloyd/assert
Browse files Browse the repository at this point in the history
Change the return type of certain `Assert` methods.
  • Loading branch information
dmlloyd authored Jan 23, 2024
2 parents 17eb1da + 7a79828 commit 714d043
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 16 deletions.
4 changes: 4 additions & 0 deletions constraint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>io.github.dmlloyd.module-info</groupId>
<artifactId>module-info</artifactId>
</plugin>
<plugin>
<groupId>org.jboss.bridger</groupId>
<artifactId>bridger</artifactId>
</plugin>
</plugins>
</build>

Expand Down
180 changes: 164 additions & 16 deletions constraint/src/main/java/io/smallrye/common/constraint/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,23 @@ public static double[] checkNotEmptyParam(String name, double[] value) {
* @param min the minimum value
* @param actual the actual parameter value
* @param <T> the parameter type
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static <T extends Comparable<T>> void checkMinimumParameter(String name, T min, T actual)
public static <T extends Comparable<T>> T checkMinimumParameter(String name, T min, T actual)
throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual.compareTo(min) < 0)
throw Messages.log.paramLessThan(name, min);
return actual;
}

/**
* @hidden
*/
public static <T extends Comparable<T>> void checkMinimumParameter$$bridge(String name, T min, T actual)
throws IllegalArgumentException {
checkMinimumParameter(name, min, actual);
}

/**
Expand All @@ -277,12 +287,21 @@ public static <T extends Comparable<T>> void checkMinimumParameter(String name,
* @param name the parameter name
* @param min the minimum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static void checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException {
public static int checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual < min)
throw Messages.log.paramLessThan(name, min);
return actual;
}

/**
* @hidden
*/
public static void checkMinimumParameter$$bridge(String name, int min, int actual) throws IllegalArgumentException {
checkMinimumParameter(name, min, actual);
}

/**
Expand All @@ -291,12 +310,21 @@ public static void checkMinimumParameter(String name, int min, int actual) throw
* @param name the parameter name
* @param min the minimum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static void checkMinimumParameterUnsigned(String name, int min, int actual) throws IllegalArgumentException {
public static int checkMinimumParameterUnsigned(String name, int min, int actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (Integer.compareUnsigned(actual, min) < 0)
throw Messages.log.paramLessThan(name, Integer.toUnsignedLong(min));
return actual;
}

/**
* @hidden
*/
public static void checkMinimumParameterUnsigned$$bridge(String name, int min, int actual) throws IllegalArgumentException {
checkMinimumParameterUnsigned(name, min, actual);
}

/**
Expand All @@ -305,12 +333,21 @@ public static void checkMinimumParameterUnsigned(String name, int min, int actua
* @param name the parameter name
* @param min the minimum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static void checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException {
public static long checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual < min)
throw Messages.log.paramLessThan(name, min);
return actual;
}

/**
* @hidden
*/
public static void checkMinimumParameter$$bridge(String name, long min, long actual) throws IllegalArgumentException {
checkMinimumParameter(name, min, actual);
}

/**
Expand All @@ -319,12 +356,22 @@ public static void checkMinimumParameter(String name, long min, long actual) thr
* @param name the parameter name
* @param min the minimum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static void checkMinimumParameterUnsigned(String name, long min, long actual) throws IllegalArgumentException {
public static long checkMinimumParameterUnsigned(String name, long min, long actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (Long.compareUnsigned(actual, min) < 0)
throw Messages.log.paramLessThan(name, Long.toUnsignedString(min));
return actual;
}

/**
* @hidden
*/
public static void checkMinimumParameterUnsigned$$bridge(String name, long min, long actual)
throws IllegalArgumentException {
checkMinimumParameterUnsigned(name, min, actual);
}

/**
Expand All @@ -333,12 +380,21 @@ public static void checkMinimumParameterUnsigned(String name, long min, long act
* @param name the parameter name
* @param min the minimum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static void checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException {
public static float checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual < min)
throw Messages.log.paramLessThan(name, min);
return actual;
}

/**
* @hidden
*/
public static void checkMinimumParameter$$bridge(String name, float min, float actual) throws IllegalArgumentException {
checkMinimumParameter(name, min, actual);
}

/**
Expand All @@ -347,12 +403,21 @@ public static void checkMinimumParameter(String name, float min, float actual) t
* @param name the parameter name
* @param min the minimum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is less than the minimum value
*/
public static void checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException {
public static double checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual < min)
throw Messages.log.paramLessThan(name, min);
return actual;
}

/**
* @hidden
*/
public static void checkMinimumParameter$$bridge(String name, double min, double actual) throws IllegalArgumentException {
checkMinimumParameter(name, min, actual);
}

/**
Expand All @@ -362,13 +427,23 @@ public static void checkMinimumParameter(String name, double min, double actual)
* @param max the maximum value
* @param actual the actual parameter value
* @param <T> the parameter type
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static <T extends Comparable<T>> void checkMaximumParameter(String name, T max, T actual)
public static <T extends Comparable<T>> T checkMaximumParameter(String name, T max, T actual)
throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual.compareTo(max) > 0)
throw Messages.log.paramGreaterThan(name, max);
return actual;
}

/**
* @hidden
*/
public static <T extends Comparable<T>> void checkMaximumParameter$$bridge(String name, T max, T actual)
throws IllegalArgumentException {
checkMaximumParameter(name, max, actual);
}

/**
Expand All @@ -377,12 +452,21 @@ public static <T extends Comparable<T>> void checkMaximumParameter(String name,
* @param name the parameter name
* @param max the maximum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static void checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException {
public static int checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual > max)
throw Messages.log.paramGreaterThan(name, max);
return actual;
}

/**
* @hidden
*/
public static void checkMaximumParameter$$bridge(String name, int max, int actual) throws IllegalArgumentException {
checkMaximumParameter(name, max, actual);
}

/**
Expand All @@ -391,12 +475,21 @@ public static void checkMaximumParameter(String name, int max, int actual) throw
* @param name the parameter name
* @param max the maximum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static void checkMaximumParameterUnsigned(String name, int max, int actual) throws IllegalArgumentException {
public static int checkMaximumParameterUnsigned(String name, int max, int actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (Integer.compareUnsigned(actual, max) > 0)
throw Messages.log.paramGreaterThan(name, Integer.toUnsignedLong(max));
return actual;
}

/**
* @hidden
*/
public static void checkMaximumParameterUnsigned$$bridge(String name, int max, int actual) throws IllegalArgumentException {
checkMaximumParameterUnsigned(name, max, actual);
}

/**
Expand All @@ -405,12 +498,21 @@ public static void checkMaximumParameterUnsigned(String name, int max, int actua
* @param name the parameter name
* @param max the maximum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static void checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException {
public static long checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual > max)
throw Messages.log.paramGreaterThan(name, max);
return actual;
}

/**
* @hidden
*/
public static void checkMaximumParameter$$bridge(String name, long max, long actual) throws IllegalArgumentException {
checkMaximumParameter(name, max, actual);
}

/**
Expand All @@ -419,12 +521,22 @@ public static void checkMaximumParameter(String name, long max, long actual) thr
* @param name the parameter name
* @param max the maximum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static void checkMaximumParameterUnsigned(String name, long max, long actual) throws IllegalArgumentException {
public static long checkMaximumParameterUnsigned(String name, long max, long actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (Long.compareUnsigned(actual, max) > 0)
throw Messages.log.paramGreaterThan(name, Long.toUnsignedString(max));
return actual;
}

/**
* @hidden
*/
public static void checkMaximumParameterUnsigned$$bridge(String name, long max, long actual)
throws IllegalArgumentException {
checkMaximumParameterUnsigned(name, max, actual);
}

/**
Expand All @@ -433,12 +545,21 @@ public static void checkMaximumParameterUnsigned(String name, long max, long act
* @param name the parameter name
* @param max the maximum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static void checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException {
public static float checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual > max)
throw Messages.log.paramGreaterThan(name, max);
return actual;
}

/**
* @hidden
*/
public static void checkMaximumParameter$$bridge(String name, float max, float actual) throws IllegalArgumentException {
checkMaximumParameter(name, max, actual);
}

/**
Expand All @@ -447,12 +568,21 @@ public static void checkMaximumParameter(String name, float max, float actual) t
* @param name the parameter name
* @param max the maximum value
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is greater than the maximum value
*/
public static void checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException {
public static double checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual > max)
throw Messages.log.paramGreaterThan(name, max);
return actual;
}

/**
* @hidden
*/
public static void checkMaximumParameter$$bridge(String name, double max, double actual) throws IllegalArgumentException {
checkMaximumParameter(name, max, actual);
}

/**
Expand All @@ -461,12 +591,21 @@ public static void checkMaximumParameter(String name, double max, double actual)
*
* @param name the parameter name
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is not zero or a power of two
*/
public static void checkPow2Parameter(String name, int actual) throws IllegalArgumentException {
public static int checkPow2Parameter(String name, int actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual != 0 && Integer.bitCount(actual) != 1)
throw Messages.log.paramNotPow2(name);
return actual;
}

/**
* @hidden
*/
public static void checkPow2Parameter$$bridge(String name, int actual) throws IllegalArgumentException {
checkPow2Parameter(name, actual);
}

/**
Expand All @@ -475,12 +614,21 @@ public static void checkPow2Parameter(String name, int actual) throws IllegalArg
*
* @param name the parameter name
* @param actual the actual parameter value
* @return the given actual value
* @throws IllegalArgumentException if the actual value is not zero or a power of two
*/
public static void checkPow2Parameter(String name, long actual) throws IllegalArgumentException {
public static long checkPow2Parameter(String name, long actual) throws IllegalArgumentException {
checkNotNullParamChecked("name", name);
if (actual != 0 && Long.bitCount(actual) != 1)
throw Messages.log.paramNotPow2(name);
return actual;
}

/**
* @hidden
*/
public static void checkPow2Parameter$$bridge(String name, long actual) throws IllegalArgumentException {
checkPow2Parameter(name, actual);
}

/**
Expand Down
Loading

0 comments on commit 714d043

Please sign in to comment.