public class GeneralTools extends Object
Constructor and Description |
---|
GeneralTools() |
Modifier and Type | Method and Description |
---|---|
static String |
byteToHex(byte[] data)
Byte to hex.
|
static int |
computeLevenshteinDistance(String str1,
String str2)
Compute levenshtein distance of two strings.
|
static byte[] |
decodeBase64(String str)
Decode a base64 string.
|
static boolean |
delete(File f)
Recursively delete file or directory.
|
static String |
encodeBase64(byte[] bytes)
Encode some byte in base64.
|
static String |
fileToString(File f)
Read a file and return its contents as a string.
|
static String |
hash(String msg)
Hash a message using either sha256/sha1/sha512/md5, whatever is available.
|
static String |
hashMd5(String msg)
Hash a message using MD5.
|
static String |
hashSha1(String msg)
Hash a message using SHA1.
|
static String |
hashSha256(String msg)
Hash a message using SHA256.
|
static String |
hashSha512(String msg)
Hash a message using SHA512.
|
static int |
minimum(int a,
int b,
int c)
Get the minimum of 3 values.
|
static String |
prettyDouble(Double d,
Integer neglect)
Beautify the display of a double
d . |
static String |
prettyDouble(Double d,
Integer neglect,
String pre,
String post)
Beautify the display of a double
d . |
static String |
repeat(String s,
int times)
Repeat a string.
|
static int |
sizeOfIterable(Iterable<?> iterable)
Calculate the size of iterable object.
|
static void |
stringToFile(String s,
File f)
Write a string to a file.
|
public static int minimum(int a, int b, int c)
a
- the ab
- the bc
- the cpublic static int computeLevenshteinDistance(String str1, String str2)
str1
- the str1str2
- the str2public static String repeat(String s, int times)
s
- the stringtimes
- the number of times to repeat spublic static String prettyDouble(Double d, Integer neglect)
d
. If the double is an int
we'll omit the .0
. Additionally you may define an int to
neglect (e.g. 0
or 1
), thus, if
d == neglect
you'll get an empty string. Especially designed
to display equations and stuff (e.g. omit an multiplier
of 1
or an offset of 0
).d
- the double to printneglect
- an integer to neglect. Can be null if you don't want to omit any
numberpublic static String prettyDouble(Double d, Integer neglect, String pre, String post)
d
. If the double is an int
we'll omit the .0
. Additionally you may define an int to
neglect (e.g. 0
or 1
), thus, if
d == neglect
you'll get an empty string. Especially designed
to display equations and stuff (e.g. omit an multiplier
of 1
or an offset of 0
).
You can also define a pre- and post-word to be put before or after,
respectively. That means, if d == neglect
we will return
""
, otherwise pre + pretty (d) + post
.d
- the double to printneglect
- an integer to neglect. Can be null if you don't want to omit any
numberpre
- the string to put in front of d, if d != neglectpost
- the string to put after d, if d != neglectpublic static String byteToHex(byte[] data)
data
- the datapublic static String hash(String msg)
msg
- the messagepublic static String hashMd5(String msg)
msg
- the messagepublic static String hashSha1(String msg)
msg
- the messagepublic static String hashSha256(String msg)
msg
- the messagepublic static String hashSha512(String msg)
msg
- the messagepublic static String encodeBase64(byte[] bytes)
bytes
- the bytespublic static byte[] decodeBase64(String str)
str
- the string encoded in base64public static String fileToString(File f) throws IOException
f
- the fileIOException
public static void stringToFile(String s, File f) throws IOException
s
- the stringf
- the fileIOException
- Signals that an I/O exception has occurred.public static int sizeOfIterable(Iterable<?> iterable)
iterable
- the iterablepublic static boolean delete(File f) throws IOException
f
- the file/dir to deleteIOException
- Signals that an I/O exception has occurred.Copyright © 2017. All rights reserved.