Skip to content

Commit 8617f4c

Browse files
Revise public- and internal API
Due to the relations between the changes it is necessary to keep those in one commit which are explained in detail below. The main change of this revise is the clean rewrite of the internal API logic. Public API breaking changes: * All parameterized constructors have been removed due to the already provided interfaces through the Hashids.Builder class. It provides methods to achieve the same instance configuration, an instance with the default interoperable configurations is still available through the default constructor or by using default constructed builder instance. * The Hashids.Builder methods "minHashLength(int) : Builder" has been renamed to "minLength(int) : Builder" to adapt to the the builder methods naming style. * The methods * encodeToString(long...) : String * encodeToString(int...) : String * decodeLongNumbers(String) : long[] * decodeIntegerNumbers(String) : int[] are unnecessary now due to the removement of the "Hashid" class and have also been removed. The internal API has been redesigned and rewritten from scratch regarding optimizations for Java 8, reduction of complexity, performance and the new code style guide conventions. Internal API changes: * The private main logic methods "doEncode(long...)" and "doDecode(String, String)" have been removed and rewritten from scratch into the associated public API methods. * The private method "consistentShuffle(String, String) : String" has been rewritten from scratch and renamed to "shuffle(char[], char[]) : char[]". * The private methods "hash(long, String)" and "unhash(String, String)" have been rewritten from scratch and renamed to "transform(long, char[], StringBuilder, int)" and "transform(char[], char"])". * The primary algorithm logic, which was mainly implemented in the "doEncode" and "doDecode" private methods, has been rewritten from scratch and modularized into the new methods "deriveNewAlphabet(char[], char[], char) : char[]" and "filterSeparators(char[], char[]) : char[]". * The private support methods "toArray(List<Long>) : long[]" and "isEmpty(String) : boolean" have been removed. The new "HashidsFeature" enum contains constants for various features which can be enabled per instance through the Hashids.Builder method "features(HashidFeature) : Builder". Next to the changes listed above the public API now provides the "decodeOne(String) : Optional<Long>" method to simplify the use-case where the amount of resulting numbers is known before to handle the return value as single value instead of an array. This improves the prevention of an ArrayIndexOutOfBounceException when the user tries to access an non-existent array index due to an failed encoding- or decoding. All unit tests have also been rewritten from scratch to match the new API and include as much use-cases as possible and increase the code coverage. The interoperability tests run against the latest version of the reference implementation "hashids.js". The script is loaded by using thge maven-frontend-plugin which installs NodeJS locally and runs NPM to install all dependencies defined in the package.json. The parameterized "InteropHashidsTest" class compares the results of both algorithms to ensure interoperability. GH-9
1 parent 40231ad commit 8617f4c

File tree

14 files changed

+1353
-488
lines changed

14 files changed

+1353
-488
lines changed

.idea/runConfigurations/Interop_Tests.xml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Unit_Tests.xml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ notifications:
2424
on_success: never
2525
on_failure: change
2626
before_script: mvn --version
27-
script: mvn -B clean verify -P code-coverage
27+
script: mvn -B clean verify -P node,code-coverage
2828
after_success:
2929
- bash <(curl -s https://codecov.io/bash)

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ test:
2727
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
2828
- find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
2929
override:
30-
- mvn clean verify -P code-coverage
30+
- mvn -B clean verify -P node,code-coverage
3131
- find . -type f -regextype posix-egrep -regex ".*/target/(.*asc|.*jar|.*md5|.*pom|.*sha1)" -exec cp {} $CIRCLE_ARTIFACTS \;

icecore-hashids.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
<orderEntry type="sourceFolder" forTests="false" />
1515
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
1616
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
17+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-junit:2.0.0.0" level="project" />
18+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:java-hamcrest:2.0.0.0" level="project" />
1719
</component>
1820
</module>

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "icecore-hashids",
3+
"version": "0.3.0",
4+
"private": true,
5+
"description": "A lightweight generator for short, unique, non-sequential and decodable Hashids from positive unsigned (long) integer numbers.",
6+
"author": {
7+
"name": "Arctic Ice Studio",
8+
"url": "http://arcticicestudio.com"
9+
},
10+
"license": "Apache 2.0",
11+
"dependencies": {},
12+
"devDependencies": {
13+
"hashids": "1.1.1"
14+
},
15+
"scripts": {}
16+
}

