From 8f7559df5e861e2cb0ee2139718a59e534abf0d5 Mon Sep 17 00:00:00 2001 From: Felipe Reis Date: Mon, 30 Jan 2017 15:14:50 -0200 Subject: [PATCH 01/25] BAEL-612: used lambda instead of anonymous class --- .../baeldung/concurrent/future/SquareCalculator.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java b/core-java/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java index 29c4ae53ce..e53a2413d1 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java +++ b/core-java/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java @@ -1,6 +1,5 @@ package com.baeldung.concurrent.future; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -13,12 +12,9 @@ public class SquareCalculator { } public Future calculate(Integer input) { - return executor.submit(new Callable() { - @Override - public Integer call() throws Exception { - Thread.sleep(1000); - return input * input; - } - }); + return executor.submit(() -> { + Thread.sleep(1000); + return input * input; + }); } } From 5bd907aa019707749504c488a5dc9c8fc13cd3ca Mon Sep 17 00:00:00 2001 From: Alex Theedom Date: Tue, 31 Jan 2017 06:40:13 +0000 Subject: [PATCH 02/25] Add two JsonGetter examples --- .../serialization/jsongetter/Author1.java | 33 +++++++++++++++++++ .../jsongetter/{Author.java => Author2.java} | 5 +-- .../jsongetter/JsonGetterTest.java | 27 +++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author1.java rename video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/{Author.java => Author2.java} (87%) diff --git a/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author1.java b/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author1.java new file mode 100644 index 0000000000..637def5747 --- /dev/null +++ b/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author1.java @@ -0,0 +1,33 @@ +package com.baeldung.jacksonannotation.serialization.jsongetter; + + +import com.baeldung.jacksonannotation.domain.Item; +import com.baeldung.jacksonannotation.domain.Person; +import com.fasterxml.jackson.annotation.JsonGetter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Source code github.com/eugenp/tutorials + * + * @author Alex Theedom www.baeldung.com + * @version 1.0 + */ +public class Author1 extends Person { + + List items = new ArrayList<>(); + + public Author1(String firstName, String lastName) { + super(firstName, lastName); + } + + @JsonGetter + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } +} diff --git a/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author.java b/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author2.java similarity index 87% rename from video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author.java rename to video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author2.java index eccc306b45..28f2ed1484 100644 --- a/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author.java +++ b/video-tutorials/jackson-annotations/src/main/java/com/baeldung/jacksonannotation/serialization/jsongetter/Author2.java @@ -14,11 +14,11 @@ import java.util.List; * @author Alex Theedom www.baeldung.com * @version 1.0 */ -public class Author extends Person { +public class Author2 extends Person { List items = new ArrayList<>(); - public Author(String firstName, String lastName) { + public Author2(String firstName, String lastName) { super(firstName, lastName); } @@ -27,6 +27,7 @@ public class Author extends Person { return items; } + public void setItems(List items) { this.items = items; } diff --git a/video-tutorials/jackson-annotations/src/test/java/com/baeldung/jacksonannotation/serialization/jsongetter/JsonGetterTest.java b/video-tutorials/jackson-annotations/src/test/java/com/baeldung/jacksonannotation/serialization/jsongetter/JsonGetterTest.java index 2aa97e0baf..4df2e98cab 100644 --- a/video-tutorials/jackson-annotations/src/test/java/com/baeldung/jacksonannotation/serialization/jsongetter/JsonGetterTest.java +++ b/video-tutorials/jackson-annotations/src/test/java/com/baeldung/jacksonannotation/serialization/jsongetter/JsonGetterTest.java @@ -16,10 +16,33 @@ import static org.assertj.core.api.Assertions.assertThat; public class JsonGetterTest { @Test - public void whenSerializingUsingJsonGetter_thenCorrect() throws JsonProcessingException { + public void whenSerializingUsingJsonGetter_andNoPropertyNameSet_thenCorrect() throws JsonProcessingException { // arrange - Author author = new Author("Alex", "Theedom"); + Author1 author = new Author1("Alex", "Theedom"); + + // act + String result = new ObjectMapper().writeValueAsString(author); + + // assert + assertThat(from(result).getList("items")).isNotNull(); + + /* + { + "firstName": "Alex", + "lastName": "Theedom", + "items": [] + } + */ + + } + + + @Test + public void whenSerializingUsingJsonGetter_andPropertyNameSet_thenCorrect() throws JsonProcessingException { + + // arrange + Author2 author = new Author2("Alex", "Theedom"); // act String result = new ObjectMapper().writeValueAsString(author); From 4fe878d6d44b579d34d8648729df829f56c671ec Mon Sep 17 00:00:00 2001 From: Saptarshi Basu Date: Tue, 31 Jan 2017 13:17:23 +0530 Subject: [PATCH 03/25] JAX-RS Client [BAEL-595] (#992) * WatchService vs. Apache Commons IO Mnitoring * Indentation fixed * Indentation fixed * JAX-RS API using Jersey [BAEL-558] * JAX-RS API using Jersey [BAEL-558] * Modifications made to remove xml * applicationContext.xml removed * All try catch moved to ExceptionMapper * fixes * review comments incorporated * module renamed * JAX-RS client [BAEL-595] * jersey-core dependency removed * assert changed to assertEquals * messagebody readers and writers removed * pom dependency corrected and other minor changes --- spring-jersey/pom.xml | 16 +++--- .../com/baeldung/client/rest/RestClient.java | 31 +++++++++++ .../baeldung/client/JerseyClientLiveTest.java | 53 +++++++++++++++++++ .../baeldung/server/JerseyApiLiveTest.java | 17 +++--- 4 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 spring-jersey/src/main/java/com/baeldung/client/rest/RestClient.java create mode 100644 spring-jersey/src/test/java/com/baeldung/client/JerseyClientLiveTest.java diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml index 00d67febec..293850d41e 100644 --- a/spring-jersey/pom.xml +++ b/spring-jersey/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.baeldung - jersey-api + spring-jersey 0.1-SNAPSHOT war @@ -23,6 +23,7 @@ + spring-jersey org.apache.maven.plugins @@ -75,11 +76,6 @@ - - org.glassfish.jersey.core - jersey-server - ${jersey.version} - org.glassfish.jersey.containers jersey-container-servlet @@ -90,6 +86,12 @@ jersey-media-json-jackson ${jersey.version} + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + + javax.servlet @@ -97,8 +99,8 @@ ${servlet-api-version} provided - + org.glassfish.jersey.ext jersey-spring3 diff --git a/spring-jersey/src/main/java/com/baeldung/client/rest/RestClient.java b/spring-jersey/src/main/java/com/baeldung/client/rest/RestClient.java new file mode 100644 index 0000000000..0e45b68b14 --- /dev/null +++ b/spring-jersey/src/main/java/com/baeldung/client/rest/RestClient.java @@ -0,0 +1,31 @@ +package com.baeldung.client.rest; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.baeldung.server.model.Employee; + +public class RestClient { + + private static final String REST_URI = "http://localhost:8082/spring-jersey/resources/employees"; + private Client client = ClientBuilder.newClient(); + + public Response createJsonEmployee(Employee emp) { + return client.target(REST_URI).request(MediaType.APPLICATION_JSON).post(Entity.entity(emp, MediaType.APPLICATION_JSON)); + } + + public Employee getJsonEmployee(int id) { + return client.target(REST_URI).path(new Integer(id).toString()).request(MediaType.APPLICATION_JSON).get(Employee.class); + } + + public Response createXmlEmployee(Employee emp) { + return client.target(REST_URI).request(MediaType.APPLICATION_XML).post(Entity.entity(emp, MediaType.APPLICATION_XML)); + } + + public Employee getXmlEmployee(int id) { + return client.target(REST_URI).path(new Integer(id).toString()).request(MediaType.APPLICATION_XML).get(Employee.class); + } +} diff --git a/spring-jersey/src/test/java/com/baeldung/client/JerseyClientLiveTest.java b/spring-jersey/src/test/java/com/baeldung/client/JerseyClientLiveTest.java new file mode 100644 index 0000000000..be87cd5478 --- /dev/null +++ b/spring-jersey/src/test/java/com/baeldung/client/JerseyClientLiveTest.java @@ -0,0 +1,53 @@ +package com.baeldung.client; + +import static org.junit.Assert.assertEquals; + +import javax.ws.rs.core.Response; + +import org.junit.Test; + +import com.baeldung.client.rest.RestClient; +import com.baeldung.server.model.Employee; + +public class JerseyClientLiveTest { + + public static final int HTTP_CREATED = 201; + + private RestClient client = new RestClient(); + + @Test + public void givenCorrectObject_whenCorrectJsonRequest_thenResponseCodeCreated() { + Employee emp = new Employee(6, "Johny"); + + Response response = client.createJsonEmployee(emp); + + assertEquals(response.getStatus(), HTTP_CREATED); + } + + @Test + public void givenCorrectObject_whenCorrectXmlRequest_thenResponseCodeCreated() { + Employee emp = new Employee(7, "Jacky"); + + Response response = client.createXmlEmployee(emp); + + assertEquals(response.getStatus(), HTTP_CREATED); + } + + @Test + public void givenCorrectId_whenCorrectJsonRequest_thenCorrectEmployeeRetrieved() { + int employeeId = 1; + + Employee emp = client.getJsonEmployee(employeeId); + + assertEquals(emp.getFirstName(), "Jane"); + } + + @Test + public void givenCorrectId_whenCorrectXmlRequest_thenCorrectEmployeeRetrieved() { + int employeeId = 1; + + Employee emp = client.getXmlEmployee(employeeId); + + assertEquals(emp.getFirstName(), "Jane"); + } +} diff --git a/spring-jersey/src/test/java/com/baeldung/server/JerseyApiLiveTest.java b/spring-jersey/src/test/java/com/baeldung/server/JerseyApiLiveTest.java index 835f9144ab..12de677180 100644 --- a/spring-jersey/src/test/java/com/baeldung/server/JerseyApiLiveTest.java +++ b/spring-jersey/src/test/java/com/baeldung/server/JerseyApiLiveTest.java @@ -1,5 +1,8 @@ package com.baeldung.server; + +import static org.junit.Assert.assertEquals; + import com.baeldung.server.model.Employee; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpResponse; @@ -15,7 +18,7 @@ import java.io.IOException; public class JerseyApiLiveTest { - private static final String SERVICE_URL = "http://localhost:8082/jersey-api/resources/employees"; + private static final String SERVICE_URL = "http://localhost:8082/spring-jersey/resources/employees"; @Test public void givenGetAllEmployees_whenCorrectRequest_thenResponseCodeSuccess() throws IOException { @@ -23,7 +26,7 @@ public class JerseyApiLiveTest { final HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request); - assert(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK); + assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.SC_OK); } @Test @@ -32,7 +35,7 @@ public class JerseyApiLiveTest { final HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request); - assert(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK); + assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.SC_OK); } @Test @@ -41,7 +44,7 @@ public class JerseyApiLiveTest { final HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request); - assert(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND); + assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.SC_NOT_FOUND); } @Test @@ -53,7 +56,7 @@ public class JerseyApiLiveTest { ObjectMapper mapper = new ObjectMapper(); Employee emp = mapper.readValue(httpResponse.getEntity().getContent(), Employee.class); - assert(emp.getFirstName().equals("Jane")); + assertEquals(emp.getFirstName(), "Jane"); } @Test @@ -68,7 +71,7 @@ public class JerseyApiLiveTest { request.setEntity(input); final HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request); - assert(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED); + assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED); } @Test @@ -83,7 +86,7 @@ public class JerseyApiLiveTest { request.setEntity(input); final HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request); - assert(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_CONFLICT); + assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.SC_CONFLICT); } } \ No newline at end of file From 9a16f10802fa17f1eac69ca8da0eb814a72741ad Mon Sep 17 00:00:00 2001 From: DOHA Date: Tue, 31 Jan 2017 13:58:28 +0200 Subject: [PATCH 04/25] rename servers --- ...ring-cloud-rest-server.properties => discovery.properties} | 2 +- spring-cloud/spring-cloud-rest/pom.xml | 4 ++-- .../.gitignore | 0 .../pom.xml | 4 ++-- .../java/org/baeldung/SpringCloudRestConfigApplication.java | 0 .../src/main/resources/application.properties | 0 .../org/baeldung/SpringCloudRestConfigIntegrationTest.java | 0 .../.gitignore | 0 .../pom.xml | 4 ++-- .../src/main/java/org/baeldung/SessionConfig.java | 0 .../java/org/baeldung/SpringCloudRestServerApplication.java | 0 .../src/main/resources/bootstrap.properties | 2 +- .../org/baeldung/SpringCloudRestServerIntegrationTest.java | 0 13 files changed, 8 insertions(+), 8 deletions(-) rename spring-cloud/spring-cloud-rest/application-config/{spring-cloud-rest-server.properties => discovery.properties} (89%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-config => spring-cloud-rest-config-server}/.gitignore (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-config => spring-cloud-rest-config-server}/pom.xml (95%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-config => spring-cloud-rest-config-server}/src/main/java/org/baeldung/SpringCloudRestConfigApplication.java (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-config => spring-cloud-rest-config-server}/src/main/resources/application.properties (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-config => spring-cloud-rest-config-server}/src/test/java/org/baeldung/SpringCloudRestConfigIntegrationTest.java (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-server => spring-cloud-rest-discovery-server}/.gitignore (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-server => spring-cloud-rest-discovery-server}/pom.xml (95%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-server => spring-cloud-rest-discovery-server}/src/main/java/org/baeldung/SessionConfig.java (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-server => spring-cloud-rest-discovery-server}/src/main/java/org/baeldung/SpringCloudRestServerApplication.java (100%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-server => spring-cloud-rest-discovery-server}/src/main/resources/bootstrap.properties (72%) rename spring-cloud/spring-cloud-rest/{spring-cloud-rest-server => spring-cloud-rest-discovery-server}/src/test/java/org/baeldung/SpringCloudRestServerIntegrationTest.java (100%) diff --git a/spring-cloud/spring-cloud-rest/application-config/spring-cloud-rest-server.properties b/spring-cloud/spring-cloud-rest/application-config/discovery.properties similarity index 89% rename from spring-cloud/spring-cloud-rest/application-config/spring-cloud-rest-server.properties rename to spring-cloud/spring-cloud-rest/application-config/discovery.properties index 96cacdb5fb..2f2a56248f 100644 --- a/spring-cloud/spring-cloud-rest/application-config/spring-cloud-rest-server.properties +++ b/spring-cloud/spring-cloud-rest/application-config/discovery.properties @@ -1,4 +1,4 @@ -spring.application.name=spring-cloud-rest-server +spring.application.name=discovery server.port=8761 #### cloud diff --git a/spring-cloud/spring-cloud-rest/pom.xml b/spring-cloud/spring-cloud-rest/pom.xml index 70d9c8e4c7..6c6090b6fd 100644 --- a/spring-cloud/spring-cloud-rest/pom.xml +++ b/spring-cloud/spring-cloud-rest/pom.xml @@ -7,8 +7,8 @@ spring-cloud-rest 1.0.0-SNAPSHOT - spring-cloud-rest-config - spring-cloud-rest-server + spring-cloud-rest-config-server + spring-cloud-rest-discovery-server spring-cloud-rest-books-api spring-cloud-rest-reviews-api diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config/.gitignore b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/.gitignore similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-config/.gitignore rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/.gitignore diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml similarity index 95% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-config/pom.xml rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml index a6f045899c..a1e4af1190 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml @@ -4,11 +4,11 @@ 4.0.0 org.baeldung - spring-cloud-rest-config + spring-cloud-rest-config-server 0.0.1-SNAPSHOT jar - spring-cloud-rest-config + spring-cloud-rest-config-server Spring Cloud REST configuration server diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config/src/main/java/org/baeldung/SpringCloudRestConfigApplication.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/src/main/java/org/baeldung/SpringCloudRestConfigApplication.java similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-config/src/main/java/org/baeldung/SpringCloudRestConfigApplication.java rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/src/main/java/org/baeldung/SpringCloudRestConfigApplication.java diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config/src/main/resources/application.properties b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/src/main/resources/application.properties similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-config/src/main/resources/application.properties rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/src/main/resources/application.properties diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config/src/test/java/org/baeldung/SpringCloudRestConfigIntegrationTest.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/src/test/java/org/baeldung/SpringCloudRestConfigIntegrationTest.java similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-config/src/test/java/org/baeldung/SpringCloudRestConfigIntegrationTest.java rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/src/test/java/org/baeldung/SpringCloudRestConfigIntegrationTest.java diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/.gitignore b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/.gitignore similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-server/.gitignore rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/.gitignore diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml similarity index 95% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-server/pom.xml rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml index 98325e8ae9..d9d08079b7 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml @@ -4,11 +4,11 @@ 4.0.0 org.baeldung - spring-cloud-rest-server + spring-cloud-rest-discovery-server 0.0.1-SNAPSHOT jar - spring-cloud-rest-server + spring-cloud-rest-discovery-server Spring Cloud REST server diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/java/org/baeldung/SessionConfig.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/java/org/baeldung/SessionConfig.java similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/java/org/baeldung/SessionConfig.java rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/java/org/baeldung/SessionConfig.java diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/java/org/baeldung/SpringCloudRestServerApplication.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/java/org/baeldung/SpringCloudRestServerApplication.java similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/java/org/baeldung/SpringCloudRestServerApplication.java rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/java/org/baeldung/SpringCloudRestServerApplication.java diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/resources/bootstrap.properties b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/resources/bootstrap.properties similarity index 72% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/resources/bootstrap.properties rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/resources/bootstrap.properties index 528cb4cfd3..d31caf55b5 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/main/resources/bootstrap.properties +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/main/resources/bootstrap.properties @@ -1,4 +1,4 @@ -spring.cloud.config.name=spring-cloud-rest-server +spring.cloud.config.name=discovery spring.cloud.config.uri=http://localhost:8081 spring.cloud.config.username=configUser spring.cloud.config.password=configPassword \ No newline at end of file diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/test/java/org/baeldung/SpringCloudRestServerIntegrationTest.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringCloudRestServerIntegrationTest.java similarity index 100% rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-server/src/test/java/org/baeldung/SpringCloudRestServerIntegrationTest.java rename to spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringCloudRestServerIntegrationTest.java From 09bebd5351a9f9c56fdd0a3cc8066c61dd375eea Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Tue, 31 Jan 2017 15:47:53 +0100 Subject: [PATCH 05/25] BAEL-638 Guava Ordering --- .../org/baeldung/guava/GuavaOrderingTest.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java diff --git a/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java b/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java new file mode 100644 index 0000000000..aec9c1e393 --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java @@ -0,0 +1,91 @@ +package org.baeldung.guava; + +import com.google.common.base.Function; +import com.google.common.collect.Ordering; +import com.google.common.primitives.Ints; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class GuavaOrderingTest { + @Test + public void givenListOfIntegers_whenCreateNaturalOrderOrdering_shouldSortProperly() { + //given + List integers = Arrays.asList(3, 2, 1); + + //when + integers.sort(Ordering.natural()); + + //then + assertEquals(Arrays.asList(1, 2, 3), integers); + } + + @Test + public void givenListOfPersonObject_whenSortedUsingCustomOrdering_shouldSortProperly() { + //given + List persons = Arrays.asList(new Person("Michael", 10), new Person("Alice", 3)); + Ordering orderingByName = new Ordering() { + @Override + public int compare(Person p1, Person p2) { + return Ints.compare(p1.age, p2.age); + } + }; + + //when + persons.sort(orderingByName); + + //then + assertEquals(Arrays.asList(new Person("Alice", 3), new Person("Michael", 10)), persons); + } + + @Test + public void givenListOfPersonObject_whenSortedUsingChainedOrdering_shouldSortPropely() { + //given + List persons = Arrays.asList(new Person("Michael", 10), new Person("Alice", 3), new Person("Thomas", null)); + Ordering ordering = Ordering.natural().nullsFirst().onResultOf(new Function() { + @Override + public Comparable apply(Person person) { + return person.age; + } + }); + + //when + persons.sort(ordering); + + //then + assertEquals(Arrays.asList(new Person("Thomas", null), new Person("Alice", 3), new Person("Michael", 10)), persons); + } + + + class Person { + private final String name; + private final Integer age; + + private Person(String name, Integer age) { + this.name = name; + this.age = age; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Person person = (Person) o; + + if (name != null ? !name.equals(person.name) : person.name != null) return false; + return age != null ? age.equals(person.age) : person.age == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (age != null ? age.hashCode() : 0); + return result; + } + } +} From 7a10236334a9c6673a01470a5de3f7ea074dc4e6 Mon Sep 17 00:00:00 2001 From: Tian Baoqiang Date: Tue, 31 Jan 2017 23:54:22 +0800 Subject: [PATCH 06/25] add ConcurrentNavigableMap tests (#1083) * add concurrentmap tests * fix ConcurrentMapTests#givenConcurrentMap_whenKeyWithSameHashCode_thenPerformanceDegrades * add ConcurrentNavigableMap tests --- .../ConcurrentNavigableMapTests.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapTests.java diff --git a/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapTests.java b/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapTests.java new file mode 100644 index 0000000000..93087626a4 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapTests.java @@ -0,0 +1,79 @@ +package com.baeldung.java.concurrentmap; + +import org.junit.Test; + +import java.util.Iterator; +import java.util.NavigableMap; +import java.util.TreeMap; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.testng.Assert.*; + +public class ConcurrentNavigableMapTests { + + @Test + public void givenSkipListMap_whenAccessInMultiThreads_thenOrderingStable() throws InterruptedException { + NavigableMap skipListMap = new ConcurrentSkipListMap<>(); + + updateMapConcurrently(skipListMap, 4); + + Iterator skipListIter = skipListMap + .keySet() + .iterator(); + int previous = skipListIter.next(); + while (skipListIter.hasNext()) { + int current = skipListIter.next(); + assertTrue(previous < current); + } + } + + private void updateMapConcurrently(NavigableMap navigableMap, int concurrencyLevel) throws InterruptedException { + ExecutorService executorService = Executors.newFixedThreadPool(concurrencyLevel); + for (int i = 0; i < concurrencyLevel; i++) { + executorService.execute(() -> { + ThreadLocalRandom random = ThreadLocalRandom.current(); + for (int j = 0; j < 10000; j++) { + navigableMap.put(random.nextInt(), "test"); + } + }); + } + executorService.shutdown(); + executorService.awaitTermination(1, TimeUnit.MINUTES); + } + + @Test + public void givenSkipListMap_whenNavConcurrently_thenCountCorrect() throws InterruptedException { + NavigableMap skipListMap = new ConcurrentSkipListMap<>(); + int count = countMapElementByPollingFirstEntry(skipListMap, 10000, 4); + assertEquals(10000 * 4, count); + } + + @Test + public void givenTreeMap_whenNavConcurrently_thenCountError() throws InterruptedException { + NavigableMap treeMap = new TreeMap<>(); + int count = countMapElementByPollingFirstEntry(treeMap, 10000, 4); + assertNotEquals(10000 * 4, count); + } + + private int countMapElementByPollingFirstEntry(NavigableMap navigableMap, int elementCount, int concurrencyLevel) throws InterruptedException { + for (int i = 0; i < elementCount * concurrencyLevel; i++) { + navigableMap.put(i, i); + } + AtomicInteger counter = new AtomicInteger(0); + ExecutorService executorService = Executors.newFixedThreadPool(concurrencyLevel); + for (int j = 0; j < concurrencyLevel; j++) { + executorService.execute(() -> { + for (int i = 0; i < elementCount; i++) { + if (navigableMap.pollFirstEntry() != null) { + counter.incrementAndGet(); + } + } + }); + } + executorService.shutdown(); + executorService.awaitTermination(1, TimeUnit.MINUTES); + return counter.get(); + } + +} From d07136065a3403c3f9a4d295ccd3ec8e7693032f Mon Sep 17 00:00:00 2001 From: mujahid Date: Wed, 1 Feb 2017 02:11:46 +0800 Subject: [PATCH 07/25] BAEL-347 - Full-text search with SOLR (#1080) * solr-fulltext-search module created * solr-fulltext-search modue created --- pom.xml | 1 + solr-fulltext-search/pom.xml | 90 +++++++++++++++++++ .../solr/fulltexh/search/model/Product.java | 5 ++ .../search/service/SolrSearchService.java | 5 ++ 4 files changed, 101 insertions(+) create mode 100644 solr-fulltext-search/pom.xml create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java diff --git a/pom.xml b/pom.xml index b76c9b8ddd..6b95ba0350 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ resteasy selenium-junit-testng + solr-fulltext-search spark-java spring-akka spring-amqp diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml new file mode 100644 index 0000000000..4afcb5838a --- /dev/null +++ b/solr-fulltext-search/pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + com.baeldung + solr-fulltext-search + 0.0.1-SNAPSHOT + jar + solr-fulltext-search + + + + UTF-8 + 2.19.1 + + + + + org.apache.solr + solr-solrj + 6.1.0 + + + log4j + log4j + 1.2.16 + + + junit + junit + 4.12 + test + + + + + + + + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + \ No newline at end of file diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java new file mode 100644 index 0000000000..b5fb334282 --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java @@ -0,0 +1,5 @@ +package com.baeldung.solr.fulltexh.search.model; + +public class Product { + +} diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java new file mode 100644 index 0000000000..aa511f0e1b --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java @@ -0,0 +1,5 @@ +package com.baeldung.solr.fulltexh.search.service; + +public interface SolrSearchService { + +} From a0781d1d8862aa81fc8138d48a062fbd38c19e47 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 1 Feb 2017 01:59:02 +0530 Subject: [PATCH 08/25] BAEL 533: Pull request for Java 9 Convenience Factory Methods for Collections (#1078) * remove verbose from compiler plugin, change project build encoding to UTF-8 * BAEL - 533 - convenience factory methods for collections test files --- core-java-9/pom.xml | 4 +- .../collections/ListFactoryMethodsTest.java | 61 ++++++++++++++++++ .../collections/MapFactoryMethodsTest.java | 62 +++++++++++++++++++ .../collections/SetFactoryMethodsTest.java | 60 ++++++++++++++++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsTest.java create mode 100644 core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsTest.java create mode 100644 core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsTest.java diff --git a/core-java-9/pom.xml b/core-java-9/pom.xml index decba19c53..9d1ff29ef7 100644 --- a/core-java-9/pom.xml +++ b/core-java-9/pom.xml @@ -57,7 +57,6 @@ 1.9 1.9 - true @@ -72,6 +71,9 @@ + + UTF-8 + 1.7.21 diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsTest.java b/core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsTest.java new file mode 100644 index 0000000000..8e19d00b6a --- /dev/null +++ b/core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsTest.java @@ -0,0 +1,61 @@ +package com.baeldung.java9.language.collections; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +public class ListFactoryMethodsTest { + + @Test + public void whenListCreated_thenSuccess() { + List traditionlList = new ArrayList(); + traditionlList.add("foo"); + traditionlList.add("bar"); + traditionlList.add("baz"); + List factoryCreatedList = List.of("foo", "bar", "baz"); + assertEquals(traditionlList, factoryCreatedList); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemAdd_ifUnSupportedOpExpnThrown_thenSuccess() { + List list = List.of("foo", "bar"); + list.add("baz"); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemModify_ifUnSupportedOpExpnThrown_thenSuccess() { + List list = List.of("foo", "bar"); + list.set(0, "baz"); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemRemove_ifUnSupportedOpExpnThrown_thenSuccess() { + List list = List.of("foo", "bar"); + list.remove("foo"); + } + + @Test(expected = NullPointerException.class) + public void onNullElem_ifNullPtrExpnThrown_thenSuccess() { + List.of("foo", "bar", null); + } + + @Test + public void ifNotArrayList_thenSuccess() { + List list = List.of("foo", "bar"); + assertFalse(list instanceof ArrayList); + } + + @Test + public void ifListSizeIsOne_thenSuccess() { + int[] arr = { 1, 2, 3, 4 }; + List list = List.of(arr); + assertEquals(1, list.size()); + assertArrayEquals(arr, list.get(0)); + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsTest.java b/core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsTest.java new file mode 100644 index 0000000000..13469ff93d --- /dev/null +++ b/core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsTest.java @@ -0,0 +1,62 @@ +package com.baeldung.java9.language.collections; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +public class MapFactoryMethodsTest { + + @Test + public void whenMapCreated_thenSuccess() { + Map traditionlMap = new HashMap(); + traditionlMap.put("foo", "a"); + traditionlMap.put("bar", "b"); + traditionlMap.put("baz", "c"); + Map factoryCreatedMap = Map.of("foo", "a", "bar", "b", "baz", "c"); + assertEquals(traditionlMap, factoryCreatedMap); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemAdd_ifUnSupportedOpExpnThrown_thenSuccess() { + Map map = Map.of("foo", "a", "bar", "b"); + map.put("baz", "c"); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemModify_ifUnSupportedOpExpnThrown_thenSuccess() { + Map map = Map.of("foo", "a", "bar", "b"); + map.put("foo", "c"); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemRemove_ifUnSupportedOpExpnThrown_thenSuccess() { + Map map = Map.of("foo", "a", "bar", "b"); + map.remove("foo"); + } + + @Test(expected = IllegalArgumentException.class) + public void givenDuplicateKeys_ifIllegalArgExp_thenSuccess() { + Map.of("foo", "a", "foo", "b"); + } + + @Test(expected = NullPointerException.class) + public void onNullKey_ifNullPtrExp_thenSuccess() { + Map.of("foo", "a", null, "b"); + } + + @Test(expected = NullPointerException.class) + public void onNullValue_ifNullPtrExp_thenSuccess() { + Map.of("foo", "a", "bar", null); + } + + @Test + public void ifNotHashMap_thenSuccess() { + Map map = Map.of("foo", "a", "bar", "b"); + assertFalse(map instanceof HashMap); + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsTest.java b/core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsTest.java new file mode 100644 index 0000000000..b8537d7c82 --- /dev/null +++ b/core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsTest.java @@ -0,0 +1,60 @@ +package com.baeldung.java9.language.collections; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +public class SetFactoryMethodsTest { + + @Test + public void whenSetCreated_thenSuccess() { + Set traditionlSet = new HashSet(); + traditionlSet.add("foo"); + traditionlSet.add("bar"); + traditionlSet.add("baz"); + Set factoryCreatedSet = Set.of("foo", "bar", "baz"); + assertEquals(traditionlSet, factoryCreatedSet); + } + + @Test(expected = IllegalArgumentException.class) + public void onDuplicateElem_IfIllegalArgExp_thenSuccess() { + Set.of("foo", "bar", "baz", "foo"); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemAdd_ifUnSupportedOpExpnThrown_thenSuccess() { + Set set = Set.of("foo", "bar"); + set.add("baz"); + } + + @Test(expected = UnsupportedOperationException.class) + public void onElemRemove_ifUnSupportedOpExpnThrown_thenSuccess() { + Set set = Set.of("foo", "bar", "baz"); + set.remove("foo"); + } + + @Test(expected = NullPointerException.class) + public void onNullElem_ifNullPtrExpnThrown_thenSuccess() { + Set.of("foo", "bar", null); + } + + @Test + public void ifNotHashSet_thenSuccess() { + Set list = Set.of("foo", "bar"); + assertFalse(list instanceof HashSet); + } + + @Test + public void ifSetSizeIsOne_thenSuccess() { + int[] arr = { 1, 2, 3, 4 }; + Set set = Set.of(arr); + assertEquals(1, set.size()); + assertArrayEquals(arr, set.iterator().next()); + } + +} From fb50f56cfd5bce7a139f10a68ac3692235b65355 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Tue, 31 Jan 2017 21:46:46 +0100 Subject: [PATCH 09/25] BAEL-424 code for javaslang Try (#1068) * BAEL-424 code for javaslang Try * BAEL-424 more api examples of try * BAEL-424 less verbose names of test, two exceptions types in pattern matching --- .../exception/handling/JavaTryCatch.java | 21 ++++ .../exception/handling/JavaslangTry.java | 18 +++ .../handling/client/ClientException.java | 8 ++ .../exception/handling/client/HttpClient.java | 6 + .../exception/handling/client/Response.java | 9 ++ .../exception/handling/JavaslangTryTest.java | 115 ++++++++++++++++++ 6 files changed, 177 insertions(+) create mode 100644 javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaTryCatch.java create mode 100644 javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaslangTry.java create mode 100644 javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/ClientException.java create mode 100644 javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/HttpClient.java create mode 100644 javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/Response.java create mode 100644 javaslang/src/test/java/com/baeldung/javaslang/exception/handling/JavaslangTryTest.java diff --git a/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaTryCatch.java b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaTryCatch.java new file mode 100644 index 0000000000..2849d3424f --- /dev/null +++ b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaTryCatch.java @@ -0,0 +1,21 @@ +package com.baeldung.javaslang.exception.handling; + +import com.baeldung.javaslang.exception.handling.client.ClientException; +import com.baeldung.javaslang.exception.handling.client.HttpClient; +import com.baeldung.javaslang.exception.handling.client.Response; + +public class JavaTryCatch { + private HttpClient httpClient; + + public JavaTryCatch(HttpClient httpClient) { + this.httpClient = httpClient; + } + + public Response getResponse() { + try { + return httpClient.call(); + } catch (ClientException e) { + return null; + } + } +} diff --git a/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaslangTry.java b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaslangTry.java new file mode 100644 index 0000000000..6945f3bc0b --- /dev/null +++ b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/JavaslangTry.java @@ -0,0 +1,18 @@ +package com.baeldung.javaslang.exception.handling; + + +import com.baeldung.javaslang.exception.handling.client.HttpClient; +import com.baeldung.javaslang.exception.handling.client.Response; +import javaslang.control.Try; + +public class JavaslangTry { + private final HttpClient httpClient; + + public JavaslangTry(HttpClient httpClient) { + this.httpClient = httpClient; + } + + public Try getResponse() { + return Try.of(httpClient::call); + } +} diff --git a/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/ClientException.java b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/ClientException.java new file mode 100644 index 0000000000..7993e10117 --- /dev/null +++ b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/ClientException.java @@ -0,0 +1,8 @@ +package com.baeldung.javaslang.exception.handling.client; + + +public class ClientException extends Exception { + public ClientException(String message) { + super(message); + } +} diff --git a/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/HttpClient.java b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/HttpClient.java new file mode 100644 index 0000000000..f14e6c718f --- /dev/null +++ b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/HttpClient.java @@ -0,0 +1,6 @@ +package com.baeldung.javaslang.exception.handling.client; + + +public interface HttpClient { + Response call() throws ClientException; +} diff --git a/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/Response.java b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/Response.java new file mode 100644 index 0000000000..fded319245 --- /dev/null +++ b/javaslang/src/main/java/com/baeldung/javaslang/exception/handling/client/Response.java @@ -0,0 +1,9 @@ +package com.baeldung.javaslang.exception.handling.client; + +public class Response { + public final String id; + + public Response(String id) { + this.id = id; + } +} diff --git a/javaslang/src/test/java/com/baeldung/javaslang/exception/handling/JavaslangTryTest.java b/javaslang/src/test/java/com/baeldung/javaslang/exception/handling/JavaslangTryTest.java new file mode 100644 index 0000000000..ddf697444e --- /dev/null +++ b/javaslang/src/test/java/com/baeldung/javaslang/exception/handling/JavaslangTryTest.java @@ -0,0 +1,115 @@ +package com.baeldung.javaslang.exception.handling; + +import com.baeldung.javaslang.exception.handling.client.ClientException; +import com.baeldung.javaslang.exception.handling.client.HttpClient; +import com.baeldung.javaslang.exception.handling.client.Response; +import javaslang.collection.Stream; +import javaslang.control.Option; +import javaslang.control.Try; +import org.junit.Test; + +import java.util.function.Function; +import java.util.stream.Collectors; + +import static javaslang.API.Case; +import static javaslang.API.Match; +import static javaslang.Predicates.instanceOf; +import static org.junit.Assert.*; + +public class JavaslangTryTest { + + @Test + public void givenHttpClient_whenMakeACall_shouldReturnSuccess() { + //given + Integer defaultChainedResult = 1; + String id = "a"; + HttpClient httpClient = () -> new Response(id); + + //when + Try response = new JavaslangTry(httpClient).getResponse(); + Integer chainedResult = response + .map(this::actionThatTakesResponse) + .getOrElse(defaultChainedResult); + Stream stream = response.toStream().map(it -> it.id); + + //then + assertTrue(!stream.isEmpty()); + assertTrue(response.isSuccess()); + response.onSuccess(r -> assertEquals(id, r.id)); + response.andThen(r -> assertEquals(id, r.id)); + assertNotEquals(defaultChainedResult, chainedResult); + } + + @Test + public void givenHttpClientFailure_whenMakeACall_shouldReturnFailure() { + //given + Integer defaultChainedResult = 1; + HttpClient httpClient = () -> { + throw new ClientException("problem"); + }; + + //when + Try response = new JavaslangTry(httpClient).getResponse(); + Integer chainedResult = response + .map(this::actionThatTakesResponse) + .getOrElse(defaultChainedResult); + Option optionalResponse = response.toOption(); + + //then + assertTrue(optionalResponse.isEmpty()); + assertTrue(response.isFailure()); + response.onFailure(ex -> assertTrue(ex instanceof ClientException)); + assertEquals(defaultChainedResult, chainedResult); + } + + @Test + public void givenHttpClientThatFailure_whenMakeACall_shouldReturnFailureAndNotRecover() { + //given + Response defaultResponse = new Response("b"); + HttpClient httpClient = () -> { + throw new RuntimeException("critical problem"); + }; + + //when + Try recovered = new JavaslangTry(httpClient).getResponse() + .recover(r -> Match(r).of( + Case(instanceOf(ClientException.class), defaultResponse) + )); + + //then + assertTrue(recovered.isFailure()); + +// recovered.getOrElseThrow(throwable -> { +// throw new RuntimeException(throwable); +// }); + } + + @Test + public void givenHttpClientThatFailure_whenMakeACall_shouldReturnFailureAndRecover() { + //given + Response defaultResponse = new Response("b"); + HttpClient httpClient = () -> { + throw new ClientException("non critical problem"); + }; + + //when + Try recovered = new JavaslangTry(httpClient).getResponse() + .recover(r -> Match(r).of( + Case(instanceOf(ClientException.class), defaultResponse), + Case(instanceOf(IllegalArgumentException.class), defaultResponse) + )); + + //then + assertTrue(recovered.isSuccess()); + } + + + public int actionThatTakesResponse(Response response) { + return response.id.hashCode(); + } + + public int actionThatTakesTryResponse(Try response, int defaultTransformation){ + return response.transform(responses -> response.map(it -> it.id.hashCode()).getOrElse(defaultTransformation)); + } + +} \ No newline at end of file From b2fcd4a953f39d1a3a4b7207b9e08c220da99e4f Mon Sep 17 00:00:00 2001 From: Stephen Braimah Date: Tue, 31 Jan 2017 22:21:24 +0000 Subject: [PATCH 10/25] BAEL-639: Guide to Guava's EventBus Tests --- .../java/org/baeldung/guava/CustomEvent.java | 18 ++++++++ .../org/baeldung/guava/EventBusWrapper.java | 22 ++++++++++ .../org/baeldung/guava/EventListener.java | 33 +++++++++++++++ .../org/baeldung/guava/GuavaEventBusTest.java | 41 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 guava/src/test/java/org/baeldung/guava/CustomEvent.java create mode 100644 guava/src/test/java/org/baeldung/guava/EventBusWrapper.java create mode 100644 guava/src/test/java/org/baeldung/guava/EventListener.java create mode 100644 guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java diff --git a/guava/src/test/java/org/baeldung/guava/CustomEvent.java b/guava/src/test/java/org/baeldung/guava/CustomEvent.java new file mode 100644 index 0000000000..78348065b2 --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/CustomEvent.java @@ -0,0 +1,18 @@ +package org.baeldung.guava; + + +public class CustomEvent { + private String action; + + public CustomEvent(String action) { + this.action = action; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } +} diff --git a/guava/src/test/java/org/baeldung/guava/EventBusWrapper.java b/guava/src/test/java/org/baeldung/guava/EventBusWrapper.java new file mode 100644 index 0000000000..eddaca0baf --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/EventBusWrapper.java @@ -0,0 +1,22 @@ +package org.baeldung.guava; + +import com.google.common.eventbus.EventBus; + +class EventBusWrapper { + + private static EventBus eventBus = new EventBus(); + + static void register(Object object){ + eventBus.register(object); + } + + static void unregister(Object object){ + eventBus.unregister(object); + } + + static void post(Object object){ + eventBus.post(object); + } + + +} diff --git a/guava/src/test/java/org/baeldung/guava/EventListener.java b/guava/src/test/java/org/baeldung/guava/EventListener.java new file mode 100644 index 0000000000..17a3ac093e --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/EventListener.java @@ -0,0 +1,33 @@ +package org.baeldung.guava; +import com.google.common.eventbus.Subscribe; + +public class EventListener { + + private static int eventsHandled; + + /** + * Handles events of type String * + */ + @Subscribe + public void stringEvent(String event){ + System.out.println("do event ["+event+"]"); + eventsHandled++; + } + + /** + * Handles events of type CustomEvent + */ + @Subscribe + public void someEvent(CustomEvent customEvent){ + System.out.println("do event ["+ customEvent.getAction()+"]"); + eventsHandled++; + } + + public int getEventsHandled() { + return eventsHandled; + } + + public void resetEventsHandled(){ + eventsHandled = 0; + } +} diff --git a/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java b/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java new file mode 100644 index 0000000000..09f7eb775d --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java @@ -0,0 +1,41 @@ +package org.baeldung.guava; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class GuavaEventBusTest { + + private EventListener listener; + + @Before + public void setUp() throws Exception { + listener = new EventListener(); + EventBusWrapper.register(listener); + } + + @After + public void tearDown() throws Exception { + EventBusWrapper.unregister(listener); + } + + @Test + public void givenStringEvent_whenEventHandled_thenSuccess() throws Exception { + listener.resetEventsHandled(); + + EventBusWrapper.post("String Event"); + assertEquals(1,listener.getEventsHandled()); + + } + + @Test + public void givenCustomEvent_whenEventHandled_thenSuccess() throws Exception { + listener.resetEventsHandled(); + + CustomEvent customEvent = new CustomEvent("Custom Event"); + EventBusWrapper.post(customEvent); + + assertEquals(1,listener.getEventsHandled()); + } +} From e385c7409b5aefbfbc815922844a26a713af2491 Mon Sep 17 00:00:00 2001 From: Dotun Kola-Olaleye Date: Wed, 1 Feb 2017 00:16:55 +0100 Subject: [PATCH 11/25] String to char array and char array to String (#1002) * String to char array and char array to String. * Method change * Custom ThreadPool In Java 8 Parallel Streams * Implemented suggested edits from editor. * Broke long method signature * Changed primitive type int to long and formula. * Update wrapper type to Long --- .../baeldung/CharArrayToStringUnitTest.java | 62 +++++++++++++++++++ .../baeldung/StringToCharArrayUnitTest.java | 20 ++++++ .../streams/ThreadPoolInParallelStream.java | 45 ++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/CharArrayToStringUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/StringToCharArrayUnitTest.java create mode 100644 core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java diff --git a/core-java/src/test/java/com/baeldung/CharArrayToStringUnitTest.java b/core-java/src/test/java/com/baeldung/CharArrayToStringUnitTest.java new file mode 100644 index 0000000000..2f7830bbf4 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/CharArrayToStringUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CharArrayToStringUnitTest { + + @Test + public void givenCharArray_whenCallingStringConstructor_shouldConvertToString() { + char[] charArray = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'}; + String result = new String(charArray); + String expectedValue = "character"; + + assertEquals(expectedValue, result); + } + + @Test + public void givenCharArray_whenCallingStringConstructorWithOffsetAndLength_shouldConvertToString(){ + char[] charArray = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'}; + String result = new String(charArray, 4, 3); + String expectedValue = "act"; + + assertEquals(expectedValue, result); + } + + @Test + public void givenCharArray_whenCallingStringCopyValueOf_shouldConvertToString(){ + char[] charArray = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'}; + String result = String.copyValueOf(charArray); + String expectedValue = "character"; + + assertEquals(expectedValue, result); + } + + @Test + public void givenCharArray_whenCallingStringCopyValueOfWithOffsetAndLength_shouldConvertToString(){ + char[] charArray = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'}; + String result = String.copyValueOf(charArray, 0, 4); + String expectedValue = "char"; + + assertEquals(expectedValue, result); + } + + @Test + public void givenCharArray_whenCallingStringValueOf_shouldConvertToString(){ + char[] charArray = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'}; + String result = String.valueOf(charArray); + String expectedValue = "character"; + + assertEquals(expectedValue, result); + } + + @Test + public void givenCharArray_whenCallingStringValueOfWithOffsetAndLength_shouldConvertToString(){ + char[] charArray = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'}; + String result = String.valueOf(charArray, 3, 4); + String expectedValue = "ract"; + + assertEquals(expectedValue, result); + } +} diff --git a/core-java/src/test/java/com/baeldung/StringToCharArrayUnitTest.java b/core-java/src/test/java/com/baeldung/StringToCharArrayUnitTest.java new file mode 100644 index 0000000000..2e7dc24a17 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/StringToCharArrayUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class StringToCharArrayUnitTest { + +@Test +public void givenString_whenCallingStringToCharArray_shouldConvertToCharArray() { + String givenString = "characters"; + + char[] result = givenString.toCharArray(); + + char[] expectedCharArray = { 'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', 's' }; + + assertArrayEquals(expectedCharArray, result); +} + +} diff --git a/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java b/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java new file mode 100644 index 0000000000..d654f45626 --- /dev/null +++ b/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java @@ -0,0 +1,45 @@ +package org.baeldung.java.streams; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; +import java.util.stream.Stream; + +import org.junit.Test; + +public class ThreadPoolInParallelStream { + + @Test + public void giveRangeOfLongs_whenSummedInParallel_shouldBeEqualToExpectedTotal() + throws InterruptedException, ExecutionException { + List aList = new ArrayList<>(); + long lastNum = 1_000_000; + long firstNum = 1; + + long expectedTotal = (lastNum + firstNum) * lastNum / 2; + + for(long i = firstNum; i <= lastNum; i++){ + aList.add(i); + } + + ForkJoinPool customThreadPool = new ForkJoinPool(4); + long actualTotal = customThreadPool.submit(() -> aList.parallelStream().reduce( + 0L, (x, y) -> { + return x + y; + })).get(); + + assertEquals(expectedTotal, actualTotal); + } + + @Test + public void givenList_whenCallingParallelStream_shouldBeParallelStream(){ + List aList = new ArrayList<>(); + Stream parallelStream = aList.parallelStream(); + + assertTrue(parallelStream.isParallel()); + } +} From 352b466bce5f3a2d6eb588f5be9ebdc603919f6e Mon Sep 17 00:00:00 2001 From: Predrag Maric Date: Wed, 1 Feb 2017 01:34:33 +0100 Subject: [PATCH 12/25] BAEL-638 Fixed one variable name --- guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java b/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java index aec9c1e393..5ecf4f048d 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaOrderingTest.java @@ -27,7 +27,7 @@ public class GuavaOrderingTest { public void givenListOfPersonObject_whenSortedUsingCustomOrdering_shouldSortProperly() { //given List persons = Arrays.asList(new Person("Michael", 10), new Person("Alice", 3)); - Ordering orderingByName = new Ordering() { + Ordering orderingByAge = new Ordering() { @Override public int compare(Person p1, Person p2) { return Ints.compare(p1.age, p2.age); @@ -35,7 +35,7 @@ public class GuavaOrderingTest { }; //when - persons.sort(orderingByName); + persons.sort(orderingByAge); //then assertEquals(Arrays.asList(new Person("Alice", 3), new Person("Michael", 10)), persons); From 28cbdeb4a9d3814d398900f372e05386a7ec839b Mon Sep 17 00:00:00 2001 From: Predrag Maric Date: Wed, 1 Feb 2017 01:49:35 +0100 Subject: [PATCH 13/25] Renamed one class in Kotlin module --- ...nteroperabilityTest.kt => KotlinJavaInteroperabilityTest.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename kotlin/src/test/kotlin/com/baeldung/kotlin/{KotlinScalaInteroperabilityTest.kt => KotlinJavaInteroperabilityTest.kt} (90%) diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/KotlinScalaInteroperabilityTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/KotlinJavaInteroperabilityTest.kt similarity index 90% rename from kotlin/src/test/kotlin/com/baeldung/kotlin/KotlinScalaInteroperabilityTest.kt rename to kotlin/src/test/kotlin/com/baeldung/kotlin/KotlinJavaInteroperabilityTest.kt index 6ba7f0976f..91ccaabf6f 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/KotlinScalaInteroperabilityTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/KotlinJavaInteroperabilityTest.kt @@ -5,7 +5,7 @@ import org.junit.Test import kotlin.test.assertEquals -class KotlinScalaInteroperabilityTest { +class KotlinJavaInteroperabilityTest { @Test fun givenLowercaseString_whenExecuteMethodFromJavaStringUtils_shouldReturnStringUppercase() { From 5548022a2bd56083bf83987edefff8b0a9d1d2e6 Mon Sep 17 00:00:00 2001 From: Piotr Sliwa Date: Wed, 1 Feb 2017 07:53:17 +0100 Subject: [PATCH 14/25] BAEL-628: Added sources for "Constructor Injection in Spring with Lombok" article. (#1064) * BAEL-628: Added sources for "Constructor Injection in Spring with Lombok" article. * BAEL-628: Removed unneccessary @Autowired + Apologizer example. --- spring-core/README.md | 1 + spring-core/pom.xml | 6 +++ .../java/com/baeldung/lombok/Apologizer.java | 22 +++++++++++ .../java/com/baeldung/lombok/Fareweller.java | 18 +++++++++ .../java/com/baeldung/lombok/Greeter.java | 15 ++++++++ .../java/com/baeldung/lombok/Thanker.java | 16 ++++++++ .../java/com/baeldung/lombok/Translator.java | 5 +++ .../lombok/ApologizerAutowiringTest.java | 33 +++++++++++++++++ .../com/baeldung/lombok/ApologizerTest.java | 21 +++++++++++ .../lombok/FarewellAutowiringTest.java | 31 ++++++++++++++++ .../com/baeldung/lombok/FarewellerTest.java | 20 ++++++++++ .../java/com/baeldung/lombok/GreeterTest.java | 37 +++++++++++++++++++ .../java/com/baeldung/lombok/TestConfig.java | 17 +++++++++ .../lombok/ThankerAutowiringTest.java | 31 ++++++++++++++++ .../java/com/baeldung/lombok/ThankerTest.java | 20 ++++++++++ 15 files changed, 293 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/lombok/Apologizer.java create mode 100644 spring-core/src/main/java/com/baeldung/lombok/Fareweller.java create mode 100644 spring-core/src/main/java/com/baeldung/lombok/Greeter.java create mode 100644 spring-core/src/main/java/com/baeldung/lombok/Thanker.java create mode 100644 spring-core/src/main/java/com/baeldung/lombok/Translator.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/ApologizerAutowiringTest.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/ApologizerTest.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/FarewellAutowiringTest.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/FarewellerTest.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/GreeterTest.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/TestConfig.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/ThankerAutowiringTest.java create mode 100644 spring-core/src/test/java/com/baeldung/lombok/ThankerTest.java diff --git a/spring-core/README.md b/spring-core/README.md index 30ba30f889..f6aaaf44a0 100644 --- a/spring-core/README.md +++ b/spring-core/README.md @@ -3,3 +3,4 @@ - [Exploring the Spring BeanFactory API](http://www.baeldung.com/spring-beanfactory) - [How to use the Spring FactoryBean?](http://www.baeldung.com/spring-factorybean) - [Constructor Dependency Injection in Spring](http://www.baeldung.com/constructor-injection-in-spring) +- [Constructor Injection in Spring with Lombok](http://inprogress.baeldung.com/constructor-injection-in-spring-with-lombok) diff --git a/spring-core/pom.xml b/spring-core/pom.xml index bf05f6a6f0..3b423104d7 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -52,6 +52,11 @@ guava ${guava.version} + + org.projectlombok + lombok + ${lombok.version} + @@ -131,6 +136,7 @@ 4.12 20.0 2.6 + 1.16.12 diff --git a/spring-core/src/main/java/com/baeldung/lombok/Apologizer.java b/spring-core/src/main/java/com/baeldung/lombok/Apologizer.java new file mode 100644 index 0000000000..ddce9cdc52 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/lombok/Apologizer.java @@ -0,0 +1,22 @@ +package com.baeldung.lombok; + +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@AllArgsConstructor +public class Apologizer { + + private final Translator translator; + private final String message; + + @Autowired + public Apologizer(Translator translator) { + this(translator, "sorry"); + } + + public String apologize() { + return translator.translate(message); + } +} diff --git a/spring-core/src/main/java/com/baeldung/lombok/Fareweller.java b/spring-core/src/main/java/com/baeldung/lombok/Fareweller.java new file mode 100644 index 0000000000..b10ebb72b9 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/lombok/Fareweller.java @@ -0,0 +1,18 @@ +package com.baeldung.lombok; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class Fareweller { + + private final Translator translator; + + public Fareweller(Translator translator) { + this.translator = translator; + } + + public String farewell() { + return translator.translate("bye"); + } +} diff --git a/spring-core/src/main/java/com/baeldung/lombok/Greeter.java b/spring-core/src/main/java/com/baeldung/lombok/Greeter.java new file mode 100644 index 0000000000..ddbc024ce7 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/lombok/Greeter.java @@ -0,0 +1,15 @@ +package com.baeldung.lombok; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class Greeter { + + @Autowired + private Translator translator; + + public String greet() { + return translator.translate("hello"); + } +} diff --git a/spring-core/src/main/java/com/baeldung/lombok/Thanker.java b/spring-core/src/main/java/com/baeldung/lombok/Thanker.java new file mode 100644 index 0000000000..784100c258 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/lombok/Thanker.java @@ -0,0 +1,16 @@ +package com.baeldung.lombok; + +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@AllArgsConstructor +public class Thanker { + + private final Translator translator; + + public String thank() { + return translator.translate("thank you"); + } +} diff --git a/spring-core/src/main/java/com/baeldung/lombok/Translator.java b/spring-core/src/main/java/com/baeldung/lombok/Translator.java new file mode 100644 index 0000000000..2dea20b726 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/lombok/Translator.java @@ -0,0 +1,5 @@ +package com.baeldung.lombok; + +public interface Translator { + String translate(String input); +} diff --git a/spring-core/src/test/java/com/baeldung/lombok/ApologizerAutowiringTest.java b/spring-core/src/test/java/com/baeldung/lombok/ApologizerAutowiringTest.java new file mode 100644 index 0000000000..3e7c775f91 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/ApologizerAutowiringTest.java @@ -0,0 +1,33 @@ +package com.baeldung.lombok; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( + loader = AnnotationConfigContextLoader.class, + classes = TestConfig.class) +public class ApologizerAutowiringTest { + + private final static String TRANSLATED = "TRANSLATED"; + + @Autowired + private Apologizer apologizer; + + @Autowired + private Translator translator; + + @Test + public void apologizeWithTranslatedMessage() { + when(translator.translate("sorry")).thenReturn(TRANSLATED); + assertEquals(TRANSLATED, apologizer.apologize()); + } + +} \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/lombok/ApologizerTest.java b/spring-core/src/test/java/com/baeldung/lombok/ApologizerTest.java new file mode 100644 index 0000000000..28bd08c89f --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/ApologizerTest.java @@ -0,0 +1,21 @@ +package com.baeldung.lombok; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ApologizerTest { + + private final static String MESSAGE = "MESSAGE"; + private final static String TRANSLATED = "TRANSLATED"; + + @Test + public void apologizeWithCustomTranslatedMessage() { + Translator translator = mock(Translator.class); + Apologizer apologizer = new Apologizer(translator, MESSAGE); + when(translator.translate(MESSAGE)).thenReturn(TRANSLATED); + assertEquals(TRANSLATED, apologizer.apologize()); + } +} diff --git a/spring-core/src/test/java/com/baeldung/lombok/FarewellAutowiringTest.java b/spring-core/src/test/java/com/baeldung/lombok/FarewellAutowiringTest.java new file mode 100644 index 0000000000..d55d44fb3e --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/FarewellAutowiringTest.java @@ -0,0 +1,31 @@ +package com.baeldung.lombok; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( + loader = AnnotationConfigContextLoader.class, + classes = TestConfig.class) +public class FarewellAutowiringTest { + + @Autowired + private Fareweller fareweller; + + @Autowired + private Translator translator; + + @Test + public void sayByeWithTranslatedMessage() { + String translated = "translated"; + when(translator.translate("bye")).thenReturn(translated); + assertEquals(translated, fareweller.farewell()); + } +} diff --git a/spring-core/src/test/java/com/baeldung/lombok/FarewellerTest.java b/spring-core/src/test/java/com/baeldung/lombok/FarewellerTest.java new file mode 100644 index 0000000000..a02ad1d8ac --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/FarewellerTest.java @@ -0,0 +1,20 @@ +package com.baeldung.lombok; + +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class FarewellerTest { + + private final static String TRANSLATED = "TRANSLATED"; + + @Test + public void sayByeWithTranslatedMessage() { + Translator translator = mock(Translator.class); + when(translator.translate("bye")).thenReturn(TRANSLATED); + Fareweller fareweller = new Fareweller(translator); + assertEquals(TRANSLATED, fareweller.farewell()); + } +} \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/lombok/GreeterTest.java b/spring-core/src/test/java/com/baeldung/lombok/GreeterTest.java new file mode 100644 index 0000000000..0f66eaf301 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/GreeterTest.java @@ -0,0 +1,37 @@ +package com.baeldung.lombok; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( + loader = AnnotationConfigContextLoader.class, + classes = TestConfig.class) +public class GreeterTest { + + @Autowired + private Greeter greeter; + + @Autowired + private Translator translator; + + @Test + public void greetWithTranslatedMessage() { + String translated = "translated"; + when(translator.translate("hello")).thenReturn(translated); + assertEquals(translated, greeter.greet()); + } + + @Test(expected = NullPointerException.class) + public void throwWhenInstantiated() { + Greeter greeter = new Greeter(); + greeter.greet(); + } +} \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/lombok/TestConfig.java b/spring-core/src/test/java/com/baeldung/lombok/TestConfig.java new file mode 100644 index 0000000000..3278a8188f --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/TestConfig.java @@ -0,0 +1,17 @@ +package com.baeldung.lombok; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static org.mockito.Mockito.mock; + +@Configuration +@ComponentScan("com.baeldung.lombok") +class TestConfig { + + @Bean + public Translator mockTranslator() { + return mock(Translator.class); + } +} diff --git a/spring-core/src/test/java/com/baeldung/lombok/ThankerAutowiringTest.java b/spring-core/src/test/java/com/baeldung/lombok/ThankerAutowiringTest.java new file mode 100644 index 0000000000..59aded5831 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/ThankerAutowiringTest.java @@ -0,0 +1,31 @@ +package com.baeldung.lombok; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( + loader = AnnotationConfigContextLoader.class, + classes = TestConfig.class) +public class ThankerAutowiringTest { + + @Autowired + private Thanker thanker; + + @Autowired + private Translator translator; + + @Test + public void thankWithTranslatedMessage() { + String translated = "translated"; + when(translator.translate("thank you")).thenReturn(translated); + assertEquals(translated, thanker.thank()); + } +} \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/lombok/ThankerTest.java b/spring-core/src/test/java/com/baeldung/lombok/ThankerTest.java new file mode 100644 index 0000000000..466762fa50 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/lombok/ThankerTest.java @@ -0,0 +1,20 @@ +package com.baeldung.lombok; + +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ThankerTest { + + private final static String TRANSLATED = "TRANSLATED"; + + @Test + public void thankWithTranslatedMessage() { + Translator translator = mock(Translator.class); + when(translator.translate("thank you")).thenReturn(TRANSLATED); + Thanker thanker = new Thanker(translator); + assertEquals(TRANSLATED, thanker.thank()); + } +} \ No newline at end of file From 5c85259243b5e2b31f6d37e9c7c53e0c93666a6e Mon Sep 17 00:00:00 2001 From: pedja4 Date: Wed, 1 Feb 2017 09:42:32 +0100 Subject: [PATCH 15/25] Update README.md Added several relevant articles --- core-java/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core-java/README.md b/core-java/README.md index b653cfcfaf..cd16935864 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -54,3 +54,6 @@ - [The Basics of Java Generics](http://www.baeldung.com/java-generics) - [The Traveling Salesman Problem in Java](http://www.baeldung.com/java-simulated-annealing-for-traveling-salesman) - [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven) +- [Guide to java.util.concurrent.Future](http://www.baeldung.com/java-future) +- [Guide to java.util.concurrent.BlockingQueue](http://www.baeldung.com/java-blocking-queue) +- [Guide to CountDownLatch in Java](http://www.baeldung.com/java-countdown-latch) From 1b1b5becd7d3950f25d4b3a7f2e2b4a23e307331 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Wed, 1 Feb 2017 14:10:57 +0100 Subject: [PATCH 16/25] BAEL-639 - reformatting --- .../src/test/java/org/baeldung/guava/GuavaEventBusTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java b/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java index 09f7eb775d..bd966187ab 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java @@ -3,6 +3,7 @@ package org.baeldung.guava; import org.junit.After; import org.junit.Before; import org.junit.Test; + import static org.junit.Assert.*; public class GuavaEventBusTest { @@ -25,7 +26,7 @@ public class GuavaEventBusTest { listener.resetEventsHandled(); EventBusWrapper.post("String Event"); - assertEquals(1,listener.getEventsHandled()); + assertEquals(1, listener.getEventsHandled()); } @@ -36,6 +37,6 @@ public class GuavaEventBusTest { CustomEvent customEvent = new CustomEvent("Custom Event"); EventBusWrapper.post(customEvent); - assertEquals(1,listener.getEventsHandled()); + assertEquals(1, listener.getEventsHandled()); } } From d8efbb5c75f46c7cf147b824a5031462444febe8 Mon Sep 17 00:00:00 2001 From: Victor Mosin Date: Wed, 1 Feb 2017 20:45:21 +0100 Subject: [PATCH 17/25] Introduced new module due to BAEL-598 --- .../thrift/impl/CrossPlatformResource.java | 579 +++ .../thrift/impl/CrossPlatformService.java | 3745 +++++++++++++++++ .../impl/InvalidOperationException.java | 472 +++ apache-thrift/pom.xml | 55 + .../java/com/baeldung/thrift/Application.java | 9 + .../thrift/CrossPlatformServiceClient.java | 41 + .../thrift/CrossPlatformServiceImpl.java | 35 + .../thrift/CrossPlatformServiceServer.java | 39 + .../resources/cross-platform-service.thrift | 24 + .../thrift/CrossPlatformServiceTest.java | 33 + pom.xml | 1 + 11 files changed, 5033 insertions(+) create mode 100644 apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformResource.java create mode 100644 apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformService.java create mode 100644 apache-thrift/generated/com/baeldung/thrift/impl/InvalidOperationException.java create mode 100644 apache-thrift/pom.xml create mode 100644 apache-thrift/src/main/java/com/baeldung/thrift/Application.java create mode 100644 apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceClient.java create mode 100644 apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceImpl.java create mode 100644 apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java create mode 100644 apache-thrift/src/main/resources/cross-platform-service.thrift create mode 100644 apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java diff --git a/apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformResource.java b/apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformResource.java new file mode 100644 index 0000000000..6cb5af0695 --- /dev/null +++ b/apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformResource.java @@ -0,0 +1,579 @@ +/** + * Autogenerated by Thrift Compiler (0.10.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.baeldung.thrift.impl; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.10.0)", date = "2017-02-01") +public class CrossPlatformResource implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("CrossPlatformResource"); + + private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField SALUTATION_FIELD_DESC = new org.apache.thrift.protocol.TField("salutation", org.apache.thrift.protocol.TType.STRING, (short)3); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new CrossPlatformResourceStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new CrossPlatformResourceTupleSchemeFactory(); + + public int id; // required + public java.lang.String name; // required + public java.lang.String salutation; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ID((short)1, "id"), + NAME((short)2, "name"), + SALUTATION((short)3, "salutation"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // ID + return ID; + case 2: // NAME + return NAME; + case 3: // SALUTATION + return SALUTATION; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __ID_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.SALUTATION}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.NAME, new org.apache.thrift.meta_data.FieldMetaData("name", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.SALUTATION, new org.apache.thrift.meta_data.FieldMetaData("salutation", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(CrossPlatformResource.class, metaDataMap); + } + + public CrossPlatformResource() { + } + + public CrossPlatformResource( + int id, + java.lang.String name) + { + this(); + this.id = id; + setIdIsSet(true); + this.name = name; + } + + /** + * Performs a deep copy on other. + */ + public CrossPlatformResource(CrossPlatformResource other) { + __isset_bitfield = other.__isset_bitfield; + this.id = other.id; + if (other.isSetName()) { + this.name = other.name; + } + if (other.isSetSalutation()) { + this.salutation = other.salutation; + } + } + + public CrossPlatformResource deepCopy() { + return new CrossPlatformResource(this); + } + + @Override + public void clear() { + setIdIsSet(false); + this.id = 0; + this.name = null; + this.salutation = null; + } + + public int getId() { + return this.id; + } + + public CrossPlatformResource setId(int id) { + this.id = id; + setIdIsSet(true); + return this; + } + + public void unsetId() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __ID_ISSET_ID); + } + + /** Returns true if field id is set (has been assigned a value) and false otherwise */ + public boolean isSetId() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __ID_ISSET_ID); + } + + public void setIdIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __ID_ISSET_ID, value); + } + + public java.lang.String getName() { + return this.name; + } + + public CrossPlatformResource setName(java.lang.String name) { + this.name = name; + return this; + } + + public void unsetName() { + this.name = null; + } + + /** Returns true if field name is set (has been assigned a value) and false otherwise */ + public boolean isSetName() { + return this.name != null; + } + + public void setNameIsSet(boolean value) { + if (!value) { + this.name = null; + } + } + + public java.lang.String getSalutation() { + return this.salutation; + } + + public CrossPlatformResource setSalutation(java.lang.String salutation) { + this.salutation = salutation; + return this; + } + + public void unsetSalutation() { + this.salutation = null; + } + + /** Returns true if field salutation is set (has been assigned a value) and false otherwise */ + public boolean isSetSalutation() { + return this.salutation != null; + } + + public void setSalutationIsSet(boolean value) { + if (!value) { + this.salutation = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case ID: + if (value == null) { + unsetId(); + } else { + setId((java.lang.Integer)value); + } + break; + + case NAME: + if (value == null) { + unsetName(); + } else { + setName((java.lang.String)value); + } + break; + + case SALUTATION: + if (value == null) { + unsetSalutation(); + } else { + setSalutation((java.lang.String)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case ID: + return getId(); + + case NAME: + return getName(); + + case SALUTATION: + return getSalutation(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case ID: + return isSetId(); + case NAME: + return isSetName(); + case SALUTATION: + return isSetSalutation(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof CrossPlatformResource) + return this.equals((CrossPlatformResource)that); + return false; + } + + public boolean equals(CrossPlatformResource that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_id = true; + boolean that_present_id = true; + if (this_present_id || that_present_id) { + if (!(this_present_id && that_present_id)) + return false; + if (this.id != that.id) + return false; + } + + boolean this_present_name = true && this.isSetName(); + boolean that_present_name = true && that.isSetName(); + if (this_present_name || that_present_name) { + if (!(this_present_name && that_present_name)) + return false; + if (!this.name.equals(that.name)) + return false; + } + + boolean this_present_salutation = true && this.isSetSalutation(); + boolean that_present_salutation = true && that.isSetSalutation(); + if (this_present_salutation || that_present_salutation) { + if (!(this_present_salutation && that_present_salutation)) + return false; + if (!this.salutation.equals(that.salutation)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + id; + + hashCode = hashCode * 8191 + ((isSetName()) ? 131071 : 524287); + if (isSetName()) + hashCode = hashCode * 8191 + name.hashCode(); + + hashCode = hashCode * 8191 + ((isSetSalutation()) ? 131071 : 524287); + if (isSetSalutation()) + hashCode = hashCode * 8191 + salutation.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(CrossPlatformResource other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetId()).compareTo(other.isSetId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, other.id); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetName()).compareTo(other.isSetName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.name, other.name); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetSalutation()).compareTo(other.isSetSalutation()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSalutation()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.salutation, other.salutation); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("CrossPlatformResource("); + boolean first = true; + + sb.append("id:"); + sb.append(this.id); + first = false; + if (!first) sb.append(", "); + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + if (isSetSalutation()) { + if (!first) sb.append(", "); + sb.append("salutation:"); + if (this.salutation == null) { + sb.append("null"); + } else { + sb.append(this.salutation); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class CrossPlatformResourceStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public CrossPlatformResourceStandardScheme getScheme() { + return new CrossPlatformResourceStandardScheme(); + } + } + + private static class CrossPlatformResourceStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, CrossPlatformResource struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // ID + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.id = iprot.readI32(); + struct.setIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.name = iprot.readString(); + struct.setNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // SALUTATION + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.salutation = iprot.readString(); + struct.setSalutationIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, CrossPlatformResource struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(ID_FIELD_DESC); + oprot.writeI32(struct.id); + oprot.writeFieldEnd(); + if (struct.name != null) { + oprot.writeFieldBegin(NAME_FIELD_DESC); + oprot.writeString(struct.name); + oprot.writeFieldEnd(); + } + if (struct.salutation != null) { + if (struct.isSetSalutation()) { + oprot.writeFieldBegin(SALUTATION_FIELD_DESC); + oprot.writeString(struct.salutation); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class CrossPlatformResourceTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public CrossPlatformResourceTupleScheme getScheme() { + return new CrossPlatformResourceTupleScheme(); + } + } + + private static class CrossPlatformResourceTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, CrossPlatformResource struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetId()) { + optionals.set(0); + } + if (struct.isSetName()) { + optionals.set(1); + } + if (struct.isSetSalutation()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetId()) { + oprot.writeI32(struct.id); + } + if (struct.isSetName()) { + oprot.writeString(struct.name); + } + if (struct.isSetSalutation()) { + oprot.writeString(struct.salutation); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, CrossPlatformResource struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.id = iprot.readI32(); + struct.setIdIsSet(true); + } + if (incoming.get(1)) { + struct.name = iprot.readString(); + struct.setNameIsSet(true); + } + if (incoming.get(2)) { + struct.salutation = iprot.readString(); + struct.setSalutationIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformService.java b/apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformService.java new file mode 100644 index 0000000000..4e4537f7b6 --- /dev/null +++ b/apache-thrift/generated/com/baeldung/thrift/impl/CrossPlatformService.java @@ -0,0 +1,3745 @@ +/** + * Autogenerated by Thrift Compiler (0.10.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.baeldung.thrift.impl; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.10.0)", date = "2017-02-01") +public class CrossPlatformService { + + public interface Iface { + + public CrossPlatformResource get(int id) throws InvalidOperationException, org.apache.thrift.TException; + + public void save(CrossPlatformResource resource) throws InvalidOperationException, org.apache.thrift.TException; + + public java.util.List getList() throws InvalidOperationException, org.apache.thrift.TException; + + public boolean ping() throws InvalidOperationException, org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void get(int id, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void save(CrossPlatformResource resource, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void getList(org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException; + + public void ping(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + } + + public static class Client extends org.apache.thrift.TServiceClient implements Iface { + public static class Factory implements org.apache.thrift.TServiceClientFactory { + public Factory() {} + public Client getClient(org.apache.thrift.protocol.TProtocol prot) { + return new Client(prot); + } + public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + return new Client(iprot, oprot); + } + } + + public Client(org.apache.thrift.protocol.TProtocol prot) + { + super(prot, prot); + } + + public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + super(iprot, oprot); + } + + public CrossPlatformResource get(int id) throws InvalidOperationException, org.apache.thrift.TException + { + send_get(id); + return recv_get(); + } + + public void send_get(int id) throws org.apache.thrift.TException + { + get_args args = new get_args(); + args.setId(id); + sendBase("get", args); + } + + public CrossPlatformResource recv_get() throws InvalidOperationException, org.apache.thrift.TException + { + get_result result = new get_result(); + receiveBase(result, "get"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.e != null) { + throw result.e; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "get failed: unknown result"); + } + + public void save(CrossPlatformResource resource) throws InvalidOperationException, org.apache.thrift.TException + { + send_save(resource); + recv_save(); + } + + public void send_save(CrossPlatformResource resource) throws org.apache.thrift.TException + { + save_args args = new save_args(); + args.setResource(resource); + sendBase("save", args); + } + + public void recv_save() throws InvalidOperationException, org.apache.thrift.TException + { + save_result result = new save_result(); + receiveBase(result, "save"); + if (result.e != null) { + throw result.e; + } + return; + } + + public java.util.List getList() throws InvalidOperationException, org.apache.thrift.TException + { + send_getList(); + return recv_getList(); + } + + public void send_getList() throws org.apache.thrift.TException + { + getList_args args = new getList_args(); + sendBase("getList", args); + } + + public java.util.List recv_getList() throws InvalidOperationException, org.apache.thrift.TException + { + getList_result result = new getList_result(); + receiveBase(result, "getList"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.e != null) { + throw result.e; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getList failed: unknown result"); + } + + public boolean ping() throws InvalidOperationException, org.apache.thrift.TException + { + send_ping(); + return recv_ping(); + } + + public void send_ping() throws org.apache.thrift.TException + { + ping_args args = new ping_args(); + sendBase("ping", args); + } + + public boolean recv_ping() throws InvalidOperationException, org.apache.thrift.TException + { + ping_result result = new ping_result(); + receiveBase(result, "ping"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.e != null) { + throw result.e; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "ping failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + private org.apache.thrift.async.TAsyncClientManager clientManager; + private org.apache.thrift.protocol.TProtocolFactory protocolFactory; + public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { + this.clientManager = clientManager; + this.protocolFactory = protocolFactory; + } + public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { + return new AsyncClient(protocolFactory, clientManager, transport); + } + } + + public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { + super(protocolFactory, clientManager, transport); + } + + public void get(int id, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + get_call method_call = new get_call(id, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class get_call extends org.apache.thrift.async.TAsyncMethodCall { + private int id; + public get_call(int id, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.id = id; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("get", org.apache.thrift.protocol.TMessageType.CALL, 0)); + get_args args = new get_args(); + args.setId(id); + args.write(prot); + prot.writeMessageEnd(); + } + + public CrossPlatformResource getResult() throws InvalidOperationException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_get(); + } + } + + public void save(CrossPlatformResource resource, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + save_call method_call = new save_call(resource, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class save_call extends org.apache.thrift.async.TAsyncMethodCall { + private CrossPlatformResource resource; + public save_call(CrossPlatformResource resource, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.resource = resource; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("save", org.apache.thrift.protocol.TMessageType.CALL, 0)); + save_args args = new save_args(); + args.setResource(resource); + args.write(prot); + prot.writeMessageEnd(); + } + + public Void getResult() throws InvalidOperationException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return null; + } + } + + public void getList(org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + checkReady(); + getList_call method_call = new getList_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class getList_call extends org.apache.thrift.async.TAsyncMethodCall> { + public getList_call(org.apache.thrift.async.AsyncMethodCallback> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getList", org.apache.thrift.protocol.TMessageType.CALL, 0)); + getList_args args = new getList_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.util.List getResult() throws InvalidOperationException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_getList(); + } + } + + public void ping(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + ping_call method_call = new ping_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class ping_call extends org.apache.thrift.async.TAsyncMethodCall { + public ping_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("ping", org.apache.thrift.protocol.TMessageType.CALL, 0)); + ping_args args = new ping_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.lang.Boolean getResult() throws InvalidOperationException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_ping(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("get", new get()); + processMap.put("save", new save()); + processMap.put("getList", new getList()); + processMap.put("ping", new ping()); + return processMap; + } + + public static class get extends org.apache.thrift.ProcessFunction { + public get() { + super("get"); + } + + public get_args getEmptyArgsInstance() { + return new get_args(); + } + + protected boolean isOneway() { + return false; + } + + public get_result getResult(I iface, get_args args) throws org.apache.thrift.TException { + get_result result = new get_result(); + try { + result.success = iface.get(args.id); + } catch (InvalidOperationException e) { + result.e = e; + } + return result; + } + } + + public static class save extends org.apache.thrift.ProcessFunction { + public save() { + super("save"); + } + + public save_args getEmptyArgsInstance() { + return new save_args(); + } + + protected boolean isOneway() { + return false; + } + + public save_result getResult(I iface, save_args args) throws org.apache.thrift.TException { + save_result result = new save_result(); + try { + iface.save(args.resource); + } catch (InvalidOperationException e) { + result.e = e; + } + return result; + } + } + + public static class getList extends org.apache.thrift.ProcessFunction { + public getList() { + super("getList"); + } + + public getList_args getEmptyArgsInstance() { + return new getList_args(); + } + + protected boolean isOneway() { + return false; + } + + public getList_result getResult(I iface, getList_args args) throws org.apache.thrift.TException { + getList_result result = new getList_result(); + try { + result.success = iface.getList(); + } catch (InvalidOperationException e) { + result.e = e; + } + return result; + } + } + + public static class ping extends org.apache.thrift.ProcessFunction { + public ping() { + super("ping"); + } + + public ping_args getEmptyArgsInstance() { + return new ping_args(); + } + + protected boolean isOneway() { + return false; + } + + public ping_result getResult(I iface, ping_args args) throws org.apache.thrift.TException { + ping_result result = new ping_result(); + try { + result.success = iface.ping(); + result.setSuccessIsSet(true); + } catch (InvalidOperationException e) { + result.e = e; + } + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("get", new get()); + processMap.put("save", new save()); + processMap.put("getList", new getList()); + processMap.put("ping", new ping()); + return processMap; + } + + public static class get extends org.apache.thrift.AsyncProcessFunction { + public get() { + super("get"); + } + + public get_args getEmptyArgsInstance() { + return new get_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(CrossPlatformResource o) { + get_result result = new get_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + get_result result = new get_result(); + if (e instanceof InvalidOperationException) { + result.e = (InvalidOperationException) e; + result.setEIsSet(true); + msg = result; + } else if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, get_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.get(args.id,resultHandler); + } + } + + public static class save extends org.apache.thrift.AsyncProcessFunction { + public save() { + super("save"); + } + + public save_args getEmptyArgsInstance() { + return new save_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(Void o) { + save_result result = new save_result(); + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + save_result result = new save_result(); + if (e instanceof InvalidOperationException) { + result.e = (InvalidOperationException) e; + result.setEIsSet(true); + msg = result; + } else if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, save_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.save(args.resource,resultHandler); + } + } + + public static class getList extends org.apache.thrift.AsyncProcessFunction> { + public getList() { + super("getList"); + } + + public getList_args getEmptyArgsInstance() { + return new getList_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback>() { + public void onComplete(java.util.List o) { + getList_result result = new getList_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + getList_result result = new getList_result(); + if (e instanceof InvalidOperationException) { + result.e = (InvalidOperationException) e; + result.setEIsSet(true); + msg = result; + } else if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, getList_args args, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + iface.getList(resultHandler); + } + } + + public static class ping extends org.apache.thrift.AsyncProcessFunction { + public ping() { + super("ping"); + } + + public ping_args getEmptyArgsInstance() { + return new ping_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(java.lang.Boolean o) { + ping_result result = new ping_result(); + result.success = o; + result.setSuccessIsSet(true); + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + ping_result result = new ping_result(); + if (e instanceof InvalidOperationException) { + result.e = (InvalidOperationException) e; + result.setEIsSet(true); + msg = result; + } else if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, ping_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.ping(resultHandler); + } + } + + } + + public static class get_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("get_args"); + + private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I32, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new get_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new get_argsTupleSchemeFactory(); + + public int id; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ID((short)1, "id"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // ID + return ID; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __ID_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(get_args.class, metaDataMap); + } + + public get_args() { + } + + public get_args( + int id) + { + this(); + this.id = id; + setIdIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public get_args(get_args other) { + __isset_bitfield = other.__isset_bitfield; + this.id = other.id; + } + + public get_args deepCopy() { + return new get_args(this); + } + + @Override + public void clear() { + setIdIsSet(false); + this.id = 0; + } + + public int getId() { + return this.id; + } + + public get_args setId(int id) { + this.id = id; + setIdIsSet(true); + return this; + } + + public void unsetId() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __ID_ISSET_ID); + } + + /** Returns true if field id is set (has been assigned a value) and false otherwise */ + public boolean isSetId() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __ID_ISSET_ID); + } + + public void setIdIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __ID_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case ID: + if (value == null) { + unsetId(); + } else { + setId((java.lang.Integer)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case ID: + return getId(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case ID: + return isSetId(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof get_args) + return this.equals((get_args)that); + return false; + } + + public boolean equals(get_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_id = true; + boolean that_present_id = true; + if (this_present_id || that_present_id) { + if (!(this_present_id && that_present_id)) + return false; + if (this.id != that.id) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + id; + + return hashCode; + } + + @Override + public int compareTo(get_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetId()).compareTo(other.isSetId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, other.id); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("get_args("); + boolean first = true; + + sb.append("id:"); + sb.append(this.id); + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class get_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public get_argsStandardScheme getScheme() { + return new get_argsStandardScheme(); + } + } + + private static class get_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, get_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // ID + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.id = iprot.readI32(); + struct.setIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, get_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(ID_FIELD_DESC); + oprot.writeI32(struct.id); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class get_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public get_argsTupleScheme getScheme() { + return new get_argsTupleScheme(); + } + } + + private static class get_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, get_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetId()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetId()) { + oprot.writeI32(struct.id); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, get_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.id = iprot.readI32(); + struct.setIdIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class get_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("get_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + private static final org.apache.thrift.protocol.TField E_FIELD_DESC = new org.apache.thrift.protocol.TField("e", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new get_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new get_resultTupleSchemeFactory(); + + public CrossPlatformResource success; // required + public InvalidOperationException e; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + E((short)1, "e"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // E + return E; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CrossPlatformResource.class))); + tmpMap.put(_Fields.E, new org.apache.thrift.meta_data.FieldMetaData("e", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, InvalidOperationException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(get_result.class, metaDataMap); + } + + public get_result() { + } + + public get_result( + CrossPlatformResource success, + InvalidOperationException e) + { + this(); + this.success = success; + this.e = e; + } + + /** + * Performs a deep copy on other. + */ + public get_result(get_result other) { + if (other.isSetSuccess()) { + this.success = new CrossPlatformResource(other.success); + } + if (other.isSetE()) { + this.e = new InvalidOperationException(other.e); + } + } + + public get_result deepCopy() { + return new get_result(this); + } + + @Override + public void clear() { + this.success = null; + this.e = null; + } + + public CrossPlatformResource getSuccess() { + return this.success; + } + + public get_result setSuccess(CrossPlatformResource success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public InvalidOperationException getE() { + return this.e; + } + + public get_result setE(InvalidOperationException e) { + this.e = e; + return this; + } + + public void unsetE() { + this.e = null; + } + + /** Returns true if field e is set (has been assigned a value) and false otherwise */ + public boolean isSetE() { + return this.e != null; + } + + public void setEIsSet(boolean value) { + if (!value) { + this.e = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((CrossPlatformResource)value); + } + break; + + case E: + if (value == null) { + unsetE(); + } else { + setE((InvalidOperationException)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case E: + return getE(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case E: + return isSetE(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof get_result) + return this.equals((get_result)that); + return false; + } + + public boolean equals(get_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_e = true && this.isSetE(); + boolean that_present_e = true && that.isSetE(); + if (this_present_e || that_present_e) { + if (!(this_present_e && that_present_e)) + return false; + if (!this.e.equals(that.e)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + hashCode = hashCode * 8191 + ((isSetE()) ? 131071 : 524287); + if (isSetE()) + hashCode = hashCode * 8191 + e.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(get_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetE()).compareTo(other.isSetE()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetE()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.e, other.e); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("get_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("e:"); + if (this.e == null) { + sb.append("null"); + } else { + sb.append(this.e); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class get_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public get_resultStandardScheme getScheme() { + return new get_resultStandardScheme(); + } + } + + private static class get_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, get_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new CrossPlatformResource(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // E + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, get_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.e != null) { + oprot.writeFieldBegin(E_FIELD_DESC); + struct.e.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class get_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public get_resultTupleScheme getScheme() { + return new get_resultTupleScheme(); + } + } + + private static class get_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, get_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetE()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + if (struct.isSetE()) { + struct.e.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, get_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = new CrossPlatformResource(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class save_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("save_args"); + + private static final org.apache.thrift.protocol.TField RESOURCE_FIELD_DESC = new org.apache.thrift.protocol.TField("resource", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new save_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new save_argsTupleSchemeFactory(); + + public CrossPlatformResource resource; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + RESOURCE((short)1, "resource"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // RESOURCE + return RESOURCE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.RESOURCE, new org.apache.thrift.meta_data.FieldMetaData("resource", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CrossPlatformResource.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(save_args.class, metaDataMap); + } + + public save_args() { + } + + public save_args( + CrossPlatformResource resource) + { + this(); + this.resource = resource; + } + + /** + * Performs a deep copy on other. + */ + public save_args(save_args other) { + if (other.isSetResource()) { + this.resource = new CrossPlatformResource(other.resource); + } + } + + public save_args deepCopy() { + return new save_args(this); + } + + @Override + public void clear() { + this.resource = null; + } + + public CrossPlatformResource getResource() { + return this.resource; + } + + public save_args setResource(CrossPlatformResource resource) { + this.resource = resource; + return this; + } + + public void unsetResource() { + this.resource = null; + } + + /** Returns true if field resource is set (has been assigned a value) and false otherwise */ + public boolean isSetResource() { + return this.resource != null; + } + + public void setResourceIsSet(boolean value) { + if (!value) { + this.resource = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case RESOURCE: + if (value == null) { + unsetResource(); + } else { + setResource((CrossPlatformResource)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case RESOURCE: + return getResource(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case RESOURCE: + return isSetResource(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof save_args) + return this.equals((save_args)that); + return false; + } + + public boolean equals(save_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_resource = true && this.isSetResource(); + boolean that_present_resource = true && that.isSetResource(); + if (this_present_resource || that_present_resource) { + if (!(this_present_resource && that_present_resource)) + return false; + if (!this.resource.equals(that.resource)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetResource()) ? 131071 : 524287); + if (isSetResource()) + hashCode = hashCode * 8191 + resource.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(save_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetResource()).compareTo(other.isSetResource()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetResource()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.resource, other.resource); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("save_args("); + boolean first = true; + + sb.append("resource:"); + if (this.resource == null) { + sb.append("null"); + } else { + sb.append(this.resource); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (resource != null) { + resource.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class save_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_argsStandardScheme getScheme() { + return new save_argsStandardScheme(); + } + } + + private static class save_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, save_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // RESOURCE + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.resource = new CrossPlatformResource(); + struct.resource.read(iprot); + struct.setResourceIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, save_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.resource != null) { + oprot.writeFieldBegin(RESOURCE_FIELD_DESC); + struct.resource.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class save_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_argsTupleScheme getScheme() { + return new save_argsTupleScheme(); + } + } + + private static class save_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, save_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetResource()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetResource()) { + struct.resource.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, save_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.resource = new CrossPlatformResource(); + struct.resource.read(iprot); + struct.setResourceIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class save_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("save_result"); + + private static final org.apache.thrift.protocol.TField E_FIELD_DESC = new org.apache.thrift.protocol.TField("e", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new save_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new save_resultTupleSchemeFactory(); + + public InvalidOperationException e; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + E((short)1, "e"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // E + return E; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.E, new org.apache.thrift.meta_data.FieldMetaData("e", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, InvalidOperationException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(save_result.class, metaDataMap); + } + + public save_result() { + } + + public save_result( + InvalidOperationException e) + { + this(); + this.e = e; + } + + /** + * Performs a deep copy on other. + */ + public save_result(save_result other) { + if (other.isSetE()) { + this.e = new InvalidOperationException(other.e); + } + } + + public save_result deepCopy() { + return new save_result(this); + } + + @Override + public void clear() { + this.e = null; + } + + public InvalidOperationException getE() { + return this.e; + } + + public save_result setE(InvalidOperationException e) { + this.e = e; + return this; + } + + public void unsetE() { + this.e = null; + } + + /** Returns true if field e is set (has been assigned a value) and false otherwise */ + public boolean isSetE() { + return this.e != null; + } + + public void setEIsSet(boolean value) { + if (!value) { + this.e = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case E: + if (value == null) { + unsetE(); + } else { + setE((InvalidOperationException)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case E: + return getE(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case E: + return isSetE(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof save_result) + return this.equals((save_result)that); + return false; + } + + public boolean equals(save_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_e = true && this.isSetE(); + boolean that_present_e = true && that.isSetE(); + if (this_present_e || that_present_e) { + if (!(this_present_e && that_present_e)) + return false; + if (!this.e.equals(that.e)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetE()) ? 131071 : 524287); + if (isSetE()) + hashCode = hashCode * 8191 + e.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(save_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetE()).compareTo(other.isSetE()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetE()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.e, other.e); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("save_result("); + boolean first = true; + + sb.append("e:"); + if (this.e == null) { + sb.append("null"); + } else { + sb.append(this.e); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class save_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_resultStandardScheme getScheme() { + return new save_resultStandardScheme(); + } + } + + private static class save_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, save_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // E + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, save_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.e != null) { + oprot.writeFieldBegin(E_FIELD_DESC); + struct.e.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class save_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_resultTupleScheme getScheme() { + return new save_resultTupleScheme(); + } + } + + private static class save_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, save_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetE()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetE()) { + struct.e.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, save_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class getList_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getList_args"); + + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new getList_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new getList_argsTupleSchemeFactory(); + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getList_args.class, metaDataMap); + } + + public getList_args() { + } + + /** + * Performs a deep copy on other. + */ + public getList_args(getList_args other) { + } + + public getList_args deepCopy() { + return new getList_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof getList_args) + return this.equals((getList_args)that); + return false; + } + + public boolean equals(getList_args that) { + if (that == null) + return false; + if (this == that) + return true; + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + return hashCode; + } + + @Override + public int compareTo(getList_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("getList_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getList_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public getList_argsStandardScheme getScheme() { + return new getList_argsStandardScheme(); + } + } + + private static class getList_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getList_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getList_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getList_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public getList_argsTupleScheme getScheme() { + return new getList_argsTupleScheme(); + } + } + + private static class getList_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getList_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getList_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class getList_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getList_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0); + private static final org.apache.thrift.protocol.TField E_FIELD_DESC = new org.apache.thrift.protocol.TField("e", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new getList_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new getList_resultTupleSchemeFactory(); + + public java.util.List success; // required + public InvalidOperationException e; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + E((short)1, "e"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // E + return E; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CrossPlatformResource.class)))); + tmpMap.put(_Fields.E, new org.apache.thrift.meta_data.FieldMetaData("e", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, InvalidOperationException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getList_result.class, metaDataMap); + } + + public getList_result() { + } + + public getList_result( + java.util.List success, + InvalidOperationException e) + { + this(); + this.success = success; + this.e = e; + } + + /** + * Performs a deep copy on other. + */ + public getList_result(getList_result other) { + if (other.isSetSuccess()) { + java.util.List __this__success = new java.util.ArrayList(other.success.size()); + for (CrossPlatformResource other_element : other.success) { + __this__success.add(new CrossPlatformResource(other_element)); + } + this.success = __this__success; + } + if (other.isSetE()) { + this.e = new InvalidOperationException(other.e); + } + } + + public getList_result deepCopy() { + return new getList_result(this); + } + + @Override + public void clear() { + this.success = null; + this.e = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(CrossPlatformResource elem) { + if (this.success == null) { + this.success = new java.util.ArrayList(); + } + this.success.add(elem); + } + + public java.util.List getSuccess() { + return this.success; + } + + public getList_result setSuccess(java.util.List success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public InvalidOperationException getE() { + return this.e; + } + + public getList_result setE(InvalidOperationException e) { + this.e = e; + return this; + } + + public void unsetE() { + this.e = null; + } + + /** Returns true if field e is set (has been assigned a value) and false otherwise */ + public boolean isSetE() { + return this.e != null; + } + + public void setEIsSet(boolean value) { + if (!value) { + this.e = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.util.List)value); + } + break; + + case E: + if (value == null) { + unsetE(); + } else { + setE((InvalidOperationException)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case E: + return getE(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case E: + return isSetE(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof getList_result) + return this.equals((getList_result)that); + return false; + } + + public boolean equals(getList_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_e = true && this.isSetE(); + boolean that_present_e = true && that.isSetE(); + if (this_present_e || that_present_e) { + if (!(this_present_e && that_present_e)) + return false; + if (!this.e.equals(that.e)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + hashCode = hashCode * 8191 + ((isSetE()) ? 131071 : 524287); + if (isSetE()) + hashCode = hashCode * 8191 + e.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(getList_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetE()).compareTo(other.isSetE()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetE()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.e, other.e); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("getList_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("e:"); + if (this.e == null) { + sb.append("null"); + } else { + sb.append(this.e); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getList_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public getList_resultStandardScheme getScheme() { + return new getList_resultStandardScheme(); + } + } + + private static class getList_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getList_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list0 = iprot.readListBegin(); + struct.success = new java.util.ArrayList(_list0.size); + CrossPlatformResource _elem1; + for (int _i2 = 0; _i2 < _list0.size; ++_i2) + { + _elem1 = new CrossPlatformResource(); + _elem1.read(iprot); + struct.success.add(_elem1); + } + iprot.readListEnd(); + } + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // E + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getList_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.success.size())); + for (CrossPlatformResource _iter3 : struct.success) + { + _iter3.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + if (struct.e != null) { + oprot.writeFieldBegin(E_FIELD_DESC); + struct.e.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getList_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public getList_resultTupleScheme getScheme() { + return new getList_resultTupleScheme(); + } + } + + private static class getList_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getList_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetE()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (CrossPlatformResource _iter4 : struct.success) + { + _iter4.write(oprot); + } + } + } + if (struct.isSetE()) { + struct.e.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getList_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list5 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.success = new java.util.ArrayList(_list5.size); + CrossPlatformResource _elem6; + for (int _i7 = 0; _i7 < _list5.size; ++_i7) + { + _elem6 = new CrossPlatformResource(); + _elem6.read(iprot); + struct.success.add(_elem6); + } + } + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class ping_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ping_args"); + + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new ping_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new ping_argsTupleSchemeFactory(); + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ping_args.class, metaDataMap); + } + + public ping_args() { + } + + /** + * Performs a deep copy on other. + */ + public ping_args(ping_args other) { + } + + public ping_args deepCopy() { + return new ping_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof ping_args) + return this.equals((ping_args)that); + return false; + } + + public boolean equals(ping_args that) { + if (that == null) + return false; + if (this == that) + return true; + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + return hashCode; + } + + @Override + public int compareTo(ping_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("ping_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class ping_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public ping_argsStandardScheme getScheme() { + return new ping_argsStandardScheme(); + } + } + + private static class ping_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, ping_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, ping_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class ping_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public ping_argsTupleScheme getScheme() { + return new ping_argsTupleScheme(); + } + } + + private static class ping_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, ping_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, ping_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class ping_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ping_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.BOOL, (short)0); + private static final org.apache.thrift.protocol.TField E_FIELD_DESC = new org.apache.thrift.protocol.TField("e", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new ping_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new ping_resultTupleSchemeFactory(); + + public boolean success; // required + public InvalidOperationException e; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + E((short)1, "e"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // E + return E; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __SUCCESS_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); + tmpMap.put(_Fields.E, new org.apache.thrift.meta_data.FieldMetaData("e", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, InvalidOperationException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ping_result.class, metaDataMap); + } + + public ping_result() { + } + + public ping_result( + boolean success, + InvalidOperationException e) + { + this(); + this.success = success; + setSuccessIsSet(true); + this.e = e; + } + + /** + * Performs a deep copy on other. + */ + public ping_result(ping_result other) { + __isset_bitfield = other.__isset_bitfield; + this.success = other.success; + if (other.isSetE()) { + this.e = new InvalidOperationException(other.e); + } + } + + public ping_result deepCopy() { + return new ping_result(this); + } + + @Override + public void clear() { + setSuccessIsSet(false); + this.success = false; + this.e = null; + } + + public boolean isSuccess() { + return this.success; + } + + public ping_result setSuccess(boolean success) { + this.success = success; + setSuccessIsSet(true); + return this; + } + + public void unsetSuccess() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SUCCESS_ISSET_ID); + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SUCCESS_ISSET_ID); + } + + public void setSuccessIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SUCCESS_ISSET_ID, value); + } + + public InvalidOperationException getE() { + return this.e; + } + + public ping_result setE(InvalidOperationException e) { + this.e = e; + return this; + } + + public void unsetE() { + this.e = null; + } + + /** Returns true if field e is set (has been assigned a value) and false otherwise */ + public boolean isSetE() { + return this.e != null; + } + + public void setEIsSet(boolean value) { + if (!value) { + this.e = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.lang.Boolean)value); + } + break; + + case E: + if (value == null) { + unsetE(); + } else { + setE((InvalidOperationException)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return isSuccess(); + + case E: + return getE(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case E: + return isSetE(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof ping_result) + return this.equals((ping_result)that); + return false; + } + + public boolean equals(ping_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true; + boolean that_present_success = true; + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (this.success != that.success) + return false; + } + + boolean this_present_e = true && this.isSetE(); + boolean that_present_e = true && that.isSetE(); + if (this_present_e || that_present_e) { + if (!(this_present_e && that_present_e)) + return false; + if (!this.e.equals(that.e)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((success) ? 131071 : 524287); + + hashCode = hashCode * 8191 + ((isSetE()) ? 131071 : 524287); + if (isSetE()) + hashCode = hashCode * 8191 + e.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(ping_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetE()).compareTo(other.isSetE()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetE()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.e, other.e); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("ping_result("); + boolean first = true; + + sb.append("success:"); + sb.append(this.success); + first = false; + if (!first) sb.append(", "); + sb.append("e:"); + if (this.e == null) { + sb.append("null"); + } else { + sb.append(this.e); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class ping_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public ping_resultStandardScheme getScheme() { + return new ping_resultStandardScheme(); + } + } + + private static class ping_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, ping_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) { + struct.success = iprot.readBool(); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // E + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, ping_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetSuccess()) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeBool(struct.success); + oprot.writeFieldEnd(); + } + if (struct.e != null) { + oprot.writeFieldBegin(E_FIELD_DESC); + struct.e.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class ping_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public ping_resultTupleScheme getScheme() { + return new ping_resultTupleScheme(); + } + } + + private static class ping_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, ping_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetE()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + oprot.writeBool(struct.success); + } + if (struct.isSetE()) { + struct.e.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, ping_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = iprot.readBool(); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.e = new InvalidOperationException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/apache-thrift/generated/com/baeldung/thrift/impl/InvalidOperationException.java b/apache-thrift/generated/com/baeldung/thrift/impl/InvalidOperationException.java new file mode 100644 index 0000000000..c07616a00e --- /dev/null +++ b/apache-thrift/generated/com/baeldung/thrift/impl/InvalidOperationException.java @@ -0,0 +1,472 @@ +/** + * Autogenerated by Thrift Compiler (0.10.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.baeldung.thrift.impl; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.10.0)", date = "2017-02-01") +public class InvalidOperationException extends org.apache.thrift.TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("InvalidOperationException"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField DESCRIPTION_FIELD_DESC = new org.apache.thrift.protocol.TField("description", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new InvalidOperationExceptionStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new InvalidOperationExceptionTupleSchemeFactory(); + + public int code; // required + public java.lang.String description; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + CODE((short)1, "code"), + DESCRIPTION((short)2, "description"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case 2: // DESCRIPTION + return DESCRIPTION; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __CODE_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.DESCRIPTION, new org.apache.thrift.meta_data.FieldMetaData("description", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(InvalidOperationException.class, metaDataMap); + } + + public InvalidOperationException() { + } + + public InvalidOperationException( + int code, + java.lang.String description) + { + this(); + this.code = code; + setCodeIsSet(true); + this.description = description; + } + + /** + * Performs a deep copy on other. + */ + public InvalidOperationException(InvalidOperationException other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + if (other.isSetDescription()) { + this.description = other.description; + } + } + + public InvalidOperationException deepCopy() { + return new InvalidOperationException(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + this.description = null; + } + + public int getCode() { + return this.code; + } + + public InvalidOperationException setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public java.lang.String getDescription() { + return this.description; + } + + public InvalidOperationException setDescription(java.lang.String description) { + this.description = description; + return this; + } + + public void unsetDescription() { + this.description = null; + } + + /** Returns true if field description is set (has been assigned a value) and false otherwise */ + public boolean isSetDescription() { + return this.description != null; + } + + public void setDescriptionIsSet(boolean value) { + if (!value) { + this.description = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((java.lang.Integer)value); + } + break; + + case DESCRIPTION: + if (value == null) { + unsetDescription(); + } else { + setDescription((java.lang.String)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case DESCRIPTION: + return getDescription(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case CODE: + return isSetCode(); + case DESCRIPTION: + return isSetDescription(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof InvalidOperationException) + return this.equals((InvalidOperationException)that); + return false; + } + + public boolean equals(InvalidOperationException that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_description = true && this.isSetDescription(); + boolean that_present_description = true && that.isSetDescription(); + if (this_present_description || that_present_description) { + if (!(this_present_description && that_present_description)) + return false; + if (!this.description.equals(that.description)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + code; + + hashCode = hashCode * 8191 + ((isSetDescription()) ? 131071 : 524287); + if (isSetDescription()) + hashCode = hashCode * 8191 + description.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(InvalidOperationException other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetCode()).compareTo(other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetDescription()).compareTo(other.isSetDescription()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetDescription()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.description, other.description); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("InvalidOperationException("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("description:"); + if (this.description == null) { + sb.append("null"); + } else { + sb.append(this.description); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class InvalidOperationExceptionStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public InvalidOperationExceptionStandardScheme getScheme() { + return new InvalidOperationExceptionStandardScheme(); + } + } + + private static class InvalidOperationExceptionStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, InvalidOperationException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // DESCRIPTION + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.description = iprot.readString(); + struct.setDescriptionIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, InvalidOperationException struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(CODE_FIELD_DESC); + oprot.writeI32(struct.code); + oprot.writeFieldEnd(); + if (struct.description != null) { + oprot.writeFieldBegin(DESCRIPTION_FIELD_DESC); + oprot.writeString(struct.description); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class InvalidOperationExceptionTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public InvalidOperationExceptionTupleScheme getScheme() { + return new InvalidOperationExceptionTupleScheme(); + } + } + + private static class InvalidOperationExceptionTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, InvalidOperationException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetDescription()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetCode()) { + oprot.writeI32(struct.code); + } + if (struct.isSetDescription()) { + oprot.writeString(struct.description); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, InvalidOperationException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.description = iprot.readString(); + struct.setDescriptionIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/apache-thrift/pom.xml b/apache-thrift/pom.xml new file mode 100644 index 0000000000..e110bfb817 --- /dev/null +++ b/apache-thrift/pom.xml @@ -0,0 +1,55 @@ + + 4.0.0 + com.baeldung + apache-thrift + 0.0.1-SNAPSHOT + pom + + + 1.8 + 4.12 + 3.6.0 + 0.10.0 + 0.1.11 + + + + + org.apache.thrift + libthrift + ${thrift.version} + + + + junit + junit + ${junit.version} + test + + + + org.slf4j + slf4j-simple + 1.7.12 + test + + + + + install + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + diff --git a/apache-thrift/src/main/java/com/baeldung/thrift/Application.java b/apache-thrift/src/main/java/com/baeldung/thrift/Application.java new file mode 100644 index 0000000000..09d5cc74f3 --- /dev/null +++ b/apache-thrift/src/main/java/com/baeldung/thrift/Application.java @@ -0,0 +1,9 @@ +package com.baeldung.thrift; + +public class Application { + + public static void main(String[] args) { + CrossPlatformServiceServer server = new CrossPlatformServiceServer(); + server.start(); + } +} diff --git a/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceClient.java b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceClient.java new file mode 100644 index 0000000000..8c369acccb --- /dev/null +++ b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceClient.java @@ -0,0 +1,41 @@ +package com.baeldung.thrift; + +import com.baeldung.thrift.impl.CrossPlatformService; + +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + +public class CrossPlatformServiceClient { + + public boolean ping() { + try { + TTransport transport; + + transport = new TSocket("localhost", 9090); + transport.open(); + + TProtocol protocol = new TBinaryProtocol(transport); + CrossPlatformService.Client client = new CrossPlatformService.Client(protocol); + + System.out.print("Calling remote method..."); + + boolean result = client.ping(); + + System.out.println("done."); + + transport.close(); + + return result; + } catch (TTransportException e) { + e.printStackTrace(); + } catch (TException x) { + x.printStackTrace(); + } + + return false; + } +} diff --git a/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceImpl.java b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceImpl.java new file mode 100644 index 0000000000..008fc05ee7 --- /dev/null +++ b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceImpl.java @@ -0,0 +1,35 @@ +package com.baeldung.thrift; + +import com.baeldung.thrift.impl.CrossPlatformResource; +import com.baeldung.thrift.impl.CrossPlatformService; +import com.baeldung.thrift.impl.InvalidOperationException; + +import org.apache.thrift.TException; + +import java.util.Collections; +import java.util.List; + +public class CrossPlatformServiceImpl implements CrossPlatformService.Iface { + + @Override + public CrossPlatformResource get(final int id) throws InvalidOperationException, TException { + // add some action + return new CrossPlatformResource(); + } + + @Override + public void save(final CrossPlatformResource resource) throws InvalidOperationException, TException { + // add some action + } + + @Override + public List getList() throws InvalidOperationException, TException { + // add some action + return Collections.emptyList(); + } + + @Override + public boolean ping() throws InvalidOperationException, TException { + return true; + } +} diff --git a/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java new file mode 100644 index 0000000000..9a21512b52 --- /dev/null +++ b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java @@ -0,0 +1,39 @@ +package com.baeldung.thrift; + +import com.baeldung.thrift.impl.CrossPlatformService; + +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TSimpleServer; +import org.apache.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TServerTransport; + +public class CrossPlatformServiceServer { + + private TServer server; + + public void start() { + try { + TServerTransport serverTransport = new TServerSocket(9090); + server = new TSimpleServer(new TServer.Args(serverTransport) + .processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl()))); + + System.out.print("Starting the server... "); + + server.serve(); + + System.out.println("done."); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void stop() { + if (server != null && server.isServing()) { + System.out.print("Stopping the server... "); + + server.stop(); + + System.out.println("done."); + } + } +} diff --git a/apache-thrift/src/main/resources/cross-platform-service.thrift b/apache-thrift/src/main/resources/cross-platform-service.thrift new file mode 100644 index 0000000000..d6d3c51e18 --- /dev/null +++ b/apache-thrift/src/main/resources/cross-platform-service.thrift @@ -0,0 +1,24 @@ +namespace cpp com.baeldung.thrift.impl +namespace java com.baeldung.thrift.impl + +exception InvalidOperationException { + 1: i32 code, + 2: string description +} + +struct CrossPlatformResource { + 1: i32 id, + 2: string name, + 3: optional string salutation +} + +service CrossPlatformService { + + CrossPlatformResource get(1:i32 id) throws (1:InvalidOperationException e), + + void save(1:CrossPlatformResource resource) throws (1:InvalidOperationException e), + + list getList() throws (1:InvalidOperationException e), + + bool ping() throws (1:InvalidOperationException e) +} \ No newline at end of file diff --git a/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java b/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java new file mode 100644 index 0000000000..8a7022a281 --- /dev/null +++ b/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java @@ -0,0 +1,33 @@ +package com.baeldung.thrift; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class CrossPlatformServiceTest { + + private CrossPlatformServiceServer server = new CrossPlatformServiceServer(); + + @Before + public void setUp() { + new Thread(() -> server.start()).start(); + try { + // wait for the server start up + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @After + public void tearDown() { + server.stop(); + } + + @Test + public void ping() { + CrossPlatformServiceClient client = new CrossPlatformServiceClient(); + Assert.assertTrue(client.ping()); + } +} diff --git a/pom.xml b/pom.xml index 6b95ba0350..5858c69556 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ apache-cxf apache-fop apache-poi + apache-thrift aspectj assertj autovalue From f8322f161d92b16a8600bd0481955ae3fa3dd01a Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Wed, 1 Feb 2017 15:27:06 -0600 Subject: [PATCH 18/25] Create README.md --- spark-java/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 spark-java/README.md diff --git a/spark-java/README.md b/spark-java/README.md new file mode 100644 index 0000000000..edd554c7b2 --- /dev/null +++ b/spark-java/README.md @@ -0,0 +1,6 @@ +========= + +## Spark Java Tutorial Sample Project + +### Relevant Articles +- [Intro to Spark Java Framework](http://www.baeldung.com/spark-framework-rest-api) From eb79ed409b9d35ae5c76b7a92786d9bb2491cb52 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Wed, 1 Feb 2017 15:27:29 -0600 Subject: [PATCH 19/25] Update README.md --- spark-java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spark-java/README.md b/spark-java/README.md index edd554c7b2..711607bd4e 100644 --- a/spark-java/README.md +++ b/spark-java/README.md @@ -1,6 +1,6 @@ ========= -## Spark Java Tutorial Sample Project +## Spark Java Framework Tutorial Sample Project ### Relevant Articles - [Intro to Spark Java Framework](http://www.baeldung.com/spark-framework-rest-api) From 0f5b5a784eac5f27ee2405647651e249251a4796 Mon Sep 17 00:00:00 2001 From: Predrag Maric Date: Thu, 2 Feb 2017 02:59:09 +0100 Subject: [PATCH 20/25] BAEL-598 Edited pom.xml --- apache-thrift/pom.xml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/apache-thrift/pom.xml b/apache-thrift/pom.xml index e110bfb817..66cfb2bb41 100644 --- a/apache-thrift/pom.xml +++ b/apache-thrift/pom.xml @@ -38,18 +38,31 @@ install - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + org.codehaus.mojo + build-helper-maven-plugin + + + generate-sources + add-source + + + generated + + + + + + From a312ce5e1179e86181874cadc7519bf2f5007f5e Mon Sep 17 00:00:00 2001 From: pivovarit Date: Thu, 2 Feb 2017 07:47:06 +0100 Subject: [PATCH 21/25] Refactor ThreadPoolInParallelStream --- .../streams/ThreadPoolInParallelStream.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java b/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java index d654f45626..fdf593ba64 100644 --- a/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java +++ b/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java @@ -1,38 +1,34 @@ package org.baeldung.java.streams; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; +import java.util.stream.Collectors; +import java.util.stream.LongStream; import java.util.stream.Stream; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class ThreadPoolInParallelStream { @Test public void giveRangeOfLongs_whenSummedInParallel_shouldBeEqualToExpectedTotal() throws InterruptedException, ExecutionException { - List aList = new ArrayList<>(); - long lastNum = 1_000_000; long firstNum = 1; - - long expectedTotal = (lastNum + firstNum) * lastNum / 2; - - for(long i = firstNum; i <= lastNum; i++){ - aList.add(i); - } - + long lastNum = 1_000_000; + + List aList = LongStream.range(firstNum, lastNum).boxed() + .collect(Collectors.toList()); + ForkJoinPool customThreadPool = new ForkJoinPool(4); - long actualTotal = customThreadPool.submit(() -> aList.parallelStream().reduce( - 0L, (x, y) -> { - return x + y; - })).get(); + long actualTotal = customThreadPool.submit(() -> aList.parallelStream() + .reduce(0L, Long::sum)).get(); - assertEquals(expectedTotal, actualTotal); + assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal); } @Test From 3522c0537b56226b6fc0d580e3eabc48c950b4db Mon Sep 17 00:00:00 2001 From: DOHA Date: Thu, 2 Feb 2017 14:00:34 +0200 Subject: [PATCH 22/25] rename openID module --- .gitignore | 3 ++- pom.xml | 2 +- {spring-openid => spring-security-openid}/README.md | 8 +++----- {spring-openid => spring-security-openid}/pom.xml | 4 ++-- .../org/baeldung/config/GoogleOpenIdConnectConfig.java | 0 .../src/main/java/org/baeldung/config/HomeController.java | 0 .../src/main/java/org/baeldung/config/SecurityConfig.java | 0 .../java/org/baeldung/config/SpringOpenidApplication.java | 0 .../java/org/baeldung/security/OpenIdConnectFilter.java | 0 .../org/baeldung/security/OpenIdConnectUserDetails.java | 0 .../resources/application.properties.sample.properties | 0 11 files changed, 8 insertions(+), 9 deletions(-) rename {spring-openid => spring-security-openid}/README.md (63%) rename {spring-openid => spring-security-openid}/pom.xml (95%) rename {spring-openid => spring-security-openid}/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java (100%) rename {spring-openid => spring-security-openid}/src/main/java/org/baeldung/config/HomeController.java (100%) rename {spring-openid => spring-security-openid}/src/main/java/org/baeldung/config/SecurityConfig.java (100%) rename {spring-openid => spring-security-openid}/src/main/java/org/baeldung/config/SpringOpenidApplication.java (100%) rename {spring-openid => spring-security-openid}/src/main/java/org/baeldung/security/OpenIdConnectFilter.java (100%) rename {spring-openid => spring-security-openid}/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java (100%) rename {spring-openid => spring-security-openid}/src/main/resources/application.properties.sample.properties (100%) diff --git a/.gitignore b/.gitignore index 1352c943be..784627b616 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ target/ spring-openid/src/main/resources/application.properties .recommenders/ -/spring-hibernate4/nbproject/ \ No newline at end of file +/spring-hibernate4/nbproject/ +spring-security-openid/src/main/resources/application.properties diff --git a/pom.xml b/pom.xml index 5858c69556..06feb5e4f5 100644 --- a/pom.xml +++ b/pom.xml @@ -139,7 +139,7 @@ spring-mvc-web-vs-initializer spring-mvc-xml spring-mvc-simple - spring-openid + spring-security-openid spring-protobuf spring-quartz spring-rest-angular diff --git a/spring-openid/README.md b/spring-security-openid/README.md similarity index 63% rename from spring-openid/README.md rename to spring-security-openid/README.md index c5989217f4..79bf44f374 100644 --- a/spring-openid/README.md +++ b/spring-security-openid/README.md @@ -2,15 +2,13 @@ ## OpenID Connect with Spring Security - -### Build the Project +### Run the Project ``` -mvn clean install +mvn spring-boot:run ``` - ### Obtain Google App - Client ID, Secret -- You need to get client id and client secret from [Google Developer Console](https://console.developers.google.com/project/_/apiui/credential?pli=1) +- You need to get client id and client secret by creating a new project at [Google Developer Console](https://console.developers.google.com/project/_/apiui/credential?pli=1) - Make sure to add OAuth2 credentials by selecting Add credentials > OAuth 2.0 client ID - Make sure you set redirect URI to http://localhost:8081/google-login diff --git a/spring-openid/pom.xml b/spring-security-openid/pom.xml similarity index 95% rename from spring-openid/pom.xml rename to spring-security-openid/pom.xml index 6646cdea14..6e5db533d7 100644 --- a/spring-openid/pom.xml +++ b/spring-security-openid/pom.xml @@ -3,11 +3,11 @@ 4.0.0 com.baeldung - spring-openid + spring-security-openid 0.0.1-SNAPSHOT war - spring-openid + spring-security-openid Spring OpenID sample project diff --git a/spring-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java b/spring-security-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java similarity index 100% rename from spring-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java rename to spring-security-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java diff --git a/spring-openid/src/main/java/org/baeldung/config/HomeController.java b/spring-security-openid/src/main/java/org/baeldung/config/HomeController.java similarity index 100% rename from spring-openid/src/main/java/org/baeldung/config/HomeController.java rename to spring-security-openid/src/main/java/org/baeldung/config/HomeController.java diff --git a/spring-openid/src/main/java/org/baeldung/config/SecurityConfig.java b/spring-security-openid/src/main/java/org/baeldung/config/SecurityConfig.java similarity index 100% rename from spring-openid/src/main/java/org/baeldung/config/SecurityConfig.java rename to spring-security-openid/src/main/java/org/baeldung/config/SecurityConfig.java diff --git a/spring-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java b/spring-security-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java similarity index 100% rename from spring-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java rename to spring-security-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java diff --git a/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java b/spring-security-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java similarity index 100% rename from spring-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java rename to spring-security-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java diff --git a/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java b/spring-security-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java similarity index 100% rename from spring-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java rename to spring-security-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java diff --git a/spring-openid/src/main/resources/application.properties.sample.properties b/spring-security-openid/src/main/resources/application.properties.sample.properties similarity index 100% rename from spring-openid/src/main/resources/application.properties.sample.properties rename to spring-security-openid/src/main/resources/application.properties.sample.properties From c350e8b423bdaa80afaeac879caeeb9c680eadca Mon Sep 17 00:00:00 2001 From: Mobi Blunt Date: Thu, 2 Feb 2017 17:23:24 +0100 Subject: [PATCH 23/25] Fix to Unit test for Hibernate one to many (#1085) * Fix to Unit tests for Hibernate one to many * Fixed Unit test for hibernate one to many mapping tutorial * Fixed Unit test for Hibernate one to many mapping tutorial * Fixed Unit test for Hibernate one to many mapping Tutorial * Fixed Unit Test for Hibernate one to many mapping Tutorial * Unit test for Hibernate One to many Tutorial --- .../resources/hibernate-annotation.cfg.xml | 10 +- .../src/main/resources/one_to_many.sql | 2 +- .../config/HibernateAnnotationUtilTest.java | 43 ------ .../HibernateOneToManyAnnotationMainTest.java | 79 +++++++++-- .../hibernate/oneToMany/model/CartTest.java | 111 --------------- .../hibernate/oneToMany/model/ItemsTest.java | 129 ------------------ 6 files changed, 70 insertions(+), 304 deletions(-) delete mode 100644 spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtilTest.java delete mode 100644 spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/CartTest.java delete mode 100644 spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/ItemsTest.java diff --git a/spring-hibernate4/src/main/resources/hibernate-annotation.cfg.xml b/spring-hibernate4/src/main/resources/hibernate-annotation.cfg.xml index 92e323460d..311300c77c 100644 --- a/spring-hibernate4/src/main/resources/hibernate-annotation.cfg.xml +++ b/spring-hibernate4/src/main/resources/hibernate-annotation.cfg.xml @@ -5,15 +5,15 @@ com.mysql.jdbc.Driver - bastard5 - jdbc:mysql://localhost:3306/setup - root + mypassword + jdbc:mysql://localhost:3306/spring_hibernate_one_to_many?createDatabaseIfNotExist=true + myuser org.hibernate.dialect.MySQLDialect thread true - - + + diff --git a/spring-hibernate4/src/main/resources/one_to_many.sql b/spring-hibernate4/src/main/resources/one_to_many.sql index f2da0b4429..7887ff7d9c 100644 --- a/spring-hibernate4/src/main/resources/one_to_many.sql +++ b/spring-hibernate4/src/main/resources/one_to_many.sql @@ -14,4 +14,4 @@ CREATE TABLE `Items` ( PRIMARY KEY (`id`), KEY `cart_id` (`cart_id`), CONSTRAINT `items_ibfk_1` FOREIGN KEY (`cart_id`) REFERENCES `Cart` (`cart_id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; diff --git a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtilTest.java b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtilTest.java deleted file mode 100644 index 4d1b59a21e..0000000000 --- a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtilTest.java +++ /dev/null @@ -1,43 +0,0 @@ - -package com.baeldung.hibernate.oneToMany.config; - -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - - -public class HibernateAnnotationUtilTest { - - public HibernateAnnotationUtilTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - @Test - public void testGetSessionFactory() { - System.out.println("getSessionFactory"); - SessionFactory expResult = null; - SessionFactory result = HibernateAnnotationUtil.getSessionFactory(); - assertEquals(expResult, result); - fail("The test failed."); - } - -} diff --git a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java index 7ba6d3ade9..539298ae1e 100644 --- a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java +++ b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java @@ -1,8 +1,19 @@ package com.baeldung.hibernate.oneToMany.main; -import org.junit.After; -import org.junit.AfterClass; + +import com.baeldung.hibernate.oneToMany.model.Cart; +import com.baeldung.hibernate.oneToMany.model.Items; +import java.util.HashSet; +import java.util.Set; +import static org.hamcrest.Matchers.hasSize; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.dialect.HSQLDialect; +import org.hibernate.service.ServiceRegistry; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -11,30 +22,68 @@ import static org.junit.Assert.*; public class HibernateOneToManyAnnotationMainTest { + private static SessionFactory sessionFactory; + + private Session session; + public HibernateOneToManyAnnotationMainTest() { } - @BeforeClass - public static void setUpClass() { - } - @AfterClass - public static void tearDownClass() { + @BeforeClass + public static void beforeTests() { + Configuration configuration = new Configuration().addAnnotatedClass(Cart.class).addAnnotatedClass(Items.class).setProperty("hibernate.dialect", HSQLDialect.class.getName()).setProperty("hibernate.connection.driver_class", org.hsqldb.jdbcDriver.class.getName()) + .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test").setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "").setProperty("hibernate.hbm2ddl.auto", "update"); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); } @Before public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } - @After - public void tearDown() { - } + + @Test - public void testMain() { - System.out.println("main"); - String[] args = null; - HibernateOneToManyAnnotationMain.main(args); - fail("The test failed."); + public void testAddItemsToCart() { + Cart cart = new Cart(); + Set cartItems = new HashSet<>(); + cartItems = cart.getItems(); + Assert.assertNull(cartItems); + Items item1 = new Items("I10", 10, 1, cart); + assertNotNull(item1); + Set itemsSet = new HashSet(); + cart.setItems(itemsSet); + assertNotNull(cart); + System.out.println("Items added to cart"); + } + @Test + public void testSaveCart(){ + Cart cart = new Cart(); + Set cartItems = new HashSet<>(); + cartItems = cart.getItems(); + Assert.assertNull(cartItems); + Items item1 = new Items(); + item1.setItemId("I10"); + item1.setItemTotal(10); + item1.setQuantity(1); + item1.setCart(cart); + assertNotNull(item1); + Set itemsSet = new HashSet(); + itemsSet.add(item1); + assertNotNull(itemsSet); + cart.setItems(itemsSet); + assertNotNull(cart); + session.persist(cart); + session.getTransaction().commit(); + session.close(); + + } + + } diff --git a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/CartTest.java b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/CartTest.java deleted file mode 100644 index 5d6dbbb5e0..0000000000 --- a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/CartTest.java +++ /dev/null @@ -1,111 +0,0 @@ - -package com.baeldung.hibernate.oneToMany.model; - -import java.util.Set; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - - -public class CartTest { - - public CartTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - @Test - public void testGetId() { - System.out.println("getId"); - Cart instance = new Cart(); - long expResult = 0L; - long result = instance.getId(); - assertEquals(expResult, result); - fail("The test failed."); - } - - @Test - public void testSetId() { - System.out.println("setId"); - long id = 0L; - Cart instance = new Cart(); - instance.setId(id); - fail("The test failed."); - } - - @Test - public void testGetTotal() { - System.out.println("getTotal"); - Cart instance = new Cart(); - double expResult = 0.0; - double result = instance.getTotal(); - assertEquals(expResult, result, 0.0); - fail("The test failed."); - } - - @Test - public void testSetTotal() { - System.out.println("setTotal"); - double total = 0.0; - Cart instance = new Cart(); - instance.setTotal(total); - fail("The test failed."); - } - - @Test - public void testGetName() { - System.out.println("getName"); - Cart instance = new Cart(); - String expResult = ""; - String result = instance.getName(); - assertEquals(expResult, result); - fail("The test failed"); - } - - @Test - public void testSetName() { - System.out.println("setName"); - String name = ""; - Cart instance = new Cart(); - instance.setName(name); - fail("The test failed."); - } - - @Test - public void testGetItems() { - System.out.println("getItems"); - Cart instance = new Cart(); - Set expResult = null; - Set result = instance.getItems(); - assertEquals(expResult, result); - fail("The test failed."); - } - - @Test - public void testSetItems() { - System.out.println("setItems"); - Set items = null; - Cart instance = new Cart(); - instance.setItems(items); - fail("The test case failed"); - } - - -} diff --git a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/ItemsTest.java b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/ItemsTest.java deleted file mode 100644 index c6e792f9bb..0000000000 --- a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/model/ItemsTest.java +++ /dev/null @@ -1,129 +0,0 @@ - -package com.baeldung.hibernate.oneToMany.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ItemsTest { - - public ItemsTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - @Test - public void testGetItemId() { - System.out.println("getItemId"); - Items instance = new Items(); - String expResult = ""; - String result = instance.getItemId(); - assertEquals(expResult, result); - fail("The test failed."); - } - - @Test - public void testSetItemId() { - System.out.println("setItemId"); - String itemId = ""; - Items instance = new Items(); - instance.setItemId(itemId); - fail("The test failed."); - } - - @Test - public void testGetItemTotal() { - System.out.println("getItemTotal"); - Items instance = new Items(); - double expResult = 0.0; - double result = instance.getItemTotal(); - assertEquals(expResult, result, 0.0); - fail("The test failed."); - } - - @Test - public void testSetItemTotal() { - System.out.println("setItemTotal"); - double itemTotal = 0.0; - Items instance = new Items(); - instance.setItemTotal(itemTotal); - fail("The test failed."); - } - - @Test - public void testGetQuantity() { - System.out.println("getQuantity"); - Items instance = new Items(); - int expResult = 0; - int result = instance.getQuantity(); - assertEquals(expResult, result); - fail("The test failed."); - } - - @Test - public void testSetQuantity() { - System.out.println("setQuantity"); - int quantity = 0; - Items instance = new Items(); - instance.setQuantity(quantity); - fail("The test failed."); - } - - @Test - public void testGetCart() { - System.out.println("getCart"); - Items instance = new Items(); - Cart expResult = null; - Cart result = instance.getCart(); - assertEquals(expResult, result); - fail("The test failed."); - } - - @Test - public void testSetCart() { - System.out.println("setCart"); - Cart cart = null; - Items instance = new Items(); - instance.setCart(cart); - fail("The test failed."); - } - - @Test - public void testGetId() { - System.out.println("getId"); - Items instance = new Items(); - long expResult = 0L; - long result = instance.getId(); - assertEquals(expResult, result); - fail("The test failed."); - } - - @Test - public void testSetId() { - System.out.println("setId"); - long id = 0L; - Items instance = new Items(); - instance.setId(id); - fail("The test failed."); - } - -} From a1312e9ce01545f13ffb3068c873c9b43530ae42 Mon Sep 17 00:00:00 2001 From: Dotun Kola-Olaleye Date: Thu, 2 Feb 2017 18:30:05 +0100 Subject: [PATCH 24/25] Custom Thread Pools In Java 8 Parallel Streams (#1088) * String to char array and char array to String. * Method change * Custom ThreadPool In Java 8 Parallel Streams * Implemented suggested edits from editor. * Broke long method signature * Changed primitive type int to long and formula. * Update wrapper type to Long --- .../baeldung/java/streams/ThreadPoolInParallelStream.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java b/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java index fdf593ba64..b8c0991b8d 100644 --- a/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java +++ b/core-java/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStream.java @@ -1,5 +1,5 @@ package org.baeldung.java.streams; - + import org.junit.Test; import java.util.ArrayList; @@ -17,18 +17,18 @@ public class ThreadPoolInParallelStream { @Test public void giveRangeOfLongs_whenSummedInParallel_shouldBeEqualToExpectedTotal() - throws InterruptedException, ExecutionException { + throws InterruptedException, ExecutionException { long firstNum = 1; long lastNum = 1_000_000; - List aList = LongStream.range(firstNum, lastNum).boxed() + List aList = LongStream.rangeClosed(firstNum, lastNum).boxed() .collect(Collectors.toList()); ForkJoinPool customThreadPool = new ForkJoinPool(4); long actualTotal = customThreadPool.submit(() -> aList.parallelStream() .reduce(0L, Long::sum)).get(); - assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal); + assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal); } @Test From a44ea9588f66b01c8507457ff1fd9d9031c85b8b Mon Sep 17 00:00:00 2001 From: lor6 Date: Fri, 3 Feb 2017 04:46:39 +0200 Subject: [PATCH 25/25] excel processing using jexcel and poi (#1058) * excel processing using jexcel and poi * update examples * small fix * fix poi version, fix imports --- spring-mvc-java/pom.xml | 26 ++++ .../com/baeldung/excel/ExcelPOIHelper.java | 140 ++++++++++++++++++ .../java/com/baeldung/excel/JExcelHelper.java | 80 ++++++++++ .../baeldung/spring/web/config/WebConfig.java | 12 ++ .../web/controller/ExcelController.java | 105 +++++++++++++ .../src/main/webapp/WEB-INF/view/excel.jsp | 56 +++++++ 6 files changed, 419 insertions(+) create mode 100644 spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java create mode 100644 spring-mvc-java/src/main/java/com/baeldung/excel/JExcelHelper.java create mode 100644 spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java create mode 100644 spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index 7d0cc24d41..9513c81064 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -160,6 +160,28 @@ test + + + org.apache.poi + poi + ${poi.version} + + + org.apache.poi + poi-ooxml + ${poi.version} + + + org.apache.poi + poi-ooxml-schemas + ${poi.version} + + + org.jxls + jxls-jexcel + ${jexcel.version} + + @@ -370,6 +392,10 @@ 1.8.9 + + + 3.16-beta1 + 1.0.6 diff --git a/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java b/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java new file mode 100644 index 0000000000..5cf74aff63 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java @@ -0,0 +1,140 @@ +package com.baeldung.excel; + +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFFont; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.FillPatternType; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; +import org.springframework.stereotype.Service; + +@Service +public class ExcelPOIHelper { + + public Map> readExcel(String fileLocation) throws IOException { + + Map> data = new HashMap>(); + FileInputStream file = new FileInputStream(new File(fileLocation)); + Workbook workbook = new XSSFWorkbook(file); + Sheet sheet = workbook.getSheetAt(0); + int i = 0; + for (Row row : sheet) { + data.put(i, new ArrayList()); + for (Cell cell : row) { + switch (cell.getCellTypeEnum()) { + case STRING: + data.get(i) + .add(cell.getRichStringCellValue() + .getString()); + break; + case NUMERIC: + if (DateUtil.isCellDateFormatted(cell)) { + data.get(i) + .add(cell.getDateCellValue() + ""); + } else { + data.get(i) + .add(cell.getNumericCellValue() + ""); + } + break; + case BOOLEAN: + data.get(i) + .add(cell.getBooleanCellValue() + ""); + break; + case FORMULA: + data.get(i) + .add(cell.getCellFormula() + ""); + break; + default: + data.get(i) + .add(" "); + } + } + i++; + } + if (workbook != null){ + workbook.close(); + } + return data; + } + + public void writeExcel() throws IOException { + Workbook workbook = new XSSFWorkbook(); + + try { + Sheet sheet = workbook.createSheet("Persons"); + sheet.setColumnWidth(0, 6000); + sheet.setColumnWidth(1, 4000); + + Row header = sheet.createRow(0); + + CellStyle headerStyle = workbook.createCellStyle(); + + headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); + headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + XSSFFont font = ((XSSFWorkbook) workbook).createFont(); + font.setFontName("Arial"); + font.setFontHeightInPoints((short) 16); + font.setBold(true); + headerStyle.setFont(font); + + Cell headerCell = header.createCell(0); + headerCell.setCellValue("Name"); + headerCell.setCellStyle(headerStyle); + + headerCell = header.createCell(1); + headerCell.setCellValue("Age"); + headerCell.setCellStyle(headerStyle); + + CellStyle style = workbook.createCellStyle(); + style.setWrapText(true); + + Row row = sheet.createRow(2); + Cell cell = row.createCell(0); + cell.setCellValue("John Smith"); + cell.setCellStyle(style); + + cell = row.createCell(1); + cell.setCellValue(20); + cell.setCellStyle(style); + + row = sheet.createRow(3); + cell = row.createCell(0); + cell.setCellValue("Ana Johnson"); + cell.setCellStyle(style); + + cell = row.createCell(1); + cell.setCellValue(30); + cell.setCellStyle(style); + + File currDir = new File("."); + String path = currDir.getAbsolutePath(); + String fileLocation = path.substring(0, path.length() - 1) + "temp.xlsx"; + + FileOutputStream outputStream = new FileOutputStream(fileLocation); + workbook.write(outputStream); + } finally { + if (workbook != null) { + try { + workbook.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + +} \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/excel/JExcelHelper.java b/spring-mvc-java/src/main/java/com/baeldung/excel/JExcelHelper.java new file mode 100644 index 0000000000..eb65987e8b --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/excel/JExcelHelper.java @@ -0,0 +1,80 @@ +package com.baeldung.excel; + +import jxl.*; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; +import jxl.read.biff.BiffException; +import java.io.File; +import java.io.IOException; +import org.springframework.stereotype.Service; +import jxl.write.*; +import jxl.write.Number; +import jxl.format.Colour; + +@Service +public class JExcelHelper { + + public Map> readJExcel(String fileLocation) throws IOException, BiffException { + Map> data = new HashMap>(); + + Workbook workbook = Workbook.getWorkbook(new File(fileLocation)); + Sheet sheet = workbook.getSheet(0); + int rows = sheet.getRows(); + int columns = sheet.getColumns(); + + for (int i = 0; i < rows; i++) { + data.put(i, new ArrayList()); + for (int j = 0; j < columns; j++) { + data.get(i).add(sheet.getCell(j, i).getContents()); + } + } + return data; + } + + public void writeJExcel() throws IOException, WriteException { + WritableWorkbook workbook = null; + try { + File currDir = new File("."); + String path = currDir.getAbsolutePath(); + String fileLocation = path.substring(0, path.length() - 1) + "temp.xls"; + + workbook = Workbook.createWorkbook(new File(fileLocation)); + + WritableSheet sheet = workbook.createSheet("Sheet 1", 0); + + WritableCellFormat headerFormat = new WritableCellFormat(); + WritableFont font = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD); + headerFormat.setFont(font); + headerFormat.setBackground(Colour.LIGHT_BLUE); + headerFormat.setWrap(true); + Label headerLabel = new Label(0, 0, "Name", headerFormat); + sheet.setColumnView(0, 60); + sheet.addCell(headerLabel); + + headerLabel = new Label(1, 0, "Age", headerFormat); + sheet.setColumnView(0, 40); + sheet.addCell(headerLabel); + + WritableCellFormat cellFormat = new WritableCellFormat(); + cellFormat.setWrap(true); + + Label cellLabel = new Label(0, 2, "John Smith", cellFormat); + sheet.addCell(cellLabel); + Number cellNumber = new Number(1, 2, 20, cellFormat); + sheet.addCell(cellNumber); + + cellLabel = new Label(0, 3, "Ana Johnson", cellFormat); + sheet.addCell(cellLabel); + cellNumber = new Number(1, 3, 30, cellFormat); + sheet.addCell(cellNumber); + + workbook.write(); + } finally { + if (workbook != null) { + workbook.close(); + } + } + + } +} \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java index 663b9cc4d2..9578303554 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -21,6 +21,7 @@ import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.ResourceBundleViewResolver; import org.springframework.web.servlet.view.XmlViewResolver; import org.springframework.web.util.UrlPathHelper; +import com.baeldung.excel.*; @Configuration @EnableWebMvc @@ -106,4 +107,15 @@ public class WebConfig extends WebMvcConfigurerAdapter { configurer.setUrlPathHelper(urlPathHelper); } + + @Bean + public JExcelHelper jExcelHelper() { + return new JExcelHelper(); + } + + @Bean + public ExcelPOIHelper excelPOIHelper() { + return new ExcelPOIHelper(); + } + } diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java new file mode 100644 index 0000000000..810282dd65 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java @@ -0,0 +1,105 @@ +package com.baeldung.web.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import com.baeldung.excel.*; +import jxl.read.biff.BiffException; +import java.util.Map; +import java.util.ArrayList; +import javax.annotation.Resource; +import jxl.write.WriteException; + +@Controller +public class ExcelController { + + private String fileLocation; + + @Resource(name = "jExcelHelper") + private JExcelHelper jExcelHelper; + + @Resource(name = "excelPOIHelper") + private ExcelPOIHelper excelPOIHelper; + + @RequestMapping(method = RequestMethod.GET, value = "/excelProcessing") + public String getExcelProcessingPage() { + return "excel"; + } + + @RequestMapping(method = RequestMethod.POST, value = "/uploadExcelFile") + public String uploadFile(Model model, MultipartFile file) throws IOException { + InputStream in = file.getInputStream(); + File currDir = new File("."); + String path = currDir.getAbsolutePath(); + fileLocation = path.substring(0, path.length() - 1) + file.getOriginalFilename(); + FileOutputStream f = new FileOutputStream(fileLocation); + int ch = 0; + while ((ch = in.read()) != -1) { + f.write(ch); + } + f.flush(); + f.close(); + System.out.println(fileLocation); + model.addAttribute("message", "File: " + file.getOriginalFilename() + " has been uploaded successfully!"); + return "excel"; + } + + @RequestMapping(method = RequestMethod.GET, value = "/readJExcel") + public String readJExcel(Model model) throws IOException, BiffException { + + if (fileLocation != null) { + if (fileLocation.endsWith(".xls")) { + Map> data = jExcelHelper.readJExcel(fileLocation); + model.addAttribute("data", data); + } else { + model.addAttribute("message", "Not a valid .xls file!"); + } + } else { + model.addAttribute("message", "File missing! Please upload an excel file."); + } + return "excel"; + } + + @RequestMapping(method = RequestMethod.GET, value = "/readPOI") + public String readPOI(Model model) throws IOException { + + if (fileLocation != null) { + if (fileLocation.endsWith(".xlsx")) { + Map> data = excelPOIHelper.readExcel(fileLocation); + model.addAttribute("data", data); + } else { + model.addAttribute("message", "Not a valid .xlsx file!"); + } + } else { + model.addAttribute("message", "File missing! Please upload an excel file."); + } + return "excel"; + } + + @RequestMapping(method = RequestMethod.POST, value = "/writeJExcel") + public String writeJExcel(Model model) throws IOException, BiffException, WriteException { + + jExcelHelper.writeJExcel(); + + model.addAttribute("message", "Write successful!"); + + return "excel"; + } + + @RequestMapping(method = RequestMethod.POST, value = "/writePOI") + public String writePOI(Model model) throws IOException { + + excelPOIHelper.writeExcel(); + + model.addAttribute("message", "Write successful!"); + + return "excel"; + } + +} \ No newline at end of file diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp b/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp new file mode 100644 index 0000000000..b50687df15 --- /dev/null +++ b/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp @@ -0,0 +1,56 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + +Excel Processing + + + + + + + + + +
+ + +
+
+${message } +

+
+ +
+

+Read file using JExcel     +Read file using Apache POI +

+ +File content: + + + + + + + + + +
${cell}
+
+

+
+ +
+
+
+ +
+ + + + \ No newline at end of file