Skip to content

Commit

Permalink
Refactored BunqBasicHeader for better readability. (bunq#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Jul 11, 2018
1 parent 5ea6bc3 commit 9d43c55
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/main/java/com/bunq/sdk/http/BunqBasicHeader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bunq.sdk.http;

import com.sun.org.apache.xpath.internal.functions.FuncBoolean;
import okhttp3.Response;

import java.util.ArrayList;
Expand Down Expand Up @@ -41,26 +42,34 @@ private String forSigning() {
public static String collectForSigning(
Collection<BunqBasicHeader> allBasicHeader,
BunqHeader exclude,
Collection<BunqHeader> includes) {
List<String> headersForSigning = new ArrayList<String>();
Collection<BunqHeader> allNonBunqHeaderToInclude) {
List<String> allHeaderForSigning = new ArrayList<String>();

for (BunqBasicHeader basicHeader:allBasicHeader) {
BunqHeader header = basicHeader.getName();
addHeaderForSigningIfNeeded(basicHeader, allHeaderForSigning, allNonBunqHeaderToInclude);
}

if (header.equals(exclude)) {
continue;
}
Collections.sort(allHeaderForSigning);

if (header.isBunq() || includes.contains(header)) {
headersForSigning.add(basicHeader.forSigning());
}
}
return formatAllHeaderForSigning(allHeaderForSigning);
}

Collections.sort(headersForSigning);
private static void addHeaderForSigningIfNeeded(
BunqBasicHeader basicHeader,
List<String> allHeaderForSigning,
Collection<BunqHeader> allNonBunqHeaderToInclude
) {
BunqHeader header = basicHeader.getName();

if (header.isBunq() || allNonBunqHeaderToInclude.contains(header)) {
allHeaderForSigning.add(basicHeader.forSigning());
}
}

private static String formatAllHeaderForSigning(List<String> allHeaderForSigning) {
StringBuilder stringBuilder = new StringBuilder();

for (String header:headersForSigning) {
for (String header: allHeaderForSigning) {
stringBuilder.append(header);
stringBuilder.append(NEWLINE);
}
Expand Down

0 comments on commit 9d43c55

Please sign in to comment.