pom.xml

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
<java.version>1.8</java.version>
7272
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
7373
<maven.version.min>3.0.4</maven.version.min>
74-
7574
<checkstyle.version>8.0</checkstyle.version>
7675
<junit.version>4.12</junit.version>
77-
<hamcrest.version>1.3</hamcrest.version>
76+
<hamcrest.version>2.0.0.0</hamcrest.version>
77+
<node.version>v8.2.1</node.version>
7878
</properties>
7979

8080
<scm>
@@ -99,7 +99,7 @@
9999

100100
<dependency>
101101
<groupId>org.hamcrest</groupId>
102-
<artifactId>hamcrest-core</artifactId>
102+
<artifactId>hamcrest-junit</artifactId>
103103
<version>${hamcrest.version}</version>
104104
<scope>test</scope>
105105
</dependency>
@@ -286,6 +286,54 @@
286286
</pluginRepositories>
287287

288288
<profiles>
289+
<profile>
290+
<id>node</id>
291+
<build>
292+
<plugins>
293+
<plugin>
294+
<groupId>org.apache.maven.plugins</groupId>
295+
<artifactId>maven-clean-plugin</artifactId>
296+
<configuration>
297+
<filesets>
298+
<fileset>
299+
<directory>node_modules</directory>
300+
</fileset>
301+
</filesets>
302+
</configuration>
303+
</plugin>
304+
305+
<plugin>
306+
<groupId>com.github.eirslett</groupId>
307+
<artifactId>frontend-maven-plugin</artifactId>
308+
<version>1.5</version>
309+
<executions>
310+
<execution>
311+
<id>install-node-and-npm</id>
312+
<goals>
313+
<goal>install-node-and-npm</goal>
314+
</goals>
315+
<configuration>
316+
<nodeVersion>${node.version}</nodeVersion>
317+
<installDirectory>${project.build.directory}</installDirectory>
318+
</configuration>
319+
</execution>
320+
<execution>
321+
<id>npm install</id>
322+
<goals>
323+
<goal>npm</goal>
324+
</goals>
325+
<phase>generate-resources</phase>
326+
<configuration>
327+
<installDirectory>${project.build.directory}</installDirectory>
328+
<arguments>install</arguments>
329+
</configuration>
330+
</execution>
331+
</executions>
332+
</plugin>
333+
</plugins>
334+
</build>
335+
</profile>
336+
289337
<profile>
290338
<id>code-coverage</id>
291339
<build>
@@ -317,15 +365,15 @@
317365
<id>jfrog</id>
318366
<distributionManagement>
319367
<downloadUrl>https://github.com/arcticicestudio/icecore-hashids</downloadUrl>
320-
<snapshotRepository>
321-
<id>bintray</id>
322-
<name>OSS JFrog</name>
323-
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
324-
</snapshotRepository>
368+
<snapshotRepository>
369+
<id>bintray</id>
370+
<name>OSS JFrog</name>
371+
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
372+
</snapshotRepository>
325373
<repository>
326-
<id>bintray</id>
327-
<name>JFrog Bintray</name>
328-
<url>https://api.bintray.com/maven/arcticicestudio/IceCore/icecore-hashids/;publish=1</url>
374+
<id>bintray</id>
375+
<name>JFrog Bintray</name>
376+
<url>https://api.bintray.com/maven/arcticicestudio/IceCore/icecore-hashids/;publish=1</url>
329377
</repository>
330378
</distributionManagement>
331379
</profile>

0 commit comments

Comments
 (0)