Add a progress helper

This commit is contained in:
Aria 2023-05-06 02:29:19 -07:00
parent 150027f1cd
commit c6d83e67d5
2 changed files with 39 additions and 1 deletions

View file

@ -12,7 +12,7 @@ plugins {
id 'maven-publish'
}
version = "1.1.3"
version = "1.1.4"
group = "dev.zontreck"
archivesBaseName = "LibAC"
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

View file

@ -0,0 +1,38 @@
package dev.zontreck.ariaslib.util;
import java.util.concurrent.atomic.AtomicInteger;
public class Progress
{
private int maximum;
private int current;
private AtomicInteger tickNum = new AtomicInteger(0);
private static final String TICKS="-\\|/";
public String getSpinnerTick()
{
if(tickNum.get()>=TICKS.length()) tickNum.set(0);
return "[ " + TICKS.substring(tickNum.getAndIncrement(), tickNum.get()) + " ]";
}
public Progress(int maximum)
{
current=0;
this.maximum=maximum;
}
public int getPercent(){
return (current*100/maximum);
}
public String getPercentStr()
{
return (getPercent()+"%");
}
public static int getPercentOf(int current, int max)
{
return (current*100/max);
}
}