diff --git a/setting.gradle b/setting.gradle index 010c46c..6f924cf 100644 --- a/setting.gradle +++ b/setting.gradle @@ -1 +1 @@ -rootProject.name = 'algoLike.push' \ No newline at end of file +rootProject.name = 'algoLike.pull' \ No newline at end of file diff --git a/src/main/java/algoLike/pull/AttackerA.java b/src/main/java/algoLike/pull/AttackerA.java index c29cb71..9c23a6e 100644 --- a/src/main/java/algoLike/pull/AttackerA.java +++ b/src/main/java/algoLike/pull/AttackerA.java @@ -1,32 +1,31 @@ -package algoLike.push; +package algoLike.pull; -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.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + @Path("/attackerA") @Component @Resource("attackerA") public class AttackerA { - @State - private int value; - @PUT - @Message({}) - public void setAttackerA(@FormParam("a") int a) { - this.value = a; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public int getValue() { - return value; - } + @State + private int value; + + @PUT + @Message({}) + public void setAttackerA(@FormParam("a") int a) { + this.value = a; + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public int getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/AttackerB.java b/src/main/java/algoLike/pull/AttackerB.java index 5d308f3..fd07fde 100644 --- a/src/main/java/algoLike/pull/AttackerB.java +++ b/src/main/java/algoLike/pull/AttackerB.java @@ -1,32 +1,31 @@ -package algoLike.push; +package algoLike.pull; -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.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + @Path("/attackerB") @Component @Resource("attackerB") public class AttackerB { - @State - private int value; - @PUT - @Message({}) - public void setAttackerB(@FormParam("b") int b) { - this.value = b; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public int getValue() { - return value; - } + @State + private int value; + + @PUT + @Message({}) + public void setAttackerB(@FormParam("b") int b) { + this.value = b; + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public int getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/Deck.java b/src/main/java/algoLike/pull/Deck.java index ff3fc89..de3d304 100644 --- a/src/main/java/algoLike/pull/Deck.java +++ b/src/main/java/algoLike/pull/Deck.java @@ -1,57 +1,61 @@ -package algoLike.push; +package algoLike.pull; -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 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.core.MediaType; +import java.util.*; + @Path("/deck") @Component @Resource("deck") public class Deck { - private Map.Entry resultByDrawingA; - private Map.Entry resultByDrawingB; - @State - private List> value = new ArrayList>(); - @Path("/resultByDrawingA") - @POST - @Message({"resultByDrawingA"}) - public void updateResultByDrawingA(@FormParam("resultByDrawingA") String resultByDrawingA_json) throws JsonProcessingException { - Map.Entry resultByDrawingA; - { - Map i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class); - resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); - } - this.resultByDrawingA = resultByDrawingA; - this.value = this.value.subList(1, this.value.size()); - } - @Path("/resultByDrawingB") - @POST - @Message({"resultByDrawingB"}) - public void updateResultByDrawingB(@FormParam("resultByDrawingB") String resultByDrawingB_json) throws JsonProcessingException { - Map.Entry resultByDrawingB; - { - Map i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class); - resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); - } - this.resultByDrawingB = resultByDrawingB; - this.value = this.value.subList(1, this.value.size()); - } - @POST - public void addCard(@FormParam("num") Integer num) { - this.value.add(0, new AbstractMap.SimpleEntry<>(num, false)); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public List> getValue() { - return value; - } + private Map.Entry resultByDrawingA; + private Map.Entry resultByDrawingB; + @State + private List> value = new ArrayList>(); + + @Path("/resultByDrawingA") + @POST + @Message({"resultByDrawingA"}) + public void updateResultByDrawingA(@FormParam("resultByDrawingA") String resultByDrawingA_json) throws JsonProcessingException { + Map.Entry resultByDrawingA; + { + Map i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class); + resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); + } + this.resultByDrawingA = resultByDrawingA; + this.value = this.value.subList(1, this.value.size()); + } + + @Path("/resultByDrawingB") + @POST + @Message({"resultByDrawingB"}) + public void updateResultByDrawingB(@FormParam("resultByDrawingB") String resultByDrawingB_json) throws JsonProcessingException { + Map.Entry resultByDrawingB; + { + Map i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class); + resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); + } + this.resultByDrawingB = resultByDrawingB; + this.value = this.value.subList(1, this.value.size()); + } + + @POST + public void addCard(@FormParam("num") Integer num) { + this.value.add(0, new AbstractMap.SimpleEntry<>(num, false)); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public List> getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/GuessA.java b/src/main/java/algoLike/pull/GuessA.java index f965a01..bdfdeb8 100644 --- a/src/main/java/algoLike/pull/GuessA.java +++ b/src/main/java/algoLike/pull/GuessA.java @@ -1,30 +1,29 @@ -package algoLike.push; +package algoLike.pull; -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.Getter; import pushPullRefactor.Resource; import pushPullRefactor.State; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + @Path("/guessA") @Component @Resource("guessA") public class GuessA { - @State - private int value = 0; - @PUT - public void setGuessA(@FormParam("a") int a) { - this.value = a; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public int getValue() { - return value; - } + @State + private int value = 0; + + @PUT + public void setGuessA(@FormParam("a") int a) { + this.value = a; + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public int getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/GuessB.java b/src/main/java/algoLike/pull/GuessB.java index 958c492..80bb09f 100644 --- a/src/main/java/algoLike/pull/GuessB.java +++ b/src/main/java/algoLike/pull/GuessB.java @@ -1,32 +1,31 @@ -package algoLike.push; +package algoLike.pull; -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.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + @Path("/guessB") @Component @Resource("guessB") public class GuessB { - @State - private int value = 0; - @PUT - @Message({}) - public void setGuessB(@FormParam("b") int b) { - this.value = b; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public int getValue() { - return value; - } + @State + private int value = 0; + + @PUT + @Message({}) + public void setGuessB(@FormParam("b") int b) { + this.value = b; + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public int getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/HandsA.java b/src/main/java/algoLike/pull/HandsA.java index 6164918..9d3f876 100644 --- a/src/main/java/algoLike/pull/HandsA.java +++ b/src/main/java/algoLike/pull/HandsA.java @@ -1,122 +1,132 @@ -package algoLike.push; +package algoLike.pull; -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.*; +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.*; @Path("/handsA") @Resource("handsA") @Component public class HandsA { - 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"}) - public void updateResultByDrawingA(@FormParam("resultByDrawingA") String resultByDrawingA_json, @FormParam("deck") List deck_json) throws JsonProcessingException { - List> deck = new ArrayList<>(); - for (String str: deck_json) { - Map i = new ObjectMapper().readValue(str, HashMap.class); - deck.add(i.entrySet().iterator().next()); - } - Map.Entry resultByDrawingA; - { - Map i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class); - resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); - } - this.resultByDrawingA = resultByDrawingA; - List> temp_if2; - if (resultByDrawingA.getKey()) { - this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false)); - this.value.sort(Comparator.comparing(Map.Entry::getKey)); - temp_if2 = this.value; - } else { - this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), true)); - this.value.sort(Comparator.comparing(Map.Entry::getKey)); - temp_if2 = this.value; - } - this.value = temp_if2; + private final 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("/resultByDrawingB") - @POST - @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) { - Map i = new ObjectMapper().readValue(str, HashMap.class); - deck.add(i.entrySet().iterator().next()); - } - Map.Entry resultByDrawingB; - { - Map i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class); - resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); - } - this.resultByDrawingB = resultByDrawingB; - List> temp_if3; - if (resultByDrawingB.getKey()) { - 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("/resultByDrawingA") + @POST + @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) { + Map i = new ObjectMapper().readValue(str, HashMap.class); + deck.add(i.entrySet().iterator().next()); + } + Map.Entry resultByDrawingA; + { + Map i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class); + resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); + } + this.resultByDrawingA = resultByDrawingA; + List> temp_if2; + if (resultByDrawingA.getKey()) { + this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false)); + this.value.sort(Comparator.comparing(Map.Entry::getKey)); + temp_if2 = this.value; + } else { + this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), true)); + this.value.sort(Comparator.comparing(Map.Entry::getKey)); + temp_if2 = this.value; + } + this.value = temp_if2; - } - @Path("/resultBySelectingA") - @POST - @Message({"resultBySelecting"}) - public void updateResultBySelectingA(@FormParam("resultBySelectingA") String resultBySelectingA_json) throws JsonProcessingException { - Map.Entry> resultBySelectingA; - { - Map> i = new ObjectMapper().readValue(resultBySelectingA_json, HashMap.class); - resultBySelectingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); - } - this.resultBySelectingA = resultBySelectingA; - List> temp_if4; - 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)); - temp_if4 = this.value; - } - this.value = temp_if4; + } - } - @Path("/resultBySelectingB") - @POST - @Message({"resultBySelectingB"}) - public void updateResultBySelectingB(@FormParam("resultBySelectingB") String resultBySelectingB_json) throws JsonProcessingException { - Map.Entry> resultBySelectingB; - { - Map> i = new ObjectMapper().readValue(resultBySelectingB_json, HashMap.class); - resultBySelectingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); - } - 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)); - temp_if6 = this.value; - } else { - temp_if6 = this.value; - } - this.value = temp_if6; + @Path("/resultByDrawingB") + @POST + @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) { + Map i = new ObjectMapper().readValue(str, HashMap.class); + deck.add(i.entrySet().iterator().next()); + } + Map.Entry resultByDrawingB; + { + Map i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class); + resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); + } + this.resultByDrawingB = resultByDrawingB; + List> temp_if3; + if (resultByDrawingB.getKey()) { + 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; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public List> getValue() { - return value; - } + } + + @Path("/resultBySelectingA") + @POST + @Message({"resultBySelecting"}) + public void updateResultBySelectingA(@FormParam("resultBySelectingA") String resultBySelectingA_json) throws JsonProcessingException { + Map.Entry> resultBySelectingA; + { + Map> i = new ObjectMapper().readValue(resultBySelectingA_json, HashMap.class); + resultBySelectingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); + } + this.resultBySelectingA = resultBySelectingA; + List> temp_if4; + 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)); + temp_if4 = this.value; + } + this.value = temp_if4; + + } + + @Path("/resultBySelectingB") + @POST + @Message({"resultBySelectingB"}) + public void updateResultBySelectingB(@FormParam("resultBySelectingB") String resultBySelectingB_json) throws JsonProcessingException { + Map.Entry> resultBySelectingB; + { + Map> i = new ObjectMapper().readValue(resultBySelectingB_json, HashMap.class); + resultBySelectingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); + } + 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)); + temp_if6 = this.value; + } else { + temp_if6 = this.value; + } + this.value = temp_if6; + + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public List> getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/HandsB.java b/src/main/java/algoLike/pull/HandsB.java index f43e5c1..2c6b20c 100644 --- a/src/main/java/algoLike/pull/HandsB.java +++ b/src/main/java/algoLike/pull/HandsB.java @@ -1,145 +1,154 @@ -package algoLike.push; +package algoLike.pull; -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 com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.stereotype.Component; import pushPullRefactor.*; +import javax.ws.rs.*; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import java.util.*; + @Path("/handsB") @Component @Resource("handsB") public class HandsB { - private Client client = ClientBuilder.newClient(); - private Map.Entry resultByDrawingB; - private Map.Entry resultByDrawingA; - private Map.Entry> resultBySelectingB; - private Map.Entry> resultBySelectingA; - @State - private List> value = new ArrayList>(); - @PushReference("loseB") - @Pullable("direct") - private String loseB = "/loseB"; - @Path("/resultByDrawingB") - @POST - @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) { - Map i = new ObjectMapper().readValue(str, HashMap.class); - deck.add(i.entrySet().iterator().next()); - } - Map.Entry resultByDrawingB; - { - Map i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class); - resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); - } - this.resultByDrawingB = resultByDrawingB; - List> temp_if0; - if (resultByDrawingB.getKey()) { - this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false)); - this.value.sort(Comparator.comparing(Map.Entry::getKey)); - temp_if0 = this.value; - } else { - this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), true)); - this.value.sort(Comparator.comparing(Map.Entry::getKey)); - temp_if0 = this.value; - } - this.value = temp_if0; - Form form = new Form(); - for (Map.Entry i: this.value) { - form.param("handsB", new ObjectMapper().writeValueAsString(i)); - } - Entity
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); - } - @Path("/resultByDrawingA") - @POST - @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) { - Map i = new ObjectMapper().readValue(str, HashMap.class); - deck.add(i.entrySet().iterator().next()); - } - Map.Entry resultByDrawingA; - { - Map i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class); - resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); - } - this.resultByDrawingA = resultByDrawingA; - List> temp_if1; - if (resultByDrawingA.getKey()) { - this.value.set(resultByDrawingA.getValue(),new AbstractMap.SimpleEntry<>(this.value.get(resultByDrawingA.getValue()).getKey(), true)); - temp_if1 = this.value; - } else { - temp_if1 = this.value; - } - this.value = temp_if1; - Form form = new Form(); - for (Map.Entry i: this.value) { - form.param("handsB", new ObjectMapper().writeValueAsString(i)); - } - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); - } - @Path("/resultBySelectingB") - @POST - @Message({"resultBySelectingA"}) - public void updateResultBySelectingB(@FormParam("resultBySelectingB") String resultBySelectingB_json) throws JsonProcessingException { - Map.Entry> resultBySelectingB; - { - Map> i = new ObjectMapper().readValue(resultBySelectingB_json, HashMap.class); - resultBySelectingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); - } - this.resultBySelectingB = resultBySelectingB; - List> temp_if5; - if (resultBySelectingB.getKey()) { - temp_if5 = this.value; - } else { - this.value.set(resultBySelectingB.getValue().getValue(),new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingB.getValue().getValue()).getKey(), true)); - temp_if5 = this.value; - } - this.value = temp_if5; - Form form = new Form(); - for (Map.Entry i: this.value) { - form.param("handsB", new ObjectMapper().writeValueAsString(i)); - } - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); - } - @Path("/resultBySelectingA") - @POST - @Message({"resultBySelectingA"}) - public void updateResultBySelectingA(@FormParam("resultBySelectingA") String resultBySelectingA_json) throws JsonProcessingException { - Map.Entry> resultBySelectingA; - { - Map> i = new ObjectMapper().readValue(resultBySelectingA_json, HashMap.class); - resultBySelectingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); - } - this.resultBySelectingA = resultBySelectingA; - List> temp_if7; - if (resultBySelectingA.getKey()) { - this.value.set(resultBySelectingA.getValue().getKey(),new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingA.getValue().getKey()).getKey(), true)); - temp_if7 = this.value; - } else { - temp_if7 = this.value; - } - this.value = temp_if7; - Form form = new Form(); - for (Map.Entry i: this.value) { - form.param("handsB", new ObjectMapper().writeValueAsString(i)); - } - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public List> getValue() { - return value; - } + private final Client client = ClientBuilder.newClient(); + private Map.Entry resultByDrawingB; + private Map.Entry resultByDrawingA; + private Map.Entry> resultBySelectingB; + private Map.Entry> resultBySelectingA; + @State + private List> value = new ArrayList>(); + @PushReference("loseB") + @Pullable("direct") + private final String loseB = "/loseB"; + + @Path("/resultByDrawingB") + @POST + @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) { + Map i = new ObjectMapper().readValue(str, HashMap.class); + deck.add(i.entrySet().iterator().next()); + } + Map.Entry resultByDrawingB; + { + Map i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class); + resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); + } + this.resultByDrawingB = resultByDrawingB; + List> temp_if0; + if (resultByDrawingB.getKey()) { + this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false)); + this.value.sort(Comparator.comparing(Map.Entry::getKey)); + temp_if0 = this.value; + } else { + this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), true)); + this.value.sort(Comparator.comparing(Map.Entry::getKey)); + temp_if0 = this.value; + } + this.value = temp_if0; + Form form = new Form(); + for (Map.Entry i : this.value) { + form.param("handsB", new ObjectMapper().writeValueAsString(i)); + } + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); + } + + @Path("/resultByDrawingA") + @POST + @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) { + Map i = new ObjectMapper().readValue(str, HashMap.class); + deck.add(i.entrySet().iterator().next()); + } + Map.Entry resultByDrawingA; + { + Map i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class); + resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()); + } + this.resultByDrawingA = resultByDrawingA; + List> temp_if1; + if (resultByDrawingA.getKey()) { + this.value.set(resultByDrawingA.getValue(), new AbstractMap.SimpleEntry<>(this.value.get(resultByDrawingA.getValue()).getKey(), true)); + temp_if1 = this.value; + } else { + temp_if1 = this.value; + } + this.value = temp_if1; + Form form = new Form(); + for (Map.Entry i : this.value) { + form.param("handsB", new ObjectMapper().writeValueAsString(i)); + } + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); + } + + @Path("/resultBySelectingB") + @POST + @Message({"resultBySelectingA"}) + public void updateResultBySelectingB(@FormParam("resultBySelectingB") String resultBySelectingB_json) throws JsonProcessingException { + Map.Entry> resultBySelectingB; + { + Map> i = new ObjectMapper().readValue(resultBySelectingB_json, HashMap.class); + resultBySelectingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); + } + this.resultBySelectingB = resultBySelectingB; + List> temp_if5; + if (resultBySelectingB.getKey()) { + temp_if5 = this.value; + } else { + this.value.set(resultBySelectingB.getValue().getValue(), new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingB.getValue().getValue()).getKey(), true)); + temp_if5 = this.value; + } + this.value = temp_if5; + Form form = new Form(); + for (Map.Entry i : this.value) { + form.param("handsB", new ObjectMapper().writeValueAsString(i)); + } + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); + } + + @Path("/resultBySelectingA") + @POST + @Message({"resultBySelectingA"}) + public void updateResultBySelectingA(@FormParam("resultBySelectingA") String resultBySelectingA_json) throws JsonProcessingException { + Map.Entry> resultBySelectingA; + { + Map> i = new ObjectMapper().readValue(resultBySelectingA_json, HashMap.class); + resultBySelectingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); + } + this.resultBySelectingA = resultBySelectingA; + List> temp_if7; + if (resultBySelectingA.getKey()) { + this.value.set(resultBySelectingA.getValue().getKey(), new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingA.getValue().getKey()).getKey(), true)); + temp_if7 = this.value; + } else { + temp_if7 = this.value; + } + this.value = temp_if7; + Form form = new Form(); + for (Map.Entry i : this.value) { + form.param("handsB", new ObjectMapper().writeValueAsString(i)); + } + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path(loseB).request().put(entity, String.class); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public List> getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/LoseA.java b/src/main/java/algoLike/pull/LoseA.java index 9210e1a..8fd89dc 100644 --- a/src/main/java/algoLike/pull/LoseA.java +++ b/src/main/java/algoLike/pull/LoseA.java @@ -1,39 +1,44 @@ -package algoLike.push; +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.PullReference; +import pushPullRefactor.Pushable; import pushPullRefactor.Resource; -import pushPullRefactor.State; + +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 client client = ClientBUilder.newClient(); + private final Client client = ClientBuilder.newClient(); - @PullReference("handsA") - @Pushable - private String handsA = "/handsA"; + @PullReference("handsA") + @Pushable + private final 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())); - } - return (handsA.stream().filter(item -> item.getValue()==false).collect(Collectors.toList()).size()==0); - } + @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())); + } + return (handsA.stream().filter(item -> item.getValue() == false).collect(Collectors.toList()).size() == 0); + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/LoseB.java b/src/main/java/algoLike/pull/LoseB.java index 887312b..1f43e40 100644 --- a/src/main/java/algoLike/pull/LoseB.java +++ b/src/main/java/algoLike/pull/LoseB.java @@ -1,38 +1,43 @@ -package algoLike.push; +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 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.core.MediaType; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + @Path("/loseB") @Component @Resource("loseB") public class LoseB { - @State - private boolean value; - @PUT - @Message({"handsB"}) - public void updateHandsB(@FormParam("handsB") List handsB_json) throws JsonProcessingException { - List> handsB = new ArrayList<>(); - for (String str: handsB_json) { - Map i = new ObjectMapper().readValue(str, HashMap.class); - handsB.add(i.entrySet().iterator().next()); - } - this.value = (handsB.stream().filter(item -> item.getValue()==false).collect(Collectors.toList()).size()==0); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public boolean getValue() { - return value; - } + @State + private boolean value; + + @PUT + @Message({"handsB"}) + public void updateHandsB(@FormParam("handsB") List handsB_json) throws JsonProcessingException { + List> handsB = new ArrayList<>(); + for (String str : handsB_json) { + Map i = new ObjectMapper().readValue(str, HashMap.class); + handsB.add(i.entrySet().iterator().next()); + } + this.value = (handsB.stream().filter(item -> item.getValue() == false).collect(Collectors.toList()).size() == 0); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public boolean getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/ResultByDrawingA.java b/src/main/java/algoLike/pull/ResultByDrawingA.java index 15af945..063824f 100644 --- a/src/main/java/algoLike/pull/ResultByDrawingA.java +++ b/src/main/java/algoLike/pull/ResultByDrawingA.java @@ -1,56 +1,65 @@ -package algoLike.push; +package algoLike.pull; -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 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.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + @Path("/resultByDrawingA") @Component @Resource("resultByDrawingA") public class ResultByDrawingA { - private Client client = ClientBuilder.newClient(); - @State - private Map.Entry value; - @PUT - @Message({}) - public void drawAndAttackA(@FormParam("g") int g, @FormParam("b") List> b, @FormParam("t") int t) throws JsonProcessingException { - this.value = new AbstractMap.SimpleEntry<>((b.get(t).getKey()==g), t); - List> deck_json = client.target("http://localhost:8080").path("/deck").request().get(ArrayList.class); - List> deck = new ArrayList<>(); - for (Map i: deck_json) { - deck.add(i.entrySet().iterator().next()); - } - Form form = new Form(); - form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path("/deck/resultByDrawingA").request().post(entity, String.class); - form = new Form(); - form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); - for (Map.Entry i: deck) { - form.param("deck", new ObjectMapper().writeValueAsString(i)); - } - entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - result = client.target("http://localhost:8080").path("/handsB/resultByDrawingA").request().post(entity, String.class); - form = new Form(); - form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); - for (Map.Entry i: deck) { - form.param("deck", new ObjectMapper().writeValueAsString(i)); - } - entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - result = client.target("http://localhost:8080").path("/handsA/resultByDrawingA").request().post(entity, String.class); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public Map.Entry getValue() { - return value; - } + private final Client client = ClientBuilder.newClient(); + @State + private Map.Entry value; + + @PUT + @Message({}) + public void drawAndAttackA(@FormParam("g") int g, @FormParam("b") List> b, @FormParam("t") int t) throws JsonProcessingException { + this.value = new AbstractMap.SimpleEntry<>((b.get(t).getKey() == g), t); + List> deck_json = client.target("http://localhost:8080").path("/deck").request().get(ArrayList.class); + List> deck = new ArrayList<>(); + for (Map i : deck_json) { + deck.add(i.entrySet().iterator().next()); + } + Form form = new Form(); + form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/deck/resultByDrawingA").request().post(entity, String.class); + form = new Form(); + form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); + for (Map.Entry i : deck) { + form.param("deck", new ObjectMapper().writeValueAsString(i)); + } + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/handsB/resultByDrawingA").request().post(entity, String.class); + form = new Form(); + form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); + for (Map.Entry i : deck) { + form.param("deck", new ObjectMapper().writeValueAsString(i)); + } + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/handsA/resultByDrawingA").request().post(entity, String.class); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/ResultByDrawingB.java b/src/main/java/algoLike/pull/ResultByDrawingB.java index b333d52..0f8c68b 100644 --- a/src/main/java/algoLike/pull/ResultByDrawingB.java +++ b/src/main/java/algoLike/pull/ResultByDrawingB.java @@ -1,56 +1,65 @@ -package algoLike.push; +package algoLike.pull; -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 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.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + @Path("/resultByDrawingB") @Component @Resource("resultByDrawingB") public class ResultByDrawingB { - private Client client = ClientBuilder.newClient(); - @State - private Map.Entry value; - @PUT - @Message({}) - public void drawAndAttackB(@FormParam("g") int g, @FormParam("a") List> a, @FormParam("t") int t) throws JsonProcessingException { - this.value = new AbstractMap.SimpleEntry<>((a.get(t).getKey()==g), t); - List> deck_json = client.target("http://localhost:8080").path("/deck").request().get(ArrayList.class); - List> deck = new ArrayList<>(); - for (Map i: deck_json) { - deck.add(i.entrySet().iterator().next()); - } - Form form = new Form(); - form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); - for (Map.Entry i: deck) { - form.param("deck", new ObjectMapper().writeValueAsString(i)); - } - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path("/handsB/resultByDrawingB").request().post(entity, String.class); - form = new Form(); - form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); - entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - result = client.target("http://localhost:8080").path("/deck/resultByDrawingB").request().post(entity, String.class); - form = new Form(); - form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); - for (Map.Entry i: deck) { - form.param("deck", new ObjectMapper().writeValueAsString(i)); - } - entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - result = client.target("http://localhost:8080").path("/handsA/resultByDrawingB").request().post(entity, String.class); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public Map.Entry getValue() { - return value; - } + private final Client client = ClientBuilder.newClient(); + @State + private Map.Entry value; + + @PUT + @Message({}) + public void drawAndAttackB(@FormParam("g") int g, @FormParam("a") List> a, @FormParam("t") int t) throws JsonProcessingException { + this.value = new AbstractMap.SimpleEntry<>((a.get(t).getKey() == g), t); + List> deck_json = client.target("http://localhost:8080").path("/deck").request().get(ArrayList.class); + List> deck = new ArrayList<>(); + for (Map i : deck_json) { + deck.add(i.entrySet().iterator().next()); + } + Form form = new Form(); + form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); + for (Map.Entry i : deck) { + form.param("deck", new ObjectMapper().writeValueAsString(i)); + } + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/handsB/resultByDrawingB").request().post(entity, String.class); + form = new Form(); + form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/deck/resultByDrawingB").request().post(entity, String.class); + form = new Form(); + form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); + for (Map.Entry i : deck) { + form.param("deck", new ObjectMapper().writeValueAsString(i)); + } + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/handsA/resultByDrawingB").request().post(entity, String.class); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/ResultBySelectingA.java b/src/main/java/algoLike/pull/ResultBySelectingA.java index 3cd80c7..66fa91e 100644 --- a/src/main/java/algoLike/pull/ResultBySelectingA.java +++ b/src/main/java/algoLike/pull/ResultBySelectingA.java @@ -1,41 +1,49 @@ -package algoLike.push; +package algoLike.pull; -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 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.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; + @Path("/resultBySelectingA") @Component @Resource("resultBySelectingA") public class ResultBySelectingA { - private Client client = ClientBuilder.newClient(); - @State - private Map.Entry> value; - @PUT - @Message({}) - public void selectAndAttackA(@FormParam("t") int t, @FormParam("g") int g, @FormParam("b") List> b, @FormParam("a") int a) throws JsonProcessingException { - this.value = new AbstractMap.SimpleEntry<>((b.get(t).getKey()==g), new AbstractMap.SimpleEntry<>(t, a)); - Form form = new Form(); - form.param("resultBySelectingA", new ObjectMapper().writeValueAsString(this.value)); - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path("/handsA/resultBySelectingA").request().post(entity, String.class); - form = new Form(); - form.param("resultBySelectingA", new ObjectMapper().writeValueAsString(this.value)); - entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - result = client.target("http://localhost:8080").path("/handsB/resultBySelectingA").request().post(entity, String.class); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public Map.Entry> getValue() { - return value; - } + private final Client client = ClientBuilder.newClient(); + @State + private Map.Entry> value; + + @PUT + @Message({}) + public void selectAndAttackA(@FormParam("t") int t, @FormParam("g") int g, @FormParam("b") List> b, @FormParam("a") int a) throws JsonProcessingException { + this.value = new AbstractMap.SimpleEntry<>((b.get(t).getKey() == g), new AbstractMap.SimpleEntry<>(t, a)); + Form form = new Form(); + form.param("resultBySelectingA", new ObjectMapper().writeValueAsString(this.value)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/handsA/resultBySelectingA").request().post(entity, String.class); + form = new Form(); + form.param("resultBySelectingA", new ObjectMapper().writeValueAsString(this.value)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/handsB/resultBySelectingA").request().post(entity, String.class); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry> getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/ResultBySelectingB.java b/src/main/java/algoLike/pull/ResultBySelectingB.java index 7c62a32..42b6279 100644 --- a/src/main/java/algoLike/pull/ResultBySelectingB.java +++ b/src/main/java/algoLike/pull/ResultBySelectingB.java @@ -1,42 +1,49 @@ -package algoLike.push; +package algoLike.pull; -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 org.springframework.stereotype.Repository; +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.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; + @Path("/resultBySelectingB") @Component @Resource("resultBySelecting") public class ResultBySelectingB { - private Client client = ClientBuilder.newClient(); - @State - private Map.Entry> value; - @PUT - @Message({}) - public void selectAndAttackB(@FormParam("t") int t, @FormParam("g") int g, @FormParam("a") List> a, @FormParam("atk") int atk) throws JsonProcessingException { - this.value = new AbstractMap.SimpleEntry<>((a.get(t).getKey()==g), new AbstractMap.SimpleEntry<>(t, atk) ); - Form form = new Form(); - form.param("resultBySelectingB", new ObjectMapper().writeValueAsString(this.value)); - Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path("/handsB/resultBySelectingB").request().post(entity, String.class); - form = new Form(); - form.param("resultBySelectingB", new ObjectMapper().writeValueAsString(this.value)); - entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - result = client.target("http://localhost:8080").path("/handsA/resultBySelectingB").request().post(entity, String.class); - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public Map.Entry> getValue() { - return value; - } + private final Client client = ClientBuilder.newClient(); + @State + private Map.Entry> value; + + @PUT + @Message({}) + public void selectAndAttackB(@FormParam("t") int t, @FormParam("g") int g, @FormParam("a") List> a, @FormParam("atk") int atk) throws JsonProcessingException { + this.value = new AbstractMap.SimpleEntry<>((a.get(t).getKey() == g), new AbstractMap.SimpleEntry<>(t, atk)); + Form form = new Form(); + form.param("resultBySelectingB", new ObjectMapper().writeValueAsString(this.value)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/handsB/resultBySelectingB").request().post(entity, String.class); + form = new Form(); + form.param("resultBySelectingB", new ObjectMapper().writeValueAsString(this.value)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/handsA/resultBySelectingB").request().post(entity, String.class); + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry> getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/TargetA.java b/src/main/java/algoLike/pull/TargetA.java index 3a4d297..6860b01 100644 --- a/src/main/java/algoLike/pull/TargetA.java +++ b/src/main/java/algoLike/pull/TargetA.java @@ -1,32 +1,31 @@ -package algoLike.push; +package algoLike.pull; -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.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + @Path("/targetA") @Component @Resource("targetA") public class TargetA { - @State - private int value; - @PUT - @Message({}) - public void setTargetA(@FormParam("a") int a) { - this.value = a; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public int getValue() { - return value; - } + @State + private int value; + + @PUT + @Message({}) + public void setTargetA(@FormParam("a") int a) { + this.value = a; + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public int getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/algoLike/pull/TargetB.java b/src/main/java/algoLike/pull/TargetB.java index 34df139..2763b33 100644 --- a/src/main/java/algoLike/pull/TargetB.java +++ b/src/main/java/algoLike/pull/TargetB.java @@ -1,32 +1,31 @@ -package algoLike.push; +package algoLike.pull; -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.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + @Path("/targetB") @Component @Resource("targetB") public class TargetB { - @State - private int value; - @PUT - @Message({}) - public void setTargetB(@FormParam("b") int b) { - this.value = b; - } - @Produces(MediaType.APPLICATION_JSON) - @GET - @Getter - public int getValue() { - return value; - } + @State + private int value; + + @PUT + @Message({}) + public void setTargetB(@FormParam("b") int b) { + this.value = b; + } + + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public int getValue() { + return value; + } } \ No newline at end of file