From 94eb7a8e0230ba5ac5bb1b215edec393099ff719 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun Date: Fri, 17 Aug 2018 15:57:33 +0200 Subject: [PATCH] Minor formatting fixes. (bunq/sdk_java#93) --- .../java/com/bunq/sdk/http/BunqHeader.java | 151 +++++++++--------- .../com/bunq/sdk/http/BunqRequestBuilder.java | 1 + .../com/bunq/sdk/http/BunqHeaderTest.java | 1 + .../model/generated/endpoint/AvatarTest.java | 1 + 4 files changed, 79 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/bunq/sdk/http/BunqHeader.java b/src/main/java/com/bunq/sdk/http/BunqHeader.java index 34833a80..8ddd5d78 100644 --- a/src/main/java/com/bunq/sdk/http/BunqHeader.java +++ b/src/main/java/com/bunq/sdk/http/BunqHeader.java @@ -4,99 +4,100 @@ import java.util.Map; public enum BunqHeader { - ATTACHMENT_DESCRIPTION("X-Bunq-Attachment-Description"), - CACHE_CONTROL("Cache-Control", "no-cache"), - CLIENT_AUTHENTICATION("X-Bunq-Client-Authentication"), - CLIENT_ENCRYPTION_HMAC("X-Bunq-Client-Encryption-Hmac"), - CLIENT_ENCRYPTION_IV("X-Bunq-Client-Encryption-Iv"), - CLIENT_ENCRYPTION_KEY("X-Bunq-Client-Encryption-Key"), - CLIENT_REQUEST_ID("X-Bunq-Client-Request-Id"), - CLIENT_RESPONSE_ID("X-Bunq-Client-Response-Id", "Could not determine response id."), - CLIENT_SIGNATURE("X-Bunq-Client-Signature"), - CONTENT_TYPE("Content-Type"), - GEOLOCATION("X-Bunq-Geolocation", "0 0 0 0 000"), - LANGUAGE("X-Bunq-Language", "en_US"), - REGION("X-Bunq-Region", "nl_NL"), - SERVER_SIGNATURE("X-Bunq-Server-Signature"), - USER_AGENT("User-Agent", "bunq-sdk-java/0.13.1"); - - private static final String PREFIX = "X-Bunq-"; - - private final String header; - private final String defaultValue; - - BunqHeader(String header) { - this(header, null); + ATTACHMENT_DESCRIPTION("X-Bunq-Attachment-Description"), + CACHE_CONTROL("Cache-Control", "no-cache"), + CLIENT_AUTHENTICATION("X-Bunq-Client-Authentication"), + CLIENT_ENCRYPTION_HMAC("X-Bunq-Client-Encryption-Hmac"), + CLIENT_ENCRYPTION_IV("X-Bunq-Client-Encryption-Iv"), + CLIENT_ENCRYPTION_KEY("X-Bunq-Client-Encryption-Key"), + CLIENT_REQUEST_ID("X-Bunq-Client-Request-Id"), + CLIENT_RESPONSE_ID("X-Bunq-Client-Response-Id", "Could not determine response id."), + CLIENT_SIGNATURE("X-Bunq-Client-Signature"), + CONTENT_TYPE("Content-Type"), + GEOLOCATION("X-Bunq-Geolocation", "0 0 0 0 000"), + LANGUAGE("X-Bunq-Language", "en_US"), + REGION("X-Bunq-Region", "nl_NL"), + SERVER_SIGNATURE("X-Bunq-Server-Signature"), + USER_AGENT("User-Agent", "bunq-sdk-java/0.13.1"); + + private static final String PREFIX = "X-Bunq-"; + + private final String header; + private final String defaultValue; + + BunqHeader(String header) { + this(header, null); + } + + BunqHeader(String header, String defaultValue) { + this.header = header; + this.defaultValue = defaultValue; + } + + public static BunqHeader parseHeaderOrNull(String value) { + for (BunqHeader header : values()) { + if (header.equals(value)) { + return header; + } } - BunqHeader(String header, String defaultValue) { - this.header = header; - this.defaultValue = defaultValue; - } + return null; + } - public static BunqHeader parseHeaderOrNull(String value) { - for (BunqHeader header:values()) { - if (header.equals(value)) { - return header; - } - } + public String getHeaderName() { + return header; + } - return null; - } + public String getDefaultValue() { + return defaultValue; + } - public String getHeaderName() { - return header; + private String getHeaderValueOrDefault(String value) { + if (value != null) { + return value; } - public String getDefaultValue() { - return defaultValue; - } + return getDefaultValue(); + } - private String getHeaderValueOrDefault(String value) { - if (value != null) { - return value; - } + public void addTo(Map headers, String value) { + headers.put(getHeaderName(), getHeaderValueOrDefault(value)); + } - return getDefaultValue(); - } + public void addTo(BunqRequestBuilder requestBuilder) { + addTo(requestBuilder, null); + } - public void addTo(Map headers, String value) { - headers.put(getHeaderName(), getHeaderValueOrDefault(value)); - } + public void addTo(BunqRequestBuilder requestBuilder, String value) { + requestBuilder.addHeader(getHeaderName(), getHeaderValueOrDefault(value)); + } - public void addTo(BunqRequestBuilder requestBuilder) { - addTo(requestBuilder, null); - } + public boolean equals(String header) { + return getHeaderName().equalsIgnoreCase(header); + } - public void addTo(BunqRequestBuilder requestBuilder, String value) { - requestBuilder.addHeader(getHeaderName(), getHeaderValueOrDefault(value)); - } + public boolean isBunq() { + return getHeaderName().startsWith(PREFIX); + } - public boolean equals(String header) { - return getHeaderName().equalsIgnoreCase(header); + private String findKeyOrNull(Collection keys) { + for (String key : keys) { + if (this.equals(key)) { + return key; + } } - public boolean isBunq() { - return getHeaderName().startsWith(PREFIX); - } + return null; + } - private String findKeyOrNull(Collection keys) { - for (String key:keys) { - if (this.equals(key)) { - return key; - } - } + public String getHeaderValueOrDefault(Map headers) { + String key = findKeyOrNull(headers.keySet()); - return null; + if (key != null && headers.get(key) != null) { + return headers.get(key); } - public String getHeaderValueOrDefault(Map headers) { - String key = findKeyOrNull(headers.keySet()); - - if (key != null && headers.get(key) != null) { - return headers.get(key); - } + return getDefaultValue(); + } - return getDefaultValue(); - } } diff --git a/src/main/java/com/bunq/sdk/http/BunqRequestBuilder.java b/src/main/java/com/bunq/sdk/http/BunqRequestBuilder.java index 5f245819..51b62403 100644 --- a/src/main/java/com/bunq/sdk/http/BunqRequestBuilder.java +++ b/src/main/java/com/bunq/sdk/http/BunqRequestBuilder.java @@ -216,4 +216,5 @@ public BunqRequestBody getBody() { public List getAllHeader() { return this.allHeader; } + } diff --git a/src/test/java/com/bunq/sdk/http/BunqHeaderTest.java b/src/test/java/com/bunq/sdk/http/BunqHeaderTest.java index 0aabe0b7..86b13a10 100644 --- a/src/test/java/com/bunq/sdk/http/BunqHeaderTest.java +++ b/src/test/java/com/bunq/sdk/http/BunqHeaderTest.java @@ -101,4 +101,5 @@ public void addToMap() { assertEquals(HEADER_VALUE_GEOLOCATION, headers.get(BunqHeader.GEOLOCATION.getHeaderName())); assertEquals(HEADER_VALUE_USER_AGENT, headers.get(BunqHeader.USER_AGENT.getHeaderName())); } + } diff --git a/src/test/java/com/bunq/sdk/model/generated/endpoint/AvatarTest.java b/src/test/java/com/bunq/sdk/model/generated/endpoint/AvatarTest.java index b4e9eb4e..37eeb4c4 100644 --- a/src/test/java/com/bunq/sdk/model/generated/endpoint/AvatarTest.java +++ b/src/test/java/com/bunq/sdk/model/generated/endpoint/AvatarTest.java @@ -59,4 +59,5 @@ private String uploadAvatar(byte[] file_contents) { return AttachmentPublic.create(allCustomHeader, file_contents).getValue(); } + }