RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.util.StringUtils Class Reference

Static Public Member Functions

static String appendIndefiniteArticle (String thing)
 Appends the determined indefinite article to thing.
static String appendPluralCheck (String thing)
 Appends the determined plural check to thing.
static String capitalize (String string)
static int convertAmount (String input)
static String format (int num)
static String formatPrice (long amount)
static String formatText (String s)
static String getAOrAn (String nextWord)
static long hash (String input)
 Hashes a given string input.
static int hashArchive (String string)
 Hashes a String using Jagex's algorithm, this method should be used to convert actual names to hashed names to lookup files within the FileSystem.
static String hashToString (long input)

Static Private Member Functions

static int _hash (String string)
 Hashes a String using Jagex's algorithm, this method should be used to convert actual names to hashed names to lookup files within the FileSystem.
static String determineIndefiniteArticle (String thing)
 Determines the indefinite article of thing.
static String determinePluralCheck (String thing)
 Determines the plural check of thing.

Static Private Attributes

static final char VALID_USERNAME_CHARACTERS []
 An array containing valid username characters.

Detailed Description

Definition at line 8 of file StringUtils.java.

Member Function Documentation

◆ _hash()

int com.runehive.util.StringUtils._hash ( String string)
staticprivate

Hashes a String using Jagex's algorithm, this method should be used to convert actual names to hashed names to lookup files within the FileSystem.

This method should only be used internally, it is marked deprecated as it does not properly hash the specified String. The functionality of this method is used to register a proper String hashing method. The scope of this method has been marked as private to prevent confusion.

Parameters
stringThe string to hash.
Returns
The hashed string.
Deprecated
This method should only be used internally as it does not correctly hash the specified String. See the note below for more information.

Definition at line 202 of file StringUtils.java.

202 {
203 return IntStream.range(0, string.length()).reduce(0, (hash, index) -> hash * 61 + string.charAt(index) - 32);
204 }

References hash().

Referenced by hashArchive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ appendIndefiniteArticle()

String com.runehive.util.StringUtils.appendIndefiniteArticle ( String thing)
static

Appends the determined indefinite article to thing.

Parameters
thingthe thing to append.
Returns
the thing after the indefinite article has been appended.

Definition at line 96 of file StringUtils.java.

96 {
97 return determineIndefiniteArticle(thing).concat(" " + thing);
98 }

References determineIndefiniteArticle().

Referenced by com.runehive.content.skill.impl.smithing.SmithingArmour.canInit(), com.runehive.content.skill.impl.HarvestingSkillAction.canRun(), and com.runehive.content.skill.impl.woodcutting.Woodcutting.clickObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ appendPluralCheck()

String com.runehive.util.StringUtils.appendPluralCheck ( String thing)
static

Appends the determined plural check to thing.

Parameters
thingthe thing to append.
Returns
the thing after the plural check has been appended.

Definition at line 86 of file StringUtils.java.

86 {
87 return thing.concat(determinePluralCheck(thing));
88 }

References determinePluralCheck().

Referenced by com.runehive.content.skill.impl.ProducingSkillAction.canRun().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ capitalize()

◆ convertAmount()

int com.runehive.util.StringUtils.convertAmount ( String input)
static

Definition at line 29 of file StringUtils.java.

29 {
30 try {
31 input = input.toLowerCase().replace(" ", "");
32
33 int pos = input.indexOf('k');
34
35 if (pos != -1) {
36 return Integer.parseInt(input.substring(0, pos)) * 1_000;
37 }
38
39 pos = input.indexOf('m');
40
41 if (pos != -1) {
42 return Integer.parseInt(input.substring(0, pos)) * 1_000_000;
43 }
44
45 pos = input.indexOf('b');
46
47 if (pos != -1) {
48 return Integer.parseInt(input.substring(0, pos)) * 1_000_000_000;
49 }
50
51 } catch (Exception ex) {
52
53 }
54 return 0;
55 }

◆ determineIndefiniteArticle()

String com.runehive.util.StringUtils.determineIndefiniteArticle ( String thing)
staticprivate

Determines the indefinite article of thing.

Parameters
thingthe thing to determine for.
Returns
the indefinite article.

Definition at line 63 of file StringUtils.java.

63 {
64 char first = thing.toLowerCase().charAt(0);
65 boolean vowel = first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u';
66 return vowel ? "an" : "a";
67 }

Referenced by appendIndefiniteArticle().

Here is the caller graph for this function:

◆ determinePluralCheck()

String com.runehive.util.StringUtils.determinePluralCheck ( String thing)
staticprivate

Determines the plural check of thing.

