JavaUtils
1. Import
Gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation 'com.github.alexsgi:java-utils:VERSION'
}Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.alexsgi</groupId>
<artifactId>java-utils</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
2. Usage
Time-oriented functions :
Run something delayed:
FutureTaskExecutor.runDelayed(Runnable runnable, int delayInMilliSeconds);FutureTaskExecutor.runDelayed(new Runnable() {
@Override
public void run() {
System.out.println("Message");
}
}, 5000);FutureTaskExecutor.runDelayed(Runnable runnable, int delayInMilliSeconds, boolean isTerminable);isTerminable : (default: false) if set to false, the timer will stop properly on finish of the runnable, otherwise (if set to true) the timer can be interrupted (e.g. by the main method).
Mathematical functions :
Standard:
double sum(double... summands);
double difference(double minuend, double... subtrahents);
double product(double... factors);
double quotient(double dividend, double... divisors);
BigDecimal bigSum(BigDecimal... summands);
BigDecimal bigDifference(BigDecimal minuend, BigDecimal... subtrahents);
BigDecimal bigProduct(BigDecimal... factors);
BigDecimal bigQuotient(BigDecimal dividend, BigDecimal... divisors);Example :
int sum = AdvMath.sum(5, 7, 0, 9, 8, 5, -7, 0);There are many other functions - just try it out !
Cryptography :
SHA2-512:
String sha2_512Hashed = Cryptography.hashSHA2("Example text");SHA3-512:
String sha3_512Hashed = Cryptography.hashSHA3("Example");Base64-Encoding:
String base64Encoded = Cryptography.base64Encryption("Example of the example");Change the hash length (default: 512) :
Cryptography.setHashLength(int hashLength);Cryptography.setHashLength(256);Get the hash length :
int hashLength = Cryptography.getHashLength();Reset the hash length (default: 512) :
Cryptography.resetHashLength();Properties :
Load properties from file :
Properties properties = PropertyManager.loadFromFile(new File("config.properties");Store properties object in file :
PropertyManager.storeInFile(properties, new File("newConfig.properties"));System :
Get all drives :
Drive[] drives = SystemInfo.getAllDrives();
for(Drive drive : drives) {
System.out.println(drive.getDriveName());
System.out.println(drive.getDriveLetter());
System.out.println(drive.getDriveDescription());
}Color :
Change the text color or even the background color via ANSI codes :
String textFormatted = TextColor.formatColor(String input, String color);
String backgroundFormatted = TextColor.formatBackground(String input, String backgroundColor);
String bothFormated = TextColor.formatColors(String input, String color, String backgroundColor);Following options are available :
RESET
BLACK
RED
GREEN
YELLOW
BLUE
PURPLE
CYAN
WHITE
BLACK_BACKGROUND
RED_BACKGROUND
GREEN_BACKGROUND
YELLOW_BACKGROUND
BLUE_BACKGROUND
PURPLE_BACKGROUND
CYAN_BACKGROUND
WHITE_BACKGROUNDExample :
TextColor.formatColor("Example", TextColor.CYAN);
TextColor.formatBackground("Example", TextColor.CYAN_BACKGROUND);
TextColor.formatColors("Example", TextColor.CYAN, TextColor.CYAN_BACKGROUND);UI - Screenshot :
Take a screenshot (PNG):
AdvImage.takeScreenshot(File nameOfTheScreenshot);
File file = new File("C:\\Users\\Public\\Desktop\\screenshot.png");
System.out.println(file.exists());
AdvImage.takeScreenshot(file);
System.out.println(file.exists());Output :
false
trueYou like JPEG ?
AdvImage.takeJPEGScreenshot(File nameOfTheScreenshot);
By the way : it returns a File object ! (normally not important)
You want to take multiple screenshots ?
AdvImage.takeScrenshots(File path, int amount, int delay);
AdvImage.takeScrenshots(File path, int amount, int delay, boolean inNewThread);
Important : the input file needs to be a directory !
Run something parallel :
ParallelTask.runParallel(Runnable runnable, CommandCallback callback);This creates a new thread and starts it.
Create many threads with the same runnable :
MultiThreads.createThreads(Runnable runnable, int amountOfThreads);Start all those Threads :
MultiThreads.startThreads();Interrupt all Threads :
MultiThreads.interruptThreads();Clear all Threads :
MultiThreads.clearThreads();Get current amount of Threads :
int amount = MultiThreads.getThreadAmount();Some tools for Strings :
Check if a String contains at least one of the params :
StringUtils.containsOneOf(String src, String... params);Check if a String contains all of the params :
StringUtils.containsAll(String src, String... params)
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
