Skip to content

Repository files navigation

JavaUtils

CIGitHub Release

JavaUtils is a small library to ease programming with Java.

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. Features

Time-oriented functions :

Run something delayed:

FutureTaskExecutor.runDelayed(Runnablerunnable, intdelayInMilliSeconds);
FutureTaskExecutor.runDelayed(newRunnable(){
@Overridepublicvoidrun(){
System.out.println("This message will be printed after 5000 ms");
}
}, 5000);

FutureTaskExecutor.runDelayed(Runnablerunnable, intdelayInMilliSeconds, booleanisTerminable);

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).


Cryptography :

SHA2-512:

Stringsha2_512Hashed = Cryptography.hashSHA2("Example text");

SHA3-512:

Stringsha3_512Hashed = Cryptography.hashSHA3("Example");

Base64-Encoding:

Stringbase64Encoded = Cryptography.base64Encryption("Example of the example");

Change the hash length (default: 512) :

Cryptography.setHashLength(inthashLength);
Cryptography.setHashLength(256);

Get the hash length :

inthashLength = Cryptography.getHashLength();

Reset the hash length (default: 512) :

Cryptography.resetHashLength();

System :

Get all drives :

Drive[] drives = SystemInfo.getAllDrives();
for(Drivedrive : 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 :

StringtextFormatted = TextColor.formatColor(Stringinput, Stringcolor);
StringbackgroundFormatted = TextColor.formatBackground(Stringinput, StringbackgroundColor);
StringbothFormated = TextColor.formatColors(Stringinput, Stringcolor, StringbackgroundColor);

Following options are available :

RESETBLACKREDGREENYELLOWBLUEPURPLECYANWHITEBLACK_BACKGROUNDRED_BACKGROUNDGREEN_BACKGROUNDYELLOW_BACKGROUNDBLUE_BACKGROUNDPURPLE_BACKGROUNDCYAN_BACKGROUNDWHITE_BACKGROUND

Example :

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);
Filefile = newFile("C:\\Users\\Public\\Desktop\\screenshot.png");

JPEG screenshots:

AdvImage.takeJPEGScreenshot(File nameOfTheScreenshot);

You want to take multiple screenshots?

AdvImage.takeScrenshots(File path, int amount, int delay);
AdvImage.takeScrenshots(File path, int amount, int delay, boolean inNewThread);

Notice: the input file needs to be a directory


Create many threads with the same runnable :

MultiThreads.createThreads(Runnablerunnable, intamountOfThreads);

Start all threads :

MultiThreads.startThreads();

Interrupt all Threads :

MultiThreads.interruptThreads();

Clear all Threads :

MultiThreads.clearThreads();

Get current amount of Threads :

intamount = MultiThreads.getThreadAmount();

Some tools for Strings :

Check if a String contains at least one of the params :

StringUtils.containsOneOf(Stringsrc, String... params);

Check if a String contains all of the params :

StringUtils.containsAll(Stringsrc, String... params)

Releases

Packages

Used by

Contributors

Languages