Class Utils
-
- All Implemented Interfaces:
public final class Utils
-
-
Method Summary
Modifier and Type Method Description final IntegergetRed()final IntegergetGreen()final IntegergetBlue()final IntegergetAlpha()final static PolyColorrgba(Integer r, Integer g, Integer b, Float a)create a color from the given red, green, and blue integer values, and an alpha value 0f..1ffinal static PolyColorrgba(Integer r, Integer g, Integer b)create a color from the given red, green, and blue integer values, and an alpha value 0f..1ffinal static IntegerHSBtoRGB(Float hue, Float saturation, Float brightness)Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model. final static FloatArrayRGBtoHSB(Integer r, Integer g, Integer b, FloatArray out)Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model. final static PolyColortoColor(Integer $self)Takes an ARGB integer color and returns a PolyColor object. final static DoubletoRadians(Double $self)final static PolyColortoPolyColor(Color $self)Return a PolyUI compatible color object representative of this Java color object. final static PolyColor.AnimatedtoPolyColorAnimated(Color $self)Return an animatable PolyUI color object representative of this Java color object. final static Integergcd(Integer $self, Integer b)Calculate the greatest common denominator of two integers. final static <E extends Enum<E>> EgetByName(EnumEntries<E> $self, String name, Boolean ignoreCase)Get an enum constant by its name, or nullif name isnull; or does not match any of this enum's constants.final static List<String>names(EnumEntries<?> $self)Return a list of the names of the entries in this enum. final static Pair<Integer, Integer>simplifyRatio(Pair<Integer, Integer> $self)Simplify a ratio of two integers. final static Floatcl0(Float a, Float b)Returns the value closer to zero. final static Floatcl1(Float a, Float b)Returns the value closer to one. final static Integermin3(Integer a, Integer b, Integer c)Returns the minimum value among three given ints. final static FloatArrayradii(Number $self)convert the given float into an array of 4 floats for radii. final static FloatArrayradii(Float topLeft, Float topRight, Float bottomLeft, Float bottomRight)convert the given floats into an array of 4 floats for radii. final static <T extends Any> Tstdout(T $self, Object arg)print the object to stdout, then return it. final static PolyImageimage(String $self)final static PolyImageimage(String $self, Vec2 size)final static Translator.Text.Formattedtranslated(String $self, Object args)final static Translator.Texttranslated(String $self)final static Modifiersmods(KeyModifiers mods)final static <E extends Any> UnitmoveElement(Array<E> $self, Integer from, Integer to)Moves the given element from the from index to the to index. final static <T extends Any, R extends Any> Array<R>mapToArray(Array<T> $self, Function1<T, R> transform)Perform the given transform on every element in this array, and return a new array with the results. final static <T extends Any, R extends Any> Array<R>mapToArray(Collection<T> $self, Function1<T, R> transform)Perform the given transform on every element in this list, and return a new array with the results. final static <K extends Any, V extends Any, R extends Any> Array<R>mapToArray(Map<K, V> $self, Function1<Entry.Map<K, V>, R> transform)Perform the given transform on every element in this map, and return a new array with the results. final static <T extends Any, R extends Any> Array<R>mapToArray(LinkedList<T> $self, Function1<T, R> transform)Perform the given transform on every element in this list, and return a new array with the results. final static BooleanareValuesEqual(FloatArray $self)final static Unitopen(PolyUI $self, Window window)final static FloatArrayset(FloatArray $self, Float value)final static <T extends Any> List<T>ensureSize(List<T> $self, Integer size, Function1<Integer, T> initializer)Ensure that this list is at least size elements long, and if it is not, add elements to it using the given initializer. final static <T extends Any> Ref.ObjectRef<T>ref(T $self)Box the given value into a Ref.ObjectRef. final static <T extends Any> Tderef(Ref.ObjectRef<T> $self)Return the value of this Ref.ObjectRef. final static <T extends Any> LinkedList<T>asLinkedList(Collection<T> $self)Return this collection as an LinkedList. final static <T extends Any> LinkedList<T>asLinkedList(Array<T> $self)final static <T extends Any> LinkedList<T>linkedListOf(T elements)final static <K extends Any, V extends Any> VmaybeRemove(Map<K, V> $self, K key, Boolean shouldRemove)Returns the value of the given key in the map, and if shouldRemove is truethe value is also removed from the map.final static <T extends Any> Unitboth(Pair<T, T> $self, Function1<T, Unit> func)Perform the given function on both elements of this pair. final static <A extends Any, B extends Any> MutablePair<A, B>with(A $self, B that)Mutable version of to. -
-
Method Detail
-
rgba
final static PolyColor rgba(Integer r, Integer g, Integer b, Float a)
create a color from the given red, green, and blue integer values, and an alpha value
0f..1f
-
rgba
final static PolyColor rgba(Integer r, Integer g, Integer b)
create a color from the given red, green, and blue integer values, and an alpha value
0f..1f
-
HSBtoRGB
final static Integer HSBtoRGB(Float hue, Float saturation, Float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
The
saturationandbrightnesscomponents should be floating-point values between zero and one (numbers in the range 0.0-1.0). Thehuecomponent can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value that is the same format used by the method getARGB(). This integer can be supplied as an argument to the toColor method that takes a single integer argument to create a PolyColor.
- Parameters:
hue- the hue component of the colorsaturation- the saturation of the colorbrightness- the brightness of the color- Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.
-
RGBtoHSB
final static FloatArray RGBtoHSB(Integer r, Integer g, Integer b, FloatArray out)
Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.
If the out argument is
null, then a new array is allocated to return the result. Otherwise, the method returns the array out, with the values put into that array.- Parameters:
r- the red component of the colorg- the green component of the colorb- the blue component of the colorout- the array used to return the three HSB values, ornull- Returns:
an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.
- Since:
0.18.2
-
toColor
final static PolyColor toColor(Integer $self)
Takes an ARGB integer color and returns a PolyColor object.
-
toPolyColor
final static PolyColor toPolyColor(Color $self)
Return a PolyUI compatible color object representative of this Java color object.
- Since:
1.1.51
-
toPolyColorAnimated
final static PolyColor.Animated toPolyColorAnimated(Color $self)
Return an animatable PolyUI color object representative of this Java color object.
- Since:
1.1.51
-
gcd
final static Integer gcd(Integer $self, Integer b)
Calculate the greatest common denominator of two integers.
- Since:
0.18.4
-
getByName
final static <E extends Enum<E>> E getByName(EnumEntries<E> $self, String name, Boolean ignoreCase)
Get an enum constant by its name, or
nullif name isnull; or does not match any of this enum's constants.
-
names
final static List<String> names(EnumEntries<?> $self)
Return a list of the names of the entries in this enum.
-
simplifyRatio
final static Pair<Integer, Integer> simplifyRatio(Pair<Integer, Integer> $self)
Simplify a ratio of two integers.
- Since:
0.18.4
-
cl0
final static Float cl0(Float a, Float b)
Returns the value closer to zero.
If either value is
NaN, then the result isNaN.If
a == b, then the result isa.
-
cl1
final static Float cl1(Float a, Float b)
Returns the value closer to one.
If either value is
NaN, then the result isNaN.If
a == b, then the result isa.
-
min3
final static Integer min3(Integer a, Integer b, Integer c)
Returns the minimum value among three given ints.
- Parameters:
a- the first valueb- the second valuec- the third value- Returns:
the minimum value among a, b, and c
-
radii
final static FloatArray radii(Number $self)
convert the given float into an array of 4 floats for radii.
-
radii
final static FloatArray radii(Float topLeft, Float topRight, Float bottomLeft, Float bottomRight)
convert the given floats into an array of 4 floats for radii.
-
stdout
final static <T extends Any> T stdout(T $self, Object arg)
print the object to stdout, then return it.
-
translated
final static Translator.Text.Formatted translated(String $self, Object args)
-
translated
final static Translator.Text translated(String $self)
-
mods
final static Modifiers mods(KeyModifiers mods)
-
moveElement
final static <E extends Any> Unit moveElement(Array<E> $self, Integer from, Integer to)
Moves the given element from the from index to the to index.
Note: this method makes absolutely no attempt to verify if the given indices are valid.
- Parameters:
from- the index of the element to moveto- the index to move the element to
-
mapToArray
final static <T extends Any, R extends Any> Array<R> mapToArray(Array<T> $self, Function1<T, R> transform)
Perform the given transform on every element in this array, and return a new array with the results.
Equivalent to
this.map { transform(it) }.toTypedArray(), but saves on the creation of an intermediate list.
-
mapToArray
final static <T extends Any, R extends Any> Array<R> mapToArray(Collection<T> $self, Function1<T, R> transform)
Perform the given transform on every element in this list, and return a new array with the results.
Equivalent to
this.map { transform(it) }.toTypedArray(), but saves on the creation of an intermediate list.
-
mapToArray
final static <K extends Any, V extends Any, R extends Any> Array<R> mapToArray(Map<K, V> $self, Function1<Entry.Map<K, V>, R> transform)
Perform the given transform on every element in this map, and return a new array with the results.
Equivalent to
this.map { transform(it) }.toTypedArray(), but saves on the creation of an intermediate list.
-
mapToArray
final static <T extends Any, R extends Any> Array<R> mapToArray(LinkedList<T> $self, Function1<T, R> transform)
Perform the given transform on every element in this list, and return a new array with the results.
Equivalent to
this.map { transform(it) }.toTypedArray(), but saves on the creation of an intermediate list.
-
areValuesEqual
final static Boolean areValuesEqual(FloatArray $self)
-
set
final static FloatArray set(FloatArray $self, Float value)
-
ensureSize
final static <T extends Any> List<T> ensureSize(List<T> $self, Integer size, Function1<Integer, T> initializer)
Ensure that this list is at least size elements long, and if it is not, add elements to it using the given initializer.
- Since:
1.0.7
-
ref
final static <T extends Any> Ref.ObjectRef<T> ref(T $self)
Box the given value into a Ref.ObjectRef.
-
deref
final static <T extends Any> T deref(Ref.ObjectRef<T> $self)
Return the value of this Ref.ObjectRef.
-
asLinkedList
final static <T extends Any> LinkedList<T> asLinkedList(Collection<T> $self)
Return this collection as an LinkedList. Note: if it is already a LinkedList, it will be returned as-is.
-
asLinkedList
final static <T extends Any> LinkedList<T> asLinkedList(Array<T> $self)
-
linkedListOf
final static <T extends Any> LinkedList<T> linkedListOf(T elements)
-
maybeRemove
final static <K extends Any, V extends Any> V maybeRemove(Map<K, V> $self, K key, Boolean shouldRemove)
Returns the value of the given key in the map, and if shouldRemove is
truethe value is also removed from the map.- Since:
1.0.2
-
both
final static <T extends Any> Unit both(Pair<T, T> $self, Function1<T, Unit> func)
Perform the given function on both elements of this pair. The highest common type of both elements is used as the type of the parameter.
-
with
final static <A extends Any, B extends Any> MutablePair<A, B> with(A $self, B that)
Mutable version of to.
-
-
-
-