Package lu.kbra.pclib

Class PCUtils

java.lang.Object
lu.kbra.pclib.PCUtils

public final class PCUtils extends Object
  • Field Details

    • SHA_256_CHAR_LENGTH

      public static final int SHA_256_CHAR_LENGTH
      See Also:
    • HUMAN_FILE_SIZE_UNITS

      public static final String[] HUMAN_FILE_SIZE_UNITS
  • Constructor Details

    • PCUtils

      public PCUtils()
  • Method Details

    • add

      public static <T> List<T> add(List<T> beanPackages, T name)
    • add

      public static <T> T[] add(T[] beanPackages, T name)
    • addAll

      public static <T> List<T> addAll(List<T> beanPackages, List<T> name)
    • allByteBufferToArray

      public static byte[] allByteBufferToArray(ByteBuffer bb)
    • appendFileName

      public static String appendFileName(String path, String suffix)
    • applyMinThreshold

      public static float applyMinThreshold(float x, float min)
    • asArrayList

      @SafeVarargs public static <T> ArrayList<T> asArrayList(T... data)
    • asMap

      public static Map<String,Object> asMap(ResultSet rs) throws SQLException
      Throws:
      SQLException
    • backspace

      public static String backspace(String s, int pos)
    • byteArrayToHexString

      public static String byteArrayToHexString(byte[] byteArray)
    • byteArrayToList

      public static ArrayList<Byte> byteArrayToList(byte[] b)
    • byteBufferToHexString

      public static String byteBufferToHexString(ByteBuffer bb)
      Does not change the reader's position
    • byteBufferToHexString

      public static String byteBufferToHexString(ByteBuffer bb, int startingPos)
    • byteBufferToHexStringTable

      public static String byteBufferToHexStringTable(ByteBuffer bb, int columnCount, int columnWidth)
    • byteBufferToIntArray

      public static int[] byteBufferToIntArray(ByteBuffer bData, int length)
    • byteListToPrimitive

      public static byte[] byteListToPrimitive(List<Byte> bytes)
    • byteToInt

      public static int byteToInt(byte[] byteArray)
    • camelCaseToConstant

      public static String camelCaseToConstant(String camelCase)
    • camelCaseToSnakeCase

      public static String camelCaseToSnakeCase(String input)
    • capitalize

      public static String capitalize(String str)
    • cast

      public static <T> T cast(Object obj)
    • castArray

      public static <T> T[] castArray(Object[] arr, Function<Object,T> transformer, IntFunction<T[]> supplier)
    • castInt

      public static int[] castInt(Object[] arr)
    • castMap

      public static <K, V> Map<K,V> castMap(Map<?,?> map, Supplier<Map<K,V>> supplier, Class<K> keyClass, Class<V> valueClass)
    • castObject

      public static Object[] castObject(byte[] arr)
    • castObject

      public static Object[] castObject(char[] arr)
    • castObject

      public static Object[] castObject(double[] arr)
    • castObject

      public static Object[] castObject(float[] arr)
    • castObject

      public static Object[] castObject(int[] arr)
    • castObject

      public static Object[] castObject(long[] arr)
    • castObject

      public static Object[] castObject(short[] arr)
    • castObject

      public static <T> Object[] castObject(T[] arr)
    • clamp

      public static byte clamp(byte from, byte to, byte x)
    • clamp

      public static char clamp(char from, char to, char x)
    • clamp

      public static double clamp(double from, double to, double x)
    • clamp

      public static float clamp(float from, float to, float x)
    • clamp

      public static int clamp(int from, int to, int x)
    • clamp

      public static short clamp(short from, short to, short x)
    • clampColor

      public static Color clampColor(int red, int green, int blue)
    • clampColor

      public static Color clampColor(int red, int green, int blue, int alpha)
    • clampGreaterOrEquals

      public static double clampGreaterOrEquals(double min, double x)
    • clampGreaterOrEquals

      public static float clampGreaterOrEquals(float min, float x)
    • clampGreaterOrEquals

      public static int clampGreaterOrEquals(int min, int x)
    • clampGreaterOrEquals

      public static long clampGreaterOrEquals(long min, long x)
    • clampLessOrEquals

      public static double clampLessOrEquals(double x, double max)
    • clampLessOrEquals

      public static float clampLessOrEquals(float x, float max)
    • clampLessOrEquals

      public static int clampLessOrEquals(int x, int max)
    • clampLessOrEquals

      public static long clampLessOrEquals(long x, long max)
    • clampRange

      public static byte clampRange(byte from, byte to, byte x)
    • clampRange

      public static char clampRange(char from, char to, char x)
    • clampRange

      public static double clampRange(double from, double to, double x)
    • clampRange

      public static float clampRange(float from, float to, float x)
    • clampRange

      public static int clampRange(int from, int to, int x)
    • clampRange

      public static short clampRange(short from, short to, short x)
    • close

      public static void close(AutoCloseable... result)
    • combineArrays

      public static int[] combineArrays(int[] array1, int[] array2)
    • combineArrays

      public static <T> T[] combineArrays(T[] first, T[] second)
    • appendArrays

      public static <T> T[] appendArrays(T[] first, T... second)
    • compare

      public static boolean compare(byte x, byte target, byte delta)
    • compare

      public static boolean compare(char x, char target, char delta)
    • compare

      public static boolean compare(double x, double target, double delta)
    • compare

      public static boolean compare(float x, float target, float delta)
    • compare

      public static boolean compare(int x, int target, int delta)
    • compare

      public static boolean compare(short x, short target, short delta)
    • compareVersion

      public static int compareVersion(String a, String b)
    • computeDuplicates

      public static <T, B, C> Set<C> computeDuplicates(Collection<T> values, Function<T,B> func, Function<T,C> func2)
    • computeGaussianWeights

      public static float[] computeGaussianWeights(int radius)
    • concatStreams

      @SafeVarargs public static <T> Stream<? extends T> concatStreams(Stream<? extends T>... streams)
    • constantToCamelCase

      public static String constantToCamelCase(String enumName)
    • contrast

      public static double contrast(Color c1, Color c2)
    • countElements

      public static int countElements(Iterator<?> e)
    • countElements

      public static int countElements(ResultSet e) throws SQLException
      Throws:
      SQLException
    • defaultIfNull

      public static <T> T defaultIfNull(T obj, Supplier<T> orElse)
    • defaultIfNull

      public static <T> T defaultIfNull(T obj, T orElse)
    • defaultIfNull

      public static <T> T defaultIfNull(T obj, ThrowingSupplier<T,Throwable> orElse) throws Throwable
      Throws:
      Throwable
    • deleteChar

      public static String deleteChar(String s, int pos)
    • deleteFile

      public static void deleteFile(File f) throws IOException
      Throws:
      IOException
    • deleteOldFiles

      public static int deleteOldFiles(File directory, int keepCount)
    • duplicates

      public static <T, B> Set<B> duplicates(Collection<T> values, Function<T,B> func)
    • duplicates

      public static boolean duplicates(String[] refCols)
    • enumToNameString

      public static String enumToNameString(Enum<?> c)
    • enumValuetoEnum

      public static <T extends Enum<T>> T enumValuetoEnum(Class<T> enumClass, String e)
    • extractFile

      public static boolean extractFile(String inPath, File outFile) throws IOException
      Throws:
      IOException
    • extractKeys

      public static Set<String> extractKeys(org.json.JSONObject jsonObject)
      Extracts all keys from the given JSONObject, including nested keys, in the format of "key.subkey".
      Parameters:
      jsonObject - The JSONObject to extract keys from.
      Returns:
      A Set containing all keys in the desired format.
    • fill

      public static byte[] fill(byte[] bs, byte id)
    • fill

      public static char[] fill(char[] bs, char id)
    • fill

      public static double[] fill(double[] bs, double id)
    • fill

      public static float[] fill(float[] bs, float id)
    • fill

      public static int[] fill(int[] bs, int id)
    • fill

      public static long[] fill(long[] bs, long id)
    • fill

      public static short[] fill(short[] bs, short id)
    • fillArray

      public static <T> T[] fillArray(T[] arr, Function<Integer,T> provider)
    • fillArray

      public static <T> T[] fillArray(T[] arr, Object... objects)
    • fillString

      public static String fillString(String str, String place, int length)
    • findCompatibleConstructor

      public static <T> Constructor<T> findCompatibleConstructor(Class<T> clazz, Class<?>... argTypes) throws NoSuchMethodException
      Throws:
      NoSuchMethodException
    • first

      public static <T, R> ThrowingFunction<List<T>,R,Throwable> first(Function<T,R> transformer)
    • first

      public static <T, R> ThrowingFunction<List<T>,R,Throwable> first(Function<T,R> transformer, R default_)
    • first

      public static <T, R> ThrowingFunction<List<T>,R,Throwable> first(Function<T,R> transformer, Supplier<R> default_)
    • floatRepeating

      public static float[] floatRepeating(float[] is, int count)
    • getAllFields

      public static Field[] getAllFields(Class<?> clazz)
    • getAllThreads

      public static List<Thread> getAllThreads()
    • getBoolean

      public static boolean getBoolean(String name, boolean default_)
    • getCallerClassName

      public static String getCallerClassName(boolean parent)
    • getCallerClassName

      public static String getCallerClassName(boolean parent, boolean simple)
    • getCallerClassName

      public static String getCallerClassName(boolean parent, boolean simple, Class<?>... ignored)
    • getCallerClassName

      public static String getCallerClassName(boolean parent, boolean simple, String... ignorePatterns)
    • getCallerClassName

      public static String getCallerClassName(int offset, boolean simple)
      0 -> first caller (before PCUtils)
      1 -> second caller
      3...
    • getCause

      public static Throwable getCause(Throwable e)
    • getColumnIndex

      public static int getColumnIndex(ResultSet rs, String columnName) throws SQLException
      Throws:
      SQLException
    • getColumnMapping

      public static Map<String,Integer> getColumnMapping(ResultSet rs) throws SQLException
      Throws:
      SQLException
    • getFileExtension

      public static String getFileExtension(String path)
    • getFileName

      public static String getFileName(String cleanPath)
    • getFileSize

      public static long getFileSize(File file)
    • getFileSize

      public static long getFileSize(Path path)
    • getFloat

      public static float getFloat(String name, float default_)
    • getHumanFormatFileSize

      public static String getHumanFormatFileSize(long fileSize)
    • getIncrement

      public static String getIncrement(String filePath)
    • getInteger

      public static int getInteger(String name, int default_)
    • getMaxIndices

      public static int[] getMaxIndices(float[] arr, int n)
    • getRawClass

      public static Class<?> getRawClass(Type type)
    • getRootCauseMessage

      public static String getRootCauseMessage(Throwable th)
    • getStackTraceAsString

      public static String getStackTraceAsString(Throwable throwable)
    • getStatementAsSQL

      public static String getStatementAsSQL(Statement stmt)
    • getSubKey

      public static Object getSubKey(String[] keys, org.json.JSONObject obj)
    • getTypesInPackage

      public static Set<Class<?>> getTypesInPackage(String packageName)
    • hasColumn

      public static boolean hasColumn(ResultSet rs, String columnName) throws SQLException
      Throws:
      SQLException
    • hashMap

      public static <K, V> HashMap<K,V> hashMap(Object... objects)
    • hashString

      public static String hashString(String input, String algorithm)
    • hashStringSha256

      public static String hashStringSha256(String input)
    • hexToColor

      public static Color hexToColor(String hex)
      Parameters:
      hex - RRGGBBAA
    • insert

      public static <T> T[] insert(T[] array, int index, T element)
    • insertChar

      public static String insertChar(String s, int pos, char c)
    • intArrayToByteBuffer

      public static ByteBuffer intArrayToByteBuffer(int[] data)
    • intCountingUp

      public static int[] intCountingUp(int start, int end)
    • intCountingUp

      public static int[] intCountingUp(int start, int end, int steps, int count)
    • intCountingUpTriQuads

      public static int[] intCountingUpTriQuads(int quadCount)
    • intToByteArray

      public static byte[] intToByteArray(int val)
    • ipToString

      public static String ipToString(byte[] ipv4)
    • ipToString

      public static String ipToString(int ipv4)
    • isInteger

      public static boolean isInteger(String str)
    • isNumber

      public static boolean isNumber(Class<?> clazz)
    • isSubPath

      public static boolean isSubPath(Path file, Path dir)
    • isSubPath

      public static boolean isSubPath(Path file, Path dir, boolean followSymLinks) throws IOException
      Throws:
      IOException
    • isSubtype

      public static boolean isSubtype(Type type, Class<?> check)
    • isToday

      public static boolean isToday(Date date)
    • isToday

      public static boolean isToday(LocalDate localDate)
    • joinString

      public static String joinString(String[] tokens, int start, int end)
    • leftPadLine

      public static String leftPadLine(String str, String fill)
    • leftPadString

      public static String leftPadString(String str, String fill, int length)
    • leftPadStringLeftTrim

      public static String leftPadStringLeftTrim(String str, String fill, int length)
      "abcdef", " ", 5 -> "bcdef"
      "abc", " ", 5 -> " abc"
    • leftPadStringRightTrim

      public static String leftPadStringRightTrim(String str, String fill, int length)
      "abcdef", " ", 5 -> "abcde"
      "abc", " ", 5 -> " abc"
    • leftTrimToLength

      public static String leftTrimToLength(String str, int maxLength)
      Removes the leftmost characters from a string.
      "abcdef", 5 -> "bcdef"
    • limitSize

      public static <C extends Collection<T>, T> C limitSize(C lines, int count, boolean trailing)
    • listAll

      public static String listAll(String path) throws IOException
      Throws:
      IOException
    • luminance

      public static double luminance(Color c)
    • map

      public static double map(double x, double inMin, double inMax, double outMin, double outMax)
    • map

      public static float map(float x, float inMin, float inMax, float outMin, float outMax)
    • map

      public static int map(int x, int inMin, int inMax, int outMin, int outMax)
    • map

      public static long map(long x, long inMin, long inMax, long outMin, long outMax)
    • matches

      public static boolean matches(org.json.JSONObject obj1, org.json.JSONObject solution)
      Compares two JSONObjects for a match.
    • max

      public static byte max(byte a, byte b)
    • max

      public static char max(char a, char b)
    • max

      public static short max(short a, short b)
    • maxContrast

      public static Color maxContrast(Color background)
    • maxContrast

      public static Color maxContrast(Color background, Color... choices)
    • maxContrast

      public static Color maxContrast(Color background, List<Color> choices)
    • maxContrast

      public static Color maxContrast(Color background, Stream<Color> stream)
    • median

      public static float median(float[] values)
    • millisTime

      public static long millisTime(Runnable run)
    • millisTime

      public static <T> Pair<T,Long> millisTime(Supplier<T> run)
    • min

      public static byte min(byte a, byte b)
    • min

      public static char min(char a, char b)
    • min

      public static short min(short a, short b)
    • nameStringToEnum

      public static String nameStringToEnum(String c)
    • nanoTime

      public static long nanoTime(Runnable run)
    • nanoTime

      public static <T> Pair<T,Long> nanoTime(Supplier<T> run)
    • newInstance

      public static <T> T newInstance(Class<T> clazz)
    • notImplemented

      public static void notImplemented()
    • oppositeColor

      public static Color oppositeColor(Color color)
    • pack

      public static float[] pack(float[]... arrays)
    • parseBoolean

      public static boolean parseBoolean(String value, boolean else_)
    • parseInteger

      public static int parseInteger(String value, int else_)
    • progressBar

      public static String progressBar(long budgetNanos, long usedNanos, boolean showOverFlow)
    • randomCharRange

      public static char randomCharRange(char min, char max)
    • randomColor

      public static Color randomColor(boolean alpha)
    • randomDoubleRange

      public static double randomDoubleRange(double min, double max)
    • randomFloatRange

      public static float randomFloatRange(float min, float max)
    • randomId

      public static long randomId(String seed)
    • randomIntArray

      public static int[] randomIntArray(int length, int min, int max)
    • randomIntRange

      public static int randomIntRange(int min, int max)
    • randomLongRange

      public static long randomLongRange(long min, long max)
    • randomShortRange

      public static byte randomShortRange(byte min, byte max)
    • randomShortRange

      public static short randomShortRange(short min, short max)
    • readBytesFile

      public static byte[] readBytesFile(String filePath)
    • readBytesSource

      public static byte[] readBytesSource(String location)
    • readFile

      public static ByteBuffer readFile(File file) throws IOException
      Throws:
      IOException
    • readPackagedBytesFile

      public static byte[] readPackagedBytesFile(Class<?> cl, String path)
    • readPackagedBytesFile

      public static byte[] readPackagedBytesFile(ClassLoader cl, String path)
    • readPackagedBytesFile

      public static byte[] readPackagedBytesFile(String path)
    • readPackagedStringFile

      public static String readPackagedStringFile(Class<?> cl, String path)
    • readPackagedStringFile

      public static String readPackagedStringFile(ClassLoader cl, String path)
    • readPackagedStringFile

      public static String readPackagedStringFile(String path)
    • readStringFile

      public static String readStringFile(File file)
    • readStringFile

      public static String readStringFile(String filePath)
    • readStringSource

      public static String readStringSource(String location)
    • recursiveList

      public static List<String> recursiveList(Path directory) throws IOException
      Throws:
      IOException
    • recursiveTree

      public static String recursiveTree(int depth, String path) throws IOException
      Throws:
      IOException
    • recursiveTree

      public static String recursiveTree(String path) throws IOException
      Throws:
      IOException
    • remainingByteBufferToArray

      public static byte[] remainingByteBufferToArray(ByteBuffer bb)
    • removeArray

      public static <T> T[] removeArray(T[] args, BiPredicate<Integer,Object> isToRemove)
    • removeArray

      public static <T> T[] removeArray(T[] args, int i)
    • removeFileExtension

      public static String removeFileExtension(String path)
    • repeatString

      public static String repeatString(String str, int count)
    • replace

      public static String replace(String s, char target, char replacement, int maxCount, boolean fromEnd)
    • replaceFileExtension

      public static String replaceFileExtension(String path, String ext)
    • replaceLast

      public static String replaceLast(String original, String target, String replacement)
    • reversed

      public static <T> List<T> reversed(List<T> list)
    • reversedStream

      public static <T> Stream<T> reversedStream(Collection<T> values)
    • rightPadString

      public static String rightPadString(String str, String fill, int length)
    • rightTrimToLength

      public static String rightTrimToLength(String str, int length)
      Removes the rightmost characters from a string. "abcdef", 5 -> "abcde"
    • round

      public static double round(double value, int decimals)
    • roundFill

      public static String roundFill(double value, int decimals)
    • safeClone

      public static <T extends Cloneable, V extends T> V safeClone(ThrowingSupplier<Object,CloneNotSupportedException> clone)
    • setAlpha

      public static Color setAlpha(Color color, int alpha)
    • setArray

      public static <T> T[] setArray(T[] arr, int index, Function<Integer,T> sup)
    • setArray

      public static <T> T[] setArray(T[] arr, int index, T val)
    • shuffle

      public static <T> T[] shuffle(T[] arr)
    • shuffle

      public static <T> T[] shuffle(T[] arr, int fac)
    • shuffled

      public static <T> List<T> shuffled(List<T> list)
    • snap

      public static double snap(double x, double interval)
    • snap

      public static int snap(int x, int interval)
    • sqlEscapeIdentifier

      @Deprecated public static String sqlEscapeIdentifier(String identifier)
      Deprecated.
    • stdDev

      public static float stdDev(float[] values)
    • swap

      public static <T> T[] swap(T[] arr, int i, int j)
    • throw_

      public static <T> T throw_(Exception e) throws Exception
      Throws:
      Exception
    • throw_

      public static <T> T throw_(Throwable e) throws Throwable
      Throws:
      Throwable
    • throwRuntime

      public static <T> T throwRuntime(Throwable e) throws RuntimeException
      Throws:
      RuntimeException
    • throwUnsupported

      public static void throwUnsupported()
    • throwUnsupported

      public static void throwUnsupported(String msg)
    • toByteArray

      public static byte[] toByteArray(ByteBuffer cb)
    • toBytes

      public static byte[] toBytes(InputStream inputStream)
    • toDate

      public static Date toDate(Timestamp value)
    • toIntArray

      public static int[] toIntArray(byte[] arr)
    • toIterable

      public static <V> Iterable<V> toIterable(Iterator<V> iterator)
    • toLineStream

      public static Stream<String> toLineStream(InputStream inputStream)
    • toMap

      public static <M extends Map<K, V>, K, V> M toMap(Supplier<M> mapSupplier, Object... objects)
    • toObjectArray

      public static Object[] toObjectArray(int[] data)
    • toPairList

      public static <A, B> List<Pair<A,B>> toPairList(Supplier<List<Pair<A,B>>> listSupplier, Object... objects)
    • toPrimitiveByte

      public static byte[] toPrimitiveByte(Object data)
    • toPrimitiveFloat

      public static float[] toPrimitiveFloat(Object data)
    • toPrimitiveInt

      public static int[] toPrimitiveInt(Object data)
    • toShuffledList

      public static <T> Collector<T,?,List<T>> toShuffledList()
    • toSimpleIdentityString

      public static String toSimpleIdentityString(Object value)
    • toStream

      public static <E> Stream<E> toStream(Iterator<E> it)
    • toString

      public static String toString(Exception e)
    • toString

      public static String toString(InputStream inputStream)
    • toTimestamp

      public static Timestamp toTimestamp(Date value)
    • toTripletList

      public static <A, B, C> List<Triplet<A,B,C>> toTripletList(Supplier<List<Triplet<A,B,C>>> listSupplier, Object... objects)
    • try_

      public static <T> T try_(ThrowingSupplier<T,Throwable> suplier, Function<Throwable,T> except)
    • validEmail

      public static boolean validEmail(String email)
    • validString

      public static boolean validString(String content)
    • valueOfOrdinal

      public static <E extends Enum<E>> E valueOfOrdinal(Class<E> type, int ordinal)
    • wrapLine

      public static String wrapLine(String text, int lineWidth)
    • wrapPrimitiveClass

      public static Class<?> wrapPrimitiveClass(Class<?> type)
    • zigZag

      public static float zigZag(float x, int period)
    • getUnwrappedAnnotations

      public static Annotation[] getUnwrappedAnnotations(AnnotatedElement element)
    • globToRegex

      public static String globToRegex(String trim)
    • throwIfNotEqual

      public static <V> BiFunction<? super V,? super V,? extends V> throwIfNotEqual(BiFunction<? super V,? super V,Throwable> throwSupplier)
    • requireNull

      public static void requireNull(Object obj)
    • requireNull

      public static void requireNull(Object obj, String msg)
    • requireNull

      public static void requireNull(Object obj, Supplier<String> msg)
    • requireNull

      public static void requireNull(Object obj, Function<Object,String> msg)
    • printMap

      public static void printMap(Map<String,Object> map, PrintStream printSteam)
    • valueToString

      public static String valueToString(Object value)
    • printTree

      public static void printTree(Map<String,Object> map, PrintStream out)
    • printTree

      public static String printTree(Map<String,Object> hints)
    • joining

      public static <T> Collector<T,?,StringBuilder> joining(StringBuilder builder, String prefix, String delimiter, String suffix, Function<T,String> mapper)
    • joining

      public static <T> Collector<T,?,StringBuilder> joining(StringBuilder builder, String prefixAndDelimiter, String suffix, Function<T,String> mapper)
    • joining

      public static <T> Collector<T,?,StringBuilder> joining(StringBuilder builder, String prefixAndDelimiter, String suffix)
    • joining

      public static <T> Collector<T,?,StringBuilder> joining(StringBuilder builder, String prefixAndDelimiter)
    • getColumnNames

      public static String[] getColumnNames(ResultSet generatedKeys) throws SQLException
      Throws:
      SQLException
    • getArrayDimension

      public static int getArrayDimension(Type clazz)
    • isArrayType

      public static boolean isArrayType(Type type)
    • getComponentType

      public static Type getComponentType(Type type)