Skip to content

Commit 447c39d

Browse files
author
Kelvin Wijaya
authored
Merge pull request #2 from GovTechSG/developement
commit changes for Issue #1
2 parents 679a94f + a5a1dcc commit 447c39d

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
## Added
44
### V1.0-SNAPSHOT
5-
+ Initial release with HMAC256 and RSA256 signing utility
5+
+ Initial release with HMAC256 and RSA256 signing utility
6+
### V1.0.1-SNAPSHOT
7+
+ Enhancement for Issue #1 - ApiList sorting is not based on key first then value

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id 'com.github.kt3k.coveralls' version '2.6.3'
55
}
66

7-
version '1.0-SNAPSHOT'
7+
version '1.0.1-SNAPSHOT'
88

99
tasks.withType(JavaCompile) {
1010
options.encoding = "UTF-8"

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.api.util</groupId>
44
<artifactId>ApiSecurity</artifactId>
5-
<version>1.0-SNAPSHOT</version>
5+
<version>1.0.1-SNAPSHOT</version>
66
<build>
77
<plugins>
88
<plugin>

src/main/java/com/api/util/ApiSecurity/ApiList.java

+20-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import java.util.AbstractMap.SimpleEntry;
33
import java.util.ArrayList;
44
import java.util.Collections;
5+
import java.util.List;
56
import java.util.Map.Entry;
7+
import java.util.stream.Collectors;
68

79
/**
810
* @author GDS-PDD
@@ -29,19 +31,25 @@ public String toString() {
2931

3032
public String toString(String delimiter, Boolean sort, Boolean quote)
3133
{
32-
ArrayList<String> list = new ArrayList<String>();
33-
34-
String format = "%s=%s";
35-
if (quote) format = "%s=\"%s\"";
36-
37-
for (Entry<String, String> item : this)
38-
{
39-
list.add(String.format(format, item.getKey(), item.getValue()));
34+
List<String> list = new ArrayList<String>();
35+
36+
final String format = (quote ? "%s=\"%s\"" : "%s=%s");
37+
38+
/* Sort key first then value*/
39+
if (sort){
40+
list = this.stream()
41+
.sorted((Entry<String,String> l1, Entry<String,String> l2) ->
42+
{
43+
return l1.getKey().equals(l2.getKey()) ? l1.getValue().compareTo(l2.getValue())
44+
: l1.getKey().compareTo(l2.getKey());
45+
})
46+
.map(e -> String.format(format, e.getKey(), e.getValue()))
47+
.collect(Collectors.toList());
48+
} else{
49+
list = this.stream().map(e -> String.format(format, e.getKey(), e.getValue()))
50+
.collect(Collectors.toList());
4051
}
41-
42-
/* Sort statement*/
43-
if (sort) Collections.sort(list);
44-
52+
4553
return String.join(delimiter, list);
4654
}
4755
}

src/test/java/AuthorizationTokenTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public void Test_L1_Basic_Test() throws ApiUtilException
6969
, nonce
7070
, timestamp
7171
);
72-
72+
System.out.println("expectedToken:"+expectedToken);
73+
System.out.println("authorizationToken:"+authorizationToken);
7374
assertEquals(expectedToken, authorizationToken);
7475
}
7576

0 commit comments

Comments
 (0)