Package com.amalgamasimulation.utils
Class Utils
java.lang.Object
com.amalgamasimulation.utils.Utils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,T, R> Function <V, R> Deprecated, for removal: This API element is subject to removal in a future version.static <V,T1, T2, R>
Function<V, R> Deprecated, for removal: This API element is subject to removal in a future version.static <V,R> Function <V, R> constant(R constant) Deprecated, for removal: This API element is subject to removal in a future version.static LocalDateTimedateToLocalDateTime(Date date) Converts the specified instance ofDateto an instance ofLocalDateTimepointing to the same instant of time in the system's default time zone.static LocalTimegetLocalTimeDifference(LocalTime localTime1, LocalTime localTime2) static intgetMaxDaysOfCurrentMonth(LocalDateTime localDateTime) Returns the number of days in the month of the specifiedLocalDateTime.static <T> List<T> iteratorToList(Iterator<T> iterator) static <T> Stream<T> iteratorToStream(Iterator<T> iterator) static doublelimit(double lowerBound, double x, double upperBound) Deprecated.static intlimit(int lowerBound, int x, int upperBound) Deprecated.If you use Java-21+, switch to theMath.clamp(long, int, int)method.static longlimit(long lowerBound, long x, long upperBound) Deprecated.If you use Java-21+, switch to theMath.clamp(long, long, long)method.static DateConverts the specified instance ofLocalDateTimeto an instance ofDatepointing to the same instant of time in the system's default time zone.static <E> Supplier<E> supplier(E constant) Deprecated, for removal: This API element is subject to removal in a future version.static <T> List<T> Deprecated, for removal: This API element is subject to removal in a future version.use standard JDK'sCollectors.toList()methodstatic <E> List<E> Deprecated, for removal: This API element is subject to removal in a future version.static doubleweightedAverage(double weight1, double value1, double weight2, double value2) Returns the weighted average across the two specified values with respective specified weights, more specifically:(weight1 / (weight1 + weight2)) * value1 + (weight2 / (weight1 + weight2)) * value2.static doublexidz(double a, double b, double x) Returns the result of a / b, and x if b == 0.static doublezidz(double a, double b) Returns the result of a / b, and 0 if b == 0.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
zidz
public static double zidz(double a, double b) Returns the result of a / b, and 0 if b == 0.- Parameters:
a-b-- Returns:
- a / b, and 0 if b == 0
-
xidz
public static double xidz(double a, double b, double x) Returns the result of a / b, and x if b == 0.- Parameters:
a-b-x-- Returns:
- a / b, and x if b == 0
-
limit
@Deprecated(since="Java-21") public static double limit(double lowerBound, double x, double upperBound) Deprecated.If you use Java-21+, switch to theMath.clamp(double, double, double)method. WARNING: mind the arguments order!Returns the specified x value limited by the specified lower and upper bounds, more specifically:- returns x if x is between lowerBound and upperBound, inclusively
- returns lowerBound if
x < lowerBound - returns upperBound if
x > upperBound
- Parameters:
lowerBound- specified lower boundx- specified value to be limited by the boundsupperBound- specified lower bound- Returns:
- x value limited by the specified lower and upper bounds
-
limit
Deprecated.If you use Java-21+, switch to theMath.clamp(long, long, long)method. WARNING: mind the arguments order!Returns the specified x value limited by the specified lower and upper bounds, more specifically:- returns x if x is between lowerBound and upperBound, inclusively
- returns lowerBound if
x < lowerBound - returns upperBound if
x > upperBound
- Parameters:
lowerBound- specified lower boundx- specified value to be limited by the boundsupperBound- specified lower bound- Returns:
- x value limited by the specified lower and upper bounds
-
limit
Deprecated.If you use Java-21+, switch to theMath.clamp(long, int, int)method. WARNING: mind the arguments order!Returns the specified x value limited by the specified lower and upper bounds, more specifically:- returns x if x is between lowerBound and upperBound, inclusively
- returns lowerBound if
x < lowerBound - returns upperBound if
x > upperBound
- Parameters:
lowerBound- specified lower boundx- specified value to be limited by the boundsupperBound- specified lower bound- Returns:
- x value limited by the specified lower and upper bounds
-
weightedAverage
public static double weightedAverage(double weight1, double value1, double weight2, double value2) Returns the weighted average across the two specified values with respective specified weights, more specifically:(weight1 / (weight1 + weight2)) * value1 + (weight2 / (weight1 + weight2)) * value2.- Parameters:
weight1- weight of the first valuevalue1- first valueweight2- weight of the second valuevalue2- second value- Returns:
- weighted average across the two specified values with respective specified weights
-
dateToLocalDateTime
Converts the specified instance ofDateto an instance ofLocalDateTimepointing to the same instant of time in the system's default time zone.- Parameters:
date- specified instance ofDate- Returns:
- instance of
LocalDateTimepointing to the same instant of time as the specified date
-
localDateTimeToDate
Converts the specified instance ofLocalDateTimeto an instance ofDatepointing to the same instant of time in the system's default time zone.- Parameters:
date- specified instance ofLocalDateTime- Returns:
- instance of
Datepointing to the same instant of time as the specified date
-
toList
Deprecated, for removal: This API element is subject to removal in a future version.use standard JDK'sCollectors.toList()methodConverts the specified stream to a list. The result of method is identical to the result of the following expression:stream.collect(Collectors.toList())- Type Parameters:
T- type of elements of the stream- Parameters:
stream- specified stream- Returns:
- list with elements extracted from the specified stream
-
union
@SafeVarargs @Deprecated(forRemoval=true) public static <E> List<E> union(List<? extends E>... lists) Deprecated, for removal: This API element is subject to removal in a future version.Concatenates several lists into a single list. A new list is created, so the original lists are not affected.- Parameters:
lists- lists to be combined into one list- Returns:
- A single list that contains all elements from the
lists
-
getMaxDaysOfCurrentMonth
Returns the number of days in the month of the specifiedLocalDateTime.- Parameters:
localDateTime- specifiedLocalDateTime- Returns:
- number of days in the month of the specified
LocalDateTime
-
getLocalTimeDifference
-
compose
@Deprecated(forRemoval=true) public static <V,T, Function<V,R> R> compose(Function<V, T> first, Function<T, R> second) Deprecated, for removal: This API element is subject to removal in a future version.Returns a function that is a composition of the two specified functions. The resulting function is an equivalent of the following function:
Typical use case of this function is constructing a function for extracting and formating some value in one line, e.g.:Function<V, R> result= v -> { T t = first.apply( v ); R r = second.apply( t ); return r; }compose( model.getEngine()::timeToDate, Formats.getDefaultFormats()::dayMonthHoursMinutes ) ^ ^ Extract date from time Format date- Parameters:
first- first function being composedsecond- second function being composed- Returns:
- composition of the two specified functions
-
compose
@Deprecated(forRemoval=true) public static <V,T1, Function<V,T2, R> R> compose(Function<V, T1> first, Function<T1, T2> second, Function<T2, R> third) Deprecated, for removal: This API element is subject to removal in a future version. -
constant
Deprecated, for removal: This API element is subject to removal in a future version. -
supplier
Deprecated, for removal: This API element is subject to removal in a future version. -
iteratorToStream
Converts anIteratorto a sequentialStream. The resulting stream preserves the iteration order and can only be consumed once.- Type Parameters:
T- the type of elements in the iterator and stream- Parameters:
iterator- the iterator to convert to a stream- Returns:
- a sequential
Streamcontaining the elements from the iterator
-
iteratorToList
Converts anIteratorto aListcontaining all its elements. This method consumes the iterator and collects all elements into a new list.- Type Parameters:
T- the type of elements in the iterator and resulting list- Parameters:
iterator- the iterator to convert to a list- Returns:
- a new
Listcontaining all elements from the iterator in iteration order
-
Math.clamp(double, double, double)method.