orThrow
Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val number: Byte = 0
val isSuccess: Boolean = try {
Zero.orThrow(number)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
final byte number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid number.
Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val number: Short = 0
val isSuccess: Boolean = try {
Zero.orThrow(number)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
final short number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid number.
Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val isSuccess: Boolean = try {
Zero.orThrow(0)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
final int number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid number.
Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val isSuccess: Boolean = try {
Zero.orThrow(0L)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
final long number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid number.
Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val isSuccess: Boolean = try {
Zero.orThrow(0f)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
final float number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid number.
Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val isSuccess: Boolean = try {
Zero.orThrow(0.0)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
final double number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid number.
Creates an instance of Zero from the specified text, or throws an IllegalArgumentException if the text is an invalid representation of zero.
The text is a valid representation if it matches the following pattern: ^0+(?:\.0+)?$
.
Pattern symbols
Here's the explanation associated to each symbol used in this pattern:
^
Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.0
Character. Matches a "0" character (char code 48).+
Quantifier. Match 1 or more of the preceding token.(?:)
Non-capturing group. Groups multiple tokens together without creating a capture group.\.
Escaped character. Matches a "." character (char code 46).?
Quantifier. Match between 0 and 1 of the preceding token.$
End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val isSuccess: Boolean = try {
listOf("0", "000", "0.0", "0.000", "000.0", "000.000")
.forEach(Zero.Companion::orThrow)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Calling from Java
Here's an example of calling this function from Java code:
boolean isSuccess;
try {
Arrays.asList("0", "000", "0.0", "0.000", "000.0", "000.000")
.forEach(Zero::orThrow);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
See the orNull function for returning null
instead of throwing an exception in case of invalid text.