AltitudeQuests/src/main/java/com/alttd/altitudequests/util/Utilities.java

32 lines
922 B
Java
Raw Normal View History

2022-05-01 19:48:52 +00:00
package com.alttd.altitudequests.util;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
2022-05-01 19:48:52 +00:00
public class Utilities {
public static double round(double num, int precision) {
double scale = Math.pow(10, precision);
return ((int) (num * scale)) / scale;
}
public static int randomOr0(int max) {
if (max <= 1)
return 0;
2022-09-05 17:28:37 +00:00
return new Random().nextInt(0, max);
}
public static int getYearDay() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
return (calendar.get(Calendar.YEAR) * 1000) + calendar.get(Calendar.DAY_OF_YEAR);
}
public static String formatName(String name) {
name = name.toLowerCase().replaceAll("_", " ");
2022-09-05 21:35:29 +00:00
if (name.length() == 1)
return name.toUpperCase();
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
2022-05-01 19:48:52 +00:00
}