Parameters
thingthe thing to determine for.
Returns
the plural check.

Definition at line 75 of file StringUtils.java.

75 {
76 boolean needsPlural = !thing.endsWith("s") && !thing.endsWith(")");
77 return needsPlural ? "s" : "";
78 }

Referenced by appendPluralCheck().

Here is the caller graph for this function:

◆ format()

String com.runehive.util.StringUtils.format ( int num)
static

Definition at line 104 of file StringUtils.java.

104 {
105 return NumberFormat.getInstance().format(num);
106 }

◆ formatPrice()

String com.runehive.util.StringUtils.formatPrice ( long amount)
static

Definition at line 18 of file StringUtils.java.

18 {
19 if (amount >= 1_000 && amount < 1_000_000) {
20 return (amount / 1_000) + "K";
21 } else if (amount >= 1_000_000 && amount < 1_000_000_000) {
22 return (amount / 1_000_000) + "M";
23 } else if (amount >= 1_000_000_000) {
24 return (amount / 1_000_000_000) + "B";
25 }
26 return "" + amount;
27 }

◆ formatText()

String com.runehive.util.StringUtils.formatText ( String s)
static

Definition at line 108 of file StringUtils.java.

108 {
109 for (int i = 0; i < s.length(); i++) {
110 if (i == 0) {
111 s = String.format("%s%s", Character.toUpperCase(s.charAt(0)), s.substring(1));
112 }
113 if (!Character.isLetterOrDigit(s.charAt(i))) {
114 if (i + 1 < s.length()) {
115 s = String.format("%s%s%s", s.subSequence(0, i + 1), Character.toUpperCase(s.charAt(i + 1)), s.substring(i + 2));
116 }
117 }
118 }
119 return s.replace("_", " ");
120 }

◆ getAOrAn()

String com.runehive.util.StringUtils.getAOrAn ( String nextWord)
static

Definition at line 122 of file StringUtils.java.

122 {
123 String s = "a";
124 final char c = nextWord.toUpperCase().charAt(0);
125 if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
126 s = "an";
127 }
128 return s;
129 }

Referenced by com.runehive.game.world.entity.combat.magic.Autocast.sendSelectionInterface(), and com.runehive.content.skill.impl.herblore.Herblore.useItem().

Here is the caller graph for this function:

◆ hash()

long com.runehive.util.StringUtils.hash ( String input)
static

Hashes a given string input.

Parameters
inputThe string to hash.
Returns
A hash as a long.

Definition at line 151 of file StringUtils.java.

151 {
152 long hash = 0;
153
154 for (int index = 0; index < input.length(); index++) {
155 char key = input.charAt(index);
156
157 hash *= 37;
158
159 if (key >= 'A' && key <= 'Z') {
160 hash += (1 + key) - 65;
161 } else if (key >= 'a' && key <= 'z') {
162 hash += (1 + key) - 97;
163 } else if (key >= '0' && key <= '9') {
164 hash += (27 + key) - 48;
165 }
166 }
167
168 while (hash % 37 == 0 && hash != 0) hash /= 37;
169 return hash;
170 }
val index

References hash().

Referenced by _hash(), hash(), and hashToString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hashArchive()

int com.runehive.util.StringUtils.hashArchive ( String string)
static

Hashes a String using Jagex's algorithm, this method should be used to convert actual names to hashed names to lookup files within the FileSystem.

Parameters
stringThe string to hash.
Returns
The hashed string.

Definition at line 179 of file StringUtils.java.

179 {
180 return _hash(string.toUpperCase());
181 }

References _hash().

Referenced by com.runehive.fs.cache.archive.Archive.getSector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hashToString()

String com.runehive.util.StringUtils.hashToString ( long input)
static

Definition at line 131 of file StringUtils.java.

131 {
132 int length = 12;
133 char decoded[] = new char[length];
134
135 while (input != 0) {
136 long hash = input;
137 input /= 37;
138 int index = (int) (hash - input * 37);
139 decoded[length--] = VALID_USERNAME_CHARACTERS[index];
140 }
141
142 return new String(decoded, length, decoded.length - length);
143 }

References hash(), and VALID_USERNAME_CHARACTERS.

Here is the call graph for this function:

Member Data Documentation

◆ VALID_USERNAME_CHARACTERS

final char com.runehive.util.StringUtils.VALID_USERNAME_CHARACTERS[]
staticprivate
Initial value:
= {
'_',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
}

An array containing valid username characters.

Definition at line 11 of file StringUtils.java.

11 {
12 '_',
13 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
14 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
15 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
16 };

Referenced by hashToString().


The documentation for this class was generated from the following file: