Package breitband.util
Class Utils
- java.lang.Object
-
- breitband.util.Utils
-
public class Utils extends java.lang.Object
Various utilities
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Comparable<T>>
Tclamp(T value, T min, T max)
Clamps a comparable value in a specified range.static <K,V>
java.util.HashMap<K,V>deepCopyHashMap(java.util.HashMap<K,V> hashMap)
Creates and returns a deep copy of a hash map.static java.lang.StringBuilder
trimEnd(java.lang.StringBuilder text)
Trims trailing whitespaces off text.static boolean
truncate(java.lang.StringBuilder text, int maxLength)
Truncates text by cutting it off and adding an ellipsis to the end if necessary.static java.lang.String
truncate(java.lang.String text, int maxLength)
Truncates text by cutting it off and adding an ellipsis to the end if necessary.
-
-
-
Method Detail
-
deepCopyHashMap
public static <K,V> java.util.HashMap<K,V> deepCopyHashMap(java.util.HashMap<K,V> hashMap)
Creates and returns a deep copy of a hash map.All entries' values are copied and placed into a new hashmap that contains the same key/value pairs
- Type Parameters:
K
- The hash map's key typeV
- The hash map's value type- Parameters:
hashMap
- The map that will be deep copied- Returns:
- A new deep copy
-
clamp
public static <T extends java.lang.Comparable<T>> T clamp(T value, T min, T max)
Clamps a comparable value in a specified range.- Type Parameters:
T
- A comparable type- Parameters:
value
- The value to be clampedmin
- The minimum value in the rangemax
- The maximum value in the range- Returns:
- A clamped value within the specified bounds
-
truncate
public static java.lang.String truncate(java.lang.String text, int maxLength)
Truncates text by cutting it off and adding an ellipsis to the end if necessary.- Parameters:
text
- The text to truncatemaxLength
- The maximum amount of characters- Returns:
- The text, truncated if necessary
-
truncate
public static boolean truncate(java.lang.StringBuilder text, int maxLength)
Truncates text by cutting it off and adding an ellipsis to the end if necessary.- Parameters:
text
- The text to truncatemaxLength
- The maximum amount of characters- Returns:
- True only if the text has been truncated
-
trimEnd
public static java.lang.StringBuilder trimEnd(java.lang.StringBuilder text)
Trims trailing whitespaces off text.- Parameters:
text
- The text to truncate- Returns:
- The text, truncated if necessary
-
-