diff --git a/src/main/java/algoLike/pull/HandsA.java b/src/main/java/algoLike/pull/HandsA.java index 9d3f876..12bd636 100644 --- a/src/main/java/algoLike/pull/HandsA.java +++ b/src/main/java/algoLike/pull/HandsA.java @@ -1,37 +1,31 @@ package algoLike.pull; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.stereotype.Component; -import pushPullRefactor.Getter; -import pushPullRefactor.Message; -import pushPullRefactor.Resource; -import pushPullRefactor.State; - -import javax.ws.rs.*; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.MediaType; import java.util.*; +import javax.ws.rs.*; +import javax.ws.rs.client.*; +import javax.ws.rs.core.*; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import pushPullRefactor.*; @Path("/handsA") @Resource("handsA") @Component public class HandsA { - private final Client client = ClientBuilder.newClient(); + private Client client = ClientBuilder.newClient(); private Map.Entry resultByDrawingA; private Map.Entry resultByDrawingB; private Map.Entry> resultBySelectingA; private Map.Entry> resultBySelectingB; @State private List> value = new ArrayList>(); - @Path("/resultByDrawingA") @POST - @Message({"resultByDrawingA", "deck"}) + @Message({"resultByDrawingA","deck"}) public void updateResultByDrawingA(@FormParam("resultByDrawingA") String resultByDrawingA_json, @FormParam("deck") List deck_json) throws JsonProcessingException { List> deck = new ArrayList<>(); - for (String str : deck_json) { + for (String str: deck_json) { Map i = new ObjectMapper().readValue(str, HashMap.class); deck.add(i.entrySet().iterator().next()); } @@ -52,15 +46,13 @@ temp_if2 = this.value; } this.value = temp_if2; - } - @Path("/resultByDrawingB") @POST - @Message({"resultByDrawingB", "deck"}) + @Message({"resultByDrawingB","deck"}) public void updateResultByDrawingB(@FormParam("resultByDrawingB") String resultByDrawingB_json, @FormParam("deck") List deck_json) throws JsonProcessingException { List> deck = new ArrayList<>(); - for (String str : deck_json) { + for (String str: deck_json) { Map i = new ObjectMapper().readValue(str, HashMap.class); deck.add(i.entrySet().iterator().next()); } @@ -72,15 +64,13 @@ this.resultByDrawingB = resultByDrawingB; List> temp_if3; if (resultByDrawingB.getKey()) { - this.value.set(resultByDrawingB.getValue(), new AbstractMap.SimpleEntry<>(this.value.get(resultByDrawingB.getValue()).getKey(), true)); + this.value.set(resultByDrawingB.getValue(),new AbstractMap.SimpleEntry<>(this.value.get(resultByDrawingB.getValue()).getKey(), true)); temp_if3 = this.value; } else { temp_if3 = this.value; } this.value = temp_if3; - } - @Path("/resultBySelectingA") @POST @Message({"resultBySelecting"}) @@ -95,13 +85,11 @@ if (resultBySelectingA.getKey()) { temp_if4 = this.value; } else { - this.value.set(resultBySelectingA.getValue().getValue(), new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingA.getValue().getValue()).getKey(), true)); + this.value.set(resultBySelectingA.getValue().getValue(),new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingA.getValue().getValue()).getKey(), true)); temp_if4 = this.value; } this.value = temp_if4; - } - @Path("/resultBySelectingB") @POST @Message({"resultBySelectingB"}) @@ -114,15 +102,13 @@ this.resultBySelectingB = resultBySelectingB; List> temp_if6; if (resultBySelectingB.getKey()) { - this.value.set(resultBySelectingB.getValue().getKey(), new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingB.getValue().getKey()).getKey(), true)); + this.value.set(resultBySelectingB.getValue().getKey(),new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingB.getValue().getKey()).getKey(), true)); temp_if6 = this.value; } else { temp_if6 = this.value; } this.value = temp_if6; - } - @Produces(MediaType.APPLICATION_JSON) @GET @Getter diff --git a/src/main/java/algoLike/pull/LoseA.java b/src/main/java/algoLike/pull/LoseA.java index 8fd89dc..617224e 100644 --- a/src/main/java/algoLike/pull/LoseA.java +++ b/src/main/java/algoLike/pull/LoseA.java @@ -1,43 +1,38 @@ package algoLike.pull; - +import java.util.*; +import java.util.stream.Collectors; +import javax.ws.rs.*; +import javax.ws.rs.client.*; +import javax.ws.rs.core.*; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.JsonProcessingException; import pushPullRefactor.Getter; +import pushPullRefactor.Message; +import pushPullRefactor.Resource; +import pushPullRefactor.State; + +import javax.ws.rs.client.*; import pushPullRefactor.PullReference; import pushPullRefactor.Pushable; -import pushPullRefactor.Resource; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.MediaType; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; @Path("/loseA") @Component @Resource("loseA") public class LoseA { - private final Client client = ClientBuilder.newClient(); + private Client client = ClientBuilder.newClient(); @PullReference("handsA") @Pushable - private final String handsA = "/handsA"; - + String handsA= "/handsA"; @Produces(MediaType.APPLICATION_JSON) @GET @Getter public boolean getValue() { - List> handsA_json = client.target("http:localhost:8080").path(this.handsA).request().get(ArrayList.class); - List> handsA = new ArrayList<>(); - for (Map i : handsA_json) { - handsA.add(new AbstractMap.SimpleEntry<>( - Integer.parseInt(i.entrySet().iterator().next().getKey()), - i.entrySet().iterator().next().getValue())); + List> handsA_json = client.target("http://localhost:8080").path(this.handsA).request().get(ArrayList.class); + List> handsA = new ArrayList<>(); + for (Map i: handsA_json) { + handsA.add(new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue())); } return (handsA.stream().filter(item -> item.getValue() == false).collect(Collectors.toList()).size() == 0); }