Java tutorial
/* * Part of Minecraft Brawl. * Licensed under the MIT license. * * (more here later) */ package org.infernogames.mb.Utils; import java.util.concurrent.TimeUnit; public final class StringUtils extends org.apache.commons.lang.StringUtils { public static String formatSeconds(int seconds) { int millis = seconds * 1000; long min = TimeUnit.MILLISECONDS.toMinutes(millis); long sec = TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)); if ((int) sec == 0 && min > 0) { if ((int) min == 1) { return min + " minute"; } else { return min + " minutes"; } } else if ((int) min == 0) { if ((int) sec == 1) { return sec + " second"; } else { return sec + " seconds"; } } return String.format("%d minute(s) and %d second(s)", min, sec); } public static String formatEnum(Enum<?> e) { String name = e.name().toLowerCase().replaceAll("_", " "); String[] arr = name.split(" "); StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(Character.toUpperCase(arr[i].charAt(0))).append(arr[i].substring(1)).append(" "); } return sb.toString().trim(); } public static String format(String s, Object... e) { for (int i = 1; i <= e.length; i++) { s = s.replaceAll("%" + i, e[i - 1].toString()); } return s; } }