46 private static final char VALID_USERNAME_CHARACTERS[] = {
48 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
49 'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
50 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'
53 public static String formatPrice(
long amount) {
54 if (amount >= 1_000 && amount < 1_000_000) {
55 return (amount / 1_000) +
"K";
56 }
else if (amount >= 1_000_000 && amount < 1_000_000_000) {
57 return (amount / 1_000_000) +
"M";
58 }
else if (amount >= 1_000_000_000) {
59 return (amount / 1_000_000_000) +
"B";
64 public static int convertAmount(String input) {
66 input = input.toLowerCase().replace(
" ",
"");
68 int pos = input.indexOf(
'k');
71 return Integer.parseInt(input.substring(0, pos)) * 1_000;
74 pos = input.indexOf(
'm');
77 return Integer.parseInt(input.substring(0, pos)) * 1_000_000;
80 pos = input.indexOf(
'b');
83 return Integer.parseInt(input.substring(0, pos)) * 1_000_000_000;
86 }
catch (Exception ex) {
98 private static String determineIndefiniteArticle(String thing) {
99 char first = thing.toLowerCase().charAt(0);
100 boolean vowel = first ==
'a' || first ==
'e' || first ==
'i' || first ==
'o' || first ==
'u';
101 return vowel ?
"an" :
"a";
110 private static String determinePluralCheck(String thing) {
111 boolean needsPlural = !thing.endsWith(
"s") && !thing.endsWith(
")");
112 return needsPlural ?
"s" :
"";
122 return thing.concat(determinePluralCheck(thing));
132 return determineIndefiniteArticle(thing).concat(
" " + thing);
135 public static String capitalize(String
string) {
136 return Character.toUpperCase(
string.charAt(0)) +
string.substring(1);
139 public static String format(
int num) {
140 return NumberFormat.getInstance().format(num);
143 public static String formatText(String s) {
144 for (
int i = 0; i < s.length(); i++) {
146 s = String.format(
"%s%s", Character.toUpperCase(s.charAt(0)), s.substring(1));
148 if (!Character.isLetterOrDigit(s.charAt(i))) {
149 if (i + 1 < s.length()) {
150 s = String.format(
"%s%s%s", s.subSequence(0, i + 1), Character.toUpperCase(s.charAt(i + 1)), s.substring(i + 2));
154 return s.replace(
"_",
" ");
157 public static String getAOrAn(String nextWord) {
159 final char c = nextWord.toUpperCase().charAt(0);
160 if (c ==
'A' || c ==
'E' || c ==
'I' || c ==
'O' || c ==
'U') {
166 public static String hashToString(
long input) {
168 char decoded[] =
new char[length];
173 int index = (int) (
hash - input * 37);
174 decoded[length--] = VALID_USERNAME_CHARACTERS[index];
177 return new String(decoded, length, decoded.length - length);
186 public static long hash(String input) {
189 for (
int index = 0; index < input.length(); index++) {
190 char key = input.charAt(index);
194 if (key >=
'A' && key <=
'Z') {
195 hash += (1 + key) - 65;
196 }
else if (key >=
'a' && key <=
'z') {
197 hash += (1 + key) - 97;
198 }
else if (key >=
'0' && key <=
'9') {
199 hash += (27 + key) - 48;
215 return _hash(
string.toUpperCase());
237 private static int _hash(String
string) {
238 return IntStream.range(0,
string.length()).reduce(0, (
hash, index) ->
hash * 61 +
string.charAt(index) - 32);