Skip to content

kryptonbutterfly/mathUtils

Repository files navigation

mathUtils Maven Package

Contents

Utility Description
Limit.clamp takes 3 numbers. A lower bound an upper bound and a value to be restricted to be between the lower and upper bound
Limit.inRange takes 3 numbers. A lower bound an upper bound and a value to be checked to be between the lower and upper bound
Limit.assertLimit takes 3 numbers. A lower bound an upper bound and a value to be asserted to be between the lower and upper bound. If this condition is not met an exception will get thrown
Range an iterable that either supplies an index, an element or both (see example)
Min contains min functions for every primitive (see java.lang.Math#min)
Max contains max functions for every primitive (see java.lang.Math#max)

Getting the latest release

<repository>
  <id>github</id>
  <url>https://maven.pkg.github.com/kryptonbutterfly/maven-repo</url>
</repository>
<dependency>
  <groupId>kryptonbutterfly</groupId>
  <artifactId>math_utils</artifactId>
  <version>2.0.0</version>
</dependency>

Download

java version library version Download
18+ 2.0.0 math_utils-2.0.0.jar
18+ 1.1.0 math_utils-1.1.0.jar
18+ 1.0.0 MathUtils.jar

Examples

Range

String[] array = { "Hello,", "Range!" };
for (var ie : Range.range(array))
    System.out.println(ie.index() + " -- " + ie.element());

Output:

0 -- Hello,
1 -- Range!

Range.index()

String[] array = { "Hello,", "Range!" };
for (int index : Range.range(array).index())
    System.out.println(index);

Output:

0
1

Range.element()

String[] array = { "Hello,", "Range!" };
for (String element : Range.range(array).element())
    System.out.println(element);

Output:

Hello,
Range!

int Range

int start = 1, stop = 5;
for (int i : Range.range(start, stop))
    System.out.println(i);

Output:

1
2
3
4

String Range

for (char c : Range.range("AbC").reverse().element())
    System.out.println(c);

Output:

C
b
A

Min.min

System.out.println(Min.min(5, -10, 2));

Output:

-10

Max.max

System.out.println(Max.max(5, -10, 2));

Output:

5