Skip to content

Commit 6d5b21f

Browse files
Remove obsolete Hashid class
The POJO has been implemented to simplify the handling of the binding between the numbers and their hash value, but users should implement the simple POJO on their own instead of forcing them to use this approach. The public API methods now returning the primitive values which have been hold by the Hashid class. GH-9
1 parent 4fa3d22 commit 6d5b21f

File tree

3 files changed

+19
-150
lines changed

3 files changed

+19
-150
lines changed

src/main/java/com/arcticicestudio/icecore/hashids/Hashid.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/main/java/com/arcticicestudio/icecore/hashids/Hashids.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public final class Hashids {
103103
private final String separators;
104104

105105
/**
106-
* Constructs a new Hashid with all default values.
106+
* Constructs a new instance with all default values.
107107
* <p>
108108
* <ul>
109109
* <li>no salt</li>
@@ -117,7 +117,7 @@ public Hashids() {
117117
}
118118

119119
/**
120-
* Constructs a new Hashid with the specified salt and the default minimal hash length, alphabet and separators.
120+
* Constructs a new instance with the specified salt and the default minimal hash length, alphabet and separators.
121121
* <p>
122122
* <ul>
123123
* <li>no minimal hash length</li>
@@ -132,7 +132,7 @@ public Hashids(String salt) {
132132
}
133133

134134
/**
135-
* Constructs a new Hashid with the specified salt and the minimal hash length and the default alphabet and
135+
* Constructs a new instance with the specified salt and the minimal hash length and the default alphabet and
136136
* separators.
137137
* <p>
138138
* <ul>
@@ -148,7 +148,7 @@ public Hashids(String salt, int minHashLength) {
148148
}
149149

150150
/**
151-
* Constructs a new Hashid with the specified salt and alphabet and the default minimal hash length and separators.
151+
* Constructs a new instance with the specified salt and alphabet and the default minimal hash length and separators.
152152
* <p>
153153
* <ul>
154154
* <li>no minimal hash length</li>
@@ -163,7 +163,7 @@ public Hashids(String salt, String alphabet) {
163163
}
164164

165165
/**
166-
* Constructs a new Hashid with the specified salt, minimal hash length and alphabet and the default separators.
166+
* Constructs a new instance with the specified salt, minimal hash length and alphabet and the default separators.
167167
* <p>
168168
* <ul>
169169
* <li>{@link #DEFAULT_SEPARATORS}</li>
@@ -178,7 +178,7 @@ public Hashids(String salt, int minHashLength, String alphabet) {
178178
}
179179

180180
/**
181-
* Constructs a new Hashid with the specified salt, minimal hash length, alphabet and separators.
181+
* Constructs a new instance with the specified salt, minimal hash length, alphabet and separators.
182182
*
183183
* @param salt the salt value
184184
* @param minHashLength the minimal length of the hash
@@ -352,11 +352,11 @@ public Hashids build() {
352352
* Encode number(s).
353353
*
354354
* @param numbers the number(s) to encode
355-
* @return the Hashid instance with the number(s) and the encoded string
355+
* @return the hash
356356
*/
357-
public Hashid encode(long... numbers) {
357+
public String encode(long... numbers) {
358358
if (numbers.length == 0) {
359-
return Hashid.EMPTY;
359+
return "";
360360
}
361361
return doEncode(numbers);
362362
}
@@ -407,18 +407,18 @@ public String encodeHex(String hex) {
407407
while (matcher.find()) {
408408
matched.add(Long.parseLong("1" + matcher.group(), 16));
409409
}
410-
return doEncode(toArray(matched)).toString();
410+
return doEncode(toArray(matched));
411411
}
412412

413413
/**
414414
* Decode an encoded string.
415415
*
416416
* @param hash the encoded string
417-
* @return the Hashid instance with the decoded hash and decoded number(s)
417+
* @return the decoded number(s)
418418
*/
419-
public Hashid decode(String hash) {
419+
public long[] decode(String hash) {
420420
if (isEmpty(hash)) {
421-
return Hashid.EMPTY;
421+
return new long[0];
422422
}
423423
return doDecode(hash, alphabet);
424424
}
@@ -433,7 +433,7 @@ public long[] decodeLongNumbers(String hash) {
433433
if (isEmpty(hash)) {
434434
return new long[0];
435435
}
436-
return doDecode(hash, alphabet).numbers();
436+
return doDecode(hash, alphabet);
437437
}
438438

439439
/**
@@ -447,7 +447,7 @@ public int[] decodeIntegerNumbers(String hash) {
447447
if (isEmpty(hash)) {
448448
return new int[0];
449449
}
450-
long[] numbers = doDecode(hash, alphabet).numbers();
450+
long[] numbers = doDecode(hash, alphabet);
451451
int[] ints = new int[numbers.length];
452452
for (int idx = 0; idx < numbers.length; idx++) {
453453
long number = numbers[idx];
@@ -474,7 +474,7 @@ public String decodeHex(String hash) {
474474
return sb.toString();
475475
}
476476

477-
private Hashid doEncode(long... numbers) {
477+
private String doEncode(long... numbers) {
478478
int numberHashInt = 0;
479479
for (int idx = 0; idx < numbers.length; idx++) {
480480
if (numbers[idx] < 0 || numbers[idx] > MAX_NUMBER_VALUE) {
@@ -525,10 +525,10 @@ private Hashid doEncode(long... numbers) {
525525
result.replace(0, result.length(), result.substring(startPos, startPos + minHashLength));
526526
}
527527
}
528-
return new Hashid(numbers, result.toString());
528+
return result.toString();
529529
}
530530

531-
private Hashid doDecode(String hash, String alphabet) {
531+
private long[] doDecode(String hash, String alphabet) {
532532
final List<Long> result = new ArrayList<>();
533533
int idx = 0;
534534
String[] hashArray = hash.replaceAll("[" + guards + "]", " ").split(" ");
@@ -550,8 +550,7 @@ private Hashid doDecode(String hash, String alphabet) {
550550
result.add(unhash(subHash, alphabet));
551551
}
552552
}
553-
long[] resultArray = toArray(result);
554-
return new Hashid(resultArray, hash);
553+
return toArray(result);
555554
}
556555

557556
private static String consistentShuffle(String alphabet, String salt) {

src/test/java/com/arcticicestudio/icecore/hashids/HashidTest.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)