Skip to content

Commit

Permalink
stil4m#28 applied code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tubbynl committed Nov 14, 2016
1 parent 258f211 commit c21e7f5
Show file tree
Hide file tree
Showing 24 changed files with 216 additions and 220 deletions.
4 changes: 2 additions & 2 deletions src/main/java/nl/stil4m/mollie/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Issuers issuers() {
}

public Refunds refunds(String paymentId) {
return dynamicClient.refunds(apiKey,paymentId);
return dynamicClient.refunds(apiKey, paymentId);
}

public Customers customers() {
Expand All @@ -47,7 +47,7 @@ public Customers customers() {
public CustomerPayments customerPayments(String customerId) {
return dynamicClient.customerPayments(apiKey, customerId);
}

public Mandates mandates(String customerId) {
return dynamicClient.mandates(apiKey, customerId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nl/stil4m/mollie/DynamicClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Customers customers(String apiKey) {
public CustomerPayments customerPayments(String apiKey, String customerId) {
return new CustomerPayments(apiKey, endpoint, requestExecutor, customerId);
}

public Mandates mandates(String apiKey, String customerId) {
return new Mandates(apiKey, endpoint, requestExecutor, customerId);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/nl/stil4m/mollie/ResponseOrError.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public class ResponseOrError<V> {
private final Map error;
private final Boolean success;

private ResponseOrError(int status, V data, Map error, Boolean success) {
this.status = status;
this.data = data;
this.error = error;
this.success = success;
}

public static <V, T> ResponseOrError withError(int status, Map error) {
return new ResponseOrError<>(status, null, error, false);
}
Expand All @@ -18,13 +25,6 @@ public static <V, T> ResponseOrError withData(int status, V data) {
return new ResponseOrError<>(status, data, null, true);
}

private ResponseOrError(int status, V data, Map error, Boolean success) {
this.status = status;
this.data = data;
this.error = error;
this.success = success;
}

public void get(Consumer<V> onSuccess, Consumer<Map> onError) {
if (success) {
onSuccess.accept(data);
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/nl/stil4m/mollie/concepts/AbstractConcept.java
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
package nl.stil4m.mollie.concepts;

import static java.util.Objects.requireNonNull;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import nl.stil4m.mollie.RequestExecutor;
import nl.stil4m.mollie.ResponseOrError;
import nl.stil4m.mollie.domain.Page;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import java.io.IOException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Arrays;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;

import nl.stil4m.mollie.RequestExecutor;
import nl.stil4m.mollie.ResponseOrError;
import nl.stil4m.mollie.domain.Page;
import static java.util.Objects.requireNonNull;

public abstract class AbstractConcept<T extends Object> implements Concept<T> {
private static final Collector<CharSequence, ?, String> URL_JOINER = Collectors.joining("/");
private static final TypeReference<Void> VOID_TYPE_REFERENCE = new TypeReference<Void>(){};

private static final TypeReference<Void> VOID_TYPE_REFERENCE = new TypeReference<Void>() {
};

private final TypeReference<Page<T>> pageTypeReference;
private final TypeReference<T> singleTypeReference;
private final String apiKey;
private final String endpoint;
private final RequestExecutor requestExecutor;

protected AbstractConcept(String apiKey, RequestExecutor requestExecutor,TypeReference<T> singleTypeReference,TypeReference<Page<T>> pageTypeReference, String... endPoint) {
protected AbstractConcept(String apiKey, RequestExecutor requestExecutor, TypeReference<T> singleTypeReference, TypeReference<Page<T>> pageTypeReference, String... endPoint) {
this.apiKey = apiKey;
this.endpoint = requireNonNull(joinUrl(endPoint),"endPoint cannot be null or empty");
this.endpoint = requireNonNull(joinUrl(endPoint), "endPoint cannot be null or empty");
this.requestExecutor = requestExecutor;
this.singleTypeReference = singleTypeReference;
this.pageTypeReference = pageTypeReference;
}

private static String joinUrl(String... elements) {
return trimToNull(Stream.of(elements)
.map(AbstractConcept::trimToNull)
.map(s->requireNonNull(s,"URL cannot contain null or blank elements: "+Arrays.asList(elements)))
.map(s -> requireNonNull(s, "URL cannot contain null or blank elements: " + Arrays.asList(elements)))
.collect(URL_JOINER));
}

private static String trimToNull(String value) {
return value!=null && !value.trim().isEmpty()?value.trim():null;
return value != null && !value.trim().isEmpty() ? value.trim() : null;
}

@Override
public String url(String... elements) {
if(elements==null || elements.length==0) {
if (elements == null || elements.length == 0) {
return this.endpoint;
}
return joinUrl(this.endpoint,joinUrl(elements));
return joinUrl(this.endpoint, joinUrl(elements));
}

@Override
public ResponseOrError<Page<T>> requestPage(HttpUriRequest httpRequest) throws IOException {
return requestExecutor.execute(apiKey, httpRequest, pageTypeReference);
}

@Override
public ResponseOrError<T> requestSingle(HttpUriRequest httpRequest) throws IOException {
return requestExecutor.execute(apiKey, httpRequest, singleTypeReference);
}

@Override
public ResponseOrError<Void> requestVoid(HttpUriRequest httpRequest) throws IOException {
return requestExecutor.execute(apiKey, httpRequest, VOID_TYPE_REFERENCE);
}

@Override
public HttpEntity buildHttpEntity(Object value) throws UnsupportedCharsetException, JsonProcessingException {
return new StringEntity(requestExecutor.serialize(value), ContentType.APPLICATION_JSON);
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/nl/stil4m/mollie/concepts/Concept.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package nl.stil4m.mollie.concepts;

import java.io.IOException;
import java.nio.charset.UnsupportedCharsetException;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpUriRequest;

import com.fasterxml.jackson.core.JsonProcessingException;

import nl.stil4m.mollie.ResponseOrError;
import nl.stil4m.mollie.domain.Page;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpUriRequest;

import java.io.IOException;
import java.nio.charset.UnsupportedCharsetException;

public interface Concept<T extends Object> {
String url(String... elements);

ResponseOrError<Page<T>> requestPage(HttpUriRequest get) throws IOException;

ResponseOrError<T> requestSingle(HttpUriRequest get) throws IOException;

ResponseOrError<Void> requestVoid(HttpUriRequest get) throws IOException;

HttpEntity buildHttpEntity(Object value) throws UnsupportedCharsetException, JsonProcessingException;
}
9 changes: 4 additions & 5 deletions src/main/java/nl/stil4m/mollie/concepts/Create.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package nl.stil4m.mollie.concepts;

import java.io.IOException;

import nl.stil4m.mollie.ResponseOrError;
import org.apache.http.client.methods.HttpPost;

import nl.stil4m.mollie.ResponseOrError;
import java.io.IOException;

public interface Create<R extends Object, O extends Object> extends Concept<R> {

public interface Create<R extends Object,O extends Object> extends Concept<R> {

default ResponseOrError<R> create(O create) throws IOException {
HttpPost httpPost = new HttpPost(url());
httpPost.setEntity(buildHttpEntity(create));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/nl/stil4m/mollie/concepts/CustomerPayments.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import nl.stil4m.mollie.domain.CustomerPayment;
import nl.stil4m.mollie.domain.Payment;

public class CustomerPayments extends AbstractConcept<Payment> implements ListAll<Payment>,Create<Payment,CustomerPayment> {
public class CustomerPayments extends AbstractConcept<Payment> implements ListAll<Payment>, Create<Payment, CustomerPayment> {

public CustomerPayments(String apiKey, String endpoint, RequestExecutor requestExecutor, String customerId) {
super(apiKey,requestExecutor,Payments.SINGLE_TYPE,Payments.PAGE_TYPE,endpoint,"customers",customerId,"payments");
super(apiKey, requestExecutor, Payments.SINGLE_TYPE, Payments.PAGE_TYPE, endpoint, "customers", customerId, "payments");
}
}
11 changes: 6 additions & 5 deletions src/main/java/nl/stil4m/mollie/concepts/Customers.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package nl.stil4m.mollie.concepts;

import com.fasterxml.jackson.core.type.TypeReference;

import nl.stil4m.mollie.RequestExecutor;
import nl.stil4m.mollie.domain.CreateCustomer;
import nl.stil4m.mollie.domain.Customer;
import nl.stil4m.mollie.domain.Page;
import nl.stil4m.mollie.domain.UpdateCustomer;

public class Customers extends AbstractConcept<Customer> implements ListAll<Customer>,GetById<Customer>,Create<Customer,CreateCustomer>,Update<Customer,UpdateCustomer> {
private static final TypeReference<Page<Customer>> PAGE_TYPE = new TypeReference<Page<Customer>>() {};
private static final TypeReference<Customer> SINGLE_TYPE = new TypeReference<Customer>() {};
public class Customers extends AbstractConcept<Customer> implements ListAll<Customer>, GetById<Customer>, Create<Customer, CreateCustomer>, Update<Customer, UpdateCustomer> {
private static final TypeReference<Page<Customer>> PAGE_TYPE = new TypeReference<Page<Customer>>() {
};
private static final TypeReference<Customer> SINGLE_TYPE = new TypeReference<Customer>() {
};

public Customers(String apiKey, String endpoint, RequestExecutor requestExecutor) {
super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"customers");
super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "customers");
}
}
5 changes: 2 additions & 3 deletions src/main/java/nl/stil4m/mollie/concepts/Delete.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package nl.stil4m.mollie.concepts;

import java.io.IOException;

import nl.stil4m.mollie.ResponseOrError;
import org.apache.http.client.methods.HttpDelete;

import nl.stil4m.mollie.ResponseOrError;
import java.io.IOException;

public interface Delete<T extends Object> extends Concept<T> {

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/nl/stil4m/mollie/concepts/GetById.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package nl.stil4m.mollie.concepts;

import java.io.IOException;

import nl.stil4m.mollie.ResponseOrError;
import org.apache.http.client.methods.HttpGet;

import nl.stil4m.mollie.ResponseOrError;
import java.io.IOException;

public interface GetById<T extends Object> extends Concept<T> {

default ResponseOrError<T> get(String id) throws IOException {
HttpGet httpGet = new HttpGet(url(id));
return requestSingle(httpGet);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/nl/stil4m/mollie/concepts/Issuers.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package nl.stil4m.mollie.concepts;

import com.fasterxml.jackson.core.type.TypeReference;

import nl.stil4m.mollie.RequestExecutor;
import nl.stil4m.mollie.domain.Issuer;
import nl.stil4m.mollie.domain.Page;

public class Issuers extends AbstractConcept<Issuer> implements ListAll<Issuer>,GetById<Issuer> {
private static final TypeReference<Page<Issuer>> PAGE_TYPE = new TypeReference<Page<Issuer>>() {};
private static final TypeReference<Issuer> SINGLE_TYPE = new TypeReference<Issuer>() {};

public class Issuers extends AbstractConcept<Issuer> implements ListAll<Issuer>, GetById<Issuer> {
private static final TypeReference<Page<Issuer>> PAGE_TYPE = new TypeReference<Page<Issuer>>() {
};
private static final TypeReference<Issuer> SINGLE_TYPE = new TypeReference<Issuer>() {
};

public Issuers(String apiKey, String endpoint, RequestExecutor requestExecutor) {
super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"issuers");
super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "issuers");
}
}
19 changes: 9 additions & 10 deletions src/main/java/nl/stil4m/mollie/concepts/ListAll.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package nl.stil4m.mollie.concepts;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Optional;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

import nl.stil4m.mollie.ResponseOrError;
import nl.stil4m.mollie.domain.Page;
import nl.stil4m.mollie.domain.Payment;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Optional;

public interface ListAll<T extends Object> extends Concept<T> {

default ResponseOrError<Page<T>> all(Optional<Integer> count, Optional<Integer> offset) throws IOException, URISyntaxException {
return list(count,offset);
return list(count, offset);
}

default ResponseOrError<Page<T>> list(Optional<Integer> count, Optional<Integer> offset) throws IOException, URISyntaxException {
Expand All @@ -25,7 +24,7 @@ default ResponseOrError<Page<T>> list(Optional<Integer> count, Optional<Integer>
HttpGet httpGet = new HttpGet(builder.build());
return requestPage(httpGet);
}

default ResponseOrError<Page<T>> next(Page<Payment> page) throws IOException {
if (!page.getLinks().getNext().isPresent()) {
throw new IllegalArgumentException("Page does not have next");
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/nl/stil4m/mollie/concepts/Mandates.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package nl.stil4m.mollie.concepts;

import com.fasterxml.jackson.core.type.TypeReference;

import nl.stil4m.mollie.RequestExecutor;
import nl.stil4m.mollie.domain.CreateMandate;
import nl.stil4m.mollie.domain.Mandate;
import nl.stil4m.mollie.domain.Page;

public class Mandates extends AbstractConcept<Mandate> implements ListAll<Mandate>,GetById<Mandate>,Create<Mandate,CreateMandate>,Delete<Mandate> {
private static final TypeReference<Page<Mandate>> PAGE_TYPE = new TypeReference<Page<Mandate>>() {};
private static final TypeReference<Mandate> SINGLE_TYPE = new TypeReference<Mandate>() {};
public class Mandates extends AbstractConcept<Mandate> implements ListAll<Mandate>, GetById<Mandate>, Create<Mandate, CreateMandate>, Delete<Mandate> {
private static final TypeReference<Page<Mandate>> PAGE_TYPE = new TypeReference<Page<Mandate>>() {
};
private static final TypeReference<Mandate> SINGLE_TYPE = new TypeReference<Mandate>() {
};

public Mandates(String apiKey, String endpoint, RequestExecutor requestExecutor, String customerId) {
super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"customers",customerId,"mandates");
super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "customers", customerId, "mandates");
}
}
13 changes: 7 additions & 6 deletions src/main/java/nl/stil4m/mollie/concepts/Methods.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package nl.stil4m.mollie.concepts;

import com.fasterxml.jackson.core.type.TypeReference;

import nl.stil4m.mollie.RequestExecutor;
import nl.stil4m.mollie.domain.Method;
import nl.stil4m.mollie.domain.Page;

public class Methods extends AbstractConcept<Method> implements ListAll<Method>,GetById<Method> {
private static final TypeReference<Page<Method>> PAGE_TYPE = new TypeReference<Page<Method>>() {};
private static final TypeReference<Method> SINGLE_TYPE = new TypeReference<Method>() {};

public class Methods extends AbstractConcept<Method> implements ListAll<Method>, GetById<Method> {
private static final TypeReference<Page<Method>> PAGE_TYPE = new TypeReference<Page<Method>>() {
};
private static final TypeReference<Method> SINGLE_TYPE = new TypeReference<Method>() {
};

public Methods(String apiKey, String endpoint, RequestExecutor requestExecutor) {
super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"methods");
super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "methods");
}
}
Loading

0 comments on commit c21e7f5

Please sign in to comment.