diff --git a/src/main/java/algoLike/push/AttackerA.java b/src/main/java/algoLike/push/AttackerA.java new file mode 100644 index 0000000..5bd76a8 --- /dev/null +++ b/src/main/java/algoLike/push/AttackerA.java @@ -0,0 +1,24 @@ +package algoLike.push; + +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; + +@Path("/attackerA") +@Component +public class AttackerA { + private int value; + @PUT + public void setAttackerA(@FormParam("a") int a) { + this.value = a; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/AttackerB.java b/src/main/java/algoLike/push/AttackerB.java new file mode 100644 index 0000000..217b861 --- /dev/null +++ b/src/main/java/algoLike/push/AttackerB.java @@ -0,0 +1,24 @@ +package algoLike.push; + +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; + +@Path("/attackerB") +@Component +public class AttackerB { + private int value; + @PUT + public void setAttackerB(@FormParam("b") int b) { + this.value = b; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/Deck.java b/src/main/java/algoLike/push/Deck.java new file mode 100644 index 0000000..88c9162 --- /dev/null +++ b/src/main/java/algoLike/push/Deck.java @@ -0,0 +1,48 @@ +package algoLike.push; + +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; + +@Path("/deck") +@Component +public class Deck { + private Map.Entry resultByDrawingA; + private Map.Entry resultByDrawingB; + private List> value = new ArrayList>(); + @Path("/resultByDrawingA") + @POST + 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 + 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 + public List> getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/GuessA.java b/src/main/java/algoLike/push/GuessA.java new file mode 100644 index 0000000..9e31cf3 --- /dev/null +++ b/src/main/java/algoLike/push/GuessA.java @@ -0,0 +1,24 @@ +package algoLike.push; + +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; + +@Path("/guessA") +@Component +public class GuessA { + private int value = 0; + @PUT + public void setGuessA(@FormParam("a") int a) { + this.value = a; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/GuessB.java b/src/main/java/algoLike/push/GuessB.java new file mode 100644 index 0000000..efa8856 --- /dev/null +++ b/src/main/java/algoLike/push/GuessB.java @@ -0,0 +1,24 @@ +package algoLike.push; + +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; + +@Path("/guessB") +@Component +public class GuessB { + private int value = 0; + @PUT + public void setGuessB(@FormParam("b") int b) { + this.value = b; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/HandsA.java b/src/main/java/algoLike/push/HandsA.java index d3c1d5f..10e7bf4 100644 --- a/src/main/java/algoLike/push/HandsA.java +++ b/src/main/java/algoLike/push/HandsA.java @@ -1,127 +1,133 @@ package algoLike.push; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -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.*; +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; @Path("/handsA") -@Resource("handsA") +@Component public class HandsA { - private Map.Entry resultByDrawingB; - private Map.Entry resultByDrawingA; - private Map.Entry> resultBySelectingB; - private Map.Entry> resultBySelectingA; private Client client = ClientBuilder.newClient(); - - @PushReference("loseA") - @Pullable("direct") - private String loseA = "/loseA"; - - @State + private Map.Entry resultByDrawingA; + private Map.Entry resultByDrawingB; + private Map.Entry> resultBySelectingA; + private Map.Entry> resultBySelectingB; private List> value = new ArrayList>(); - - @Message({}) - - public void updateResultByDrawingB(@FormParam("result") Map.Entry resultByDrawingB) - throws JsonProcessingException { - this.resultByDrawingB = resultByDrawingB; - List> temp_if17; - if (resultByDrawingB.getKey()) { - this.value.set(resultByDrawingB.getValue(), - new AbstractMap.SimpleEntry<>(this.value.get(resultByDrawingB.getValue()).getKey(), true)); - temp_if17 = this.value; - } else { - temp_if17 = this.value; + @Path("/resultByDrawingA") + @POST + 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()); } - value = temp_if17; - - Form form = new Form(); - for (Map.Entry i : this.value) { - form.param("handsA", new ObjectMapper().writeValueAsString(i)); + 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()); } - Entity
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); - } - - @Message({}) - public void updateResultByDrawingA(Map.Entry resultByDrawingA, - List> deck) throws JsonProcessingException { this.resultByDrawingA = resultByDrawingA; - List> temp_if18; + 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_if18 = this.value; + 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_if18 = this.value; + this.value.sort(Comparator.comparing(Map.Entry::getKey)); + temp_if2 = this.value; } - value = temp_if18; - + this.value = temp_if2; Form form = new Form(); - for (Map.Entry i : this.value) { + for (Map.Entry i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); + String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); } - - @Message({}) - public void updateResultBySelectingB(Map.Entry> resultBySelectingB) - throws JsonProcessingException { - this.resultBySelectingB = resultBySelectingB; - List> temp_if20; - if (resultBySelectingB.getKey()) { - this.value.set(resultBySelectingB.getValue().getKey(), new AbstractMap.SimpleEntry<>( - this.value.get(resultBySelectingB.getValue().getKey()).getKey(), true)); - temp_if20 = this.value; + @Path("/resultByDrawingB") + @POST + 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_if20 = this.value; + temp_if3 = this.value; } - value = temp_if20; - + this.value = temp_if3; Form form = new Form(); - for (Map.Entry i : this.value) { + for (Map.Entry i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); + String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); } - - @Message({}) - public void updateResultBySelectingA(Map.Entry> resultBySelectingA) - throws JsonProcessingException { + @Path("/resultBySelectingA") + @POST + 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_if21; + List> temp_if4; if (resultBySelectingA.getKey()) { - temp_if21 = this.value; + temp_if4 = this.value; } else { - this.value.set(resultBySelectingA.getValue().getValue(), new AbstractMap.SimpleEntry<>( - this.value.get(resultBySelectingA.getValue().getValue()).getKey(), true)); - temp_if21 = this.value; + this.value.set(resultBySelectingA.getValue().getValue(),new AbstractMap.SimpleEntry<>(this.value.get(resultBySelectingA.getValue().getValue()).getKey(), true)); + temp_if4 = this.value; } - value = temp_if21; - + this.value = temp_if4; Form form = new Form(); - for (Map.Entry i : this.value) { + for (Map.Entry i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); + String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); } - + @Path("/resultBySelectingB") + @POST + 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; + Form form = new Form(); + for (Map.Entry i: this.value) { + form.param("handsA", new ObjectMapper().writeValueAsString(i)); + } + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); + } @Produces(MediaType.APPLICATION_JSON) @GET - @Getter public List> getValue() { return value; } diff --git a/src/main/java/algoLike/push/HandsB.java b/src/main/java/algoLike/push/HandsB.java new file mode 100644 index 0000000..4031a73 --- /dev/null +++ b/src/main/java/algoLike/push/HandsB.java @@ -0,0 +1,134 @@ +package algoLike.push; + +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; + +@Path("/handsB") +@Component +public class HandsB { + private Client client = ClientBuilder.newClient(); + private Map.Entry resultByDrawingB; + private Map.Entry resultByDrawingA; + private Map.Entry> resultBySelectingB; + private Map.Entry> resultBySelectingA; + private List> value = new ArrayList>(); + @Path("/resultByDrawingB") + @POST + 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 + 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 + 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 + 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 + public List> getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/LoseA.java b/src/main/java/algoLike/push/LoseA.java index f750321..05a1ca3 100644 --- a/src/main/java/algoLike/push/LoseA.java +++ b/src/main/java/algoLike/push/LoseA.java @@ -1,44 +1,29 @@ package algoLike.push; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -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 java.util.stream.Collectors; - -import pushPullRefactor.PullReference; -import pushPullRefactor.Pushable; +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; @Path("/loseA") -@Resource("loseA") +@Component public class LoseA { - @State private boolean value; - @PUT - @Message({"handsA"}) public void updateHandsA(@FormParam("handsA") List handsA_json) throws JsonProcessingException { List> handsA = new ArrayList<>(); - for (String str : handsA_json) { - Map i = new ObjectMapper().readValue(str, HashMap.class); - handsA.add(new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getKey()), - i.entrySet().iterator().next().getValue())); + for (String str: handsA_json) { + Map i = new ObjectMapper().readValue(str, HashMap.class); + handsA.add(i.entrySet().iterator().next()); } - this.value = (handsA.stream().filter(item -> item.getValue() == false).collect(Collectors.toList()) - .size() == 0); + this.value = (handsA.stream().filter(item -> item.getValue()==false).collect(Collectors.toList()).size()==0); } - @Produces(MediaType.APPLICATION_JSON) @GET - @Getter public boolean getValue() { return value; } diff --git a/src/main/java/algoLike/push/LoseB.java b/src/main/java/algoLike/push/LoseB.java new file mode 100644 index 0000000..ae0fff5 --- /dev/null +++ b/src/main/java/algoLike/push/LoseB.java @@ -0,0 +1,30 @@ +package algoLike.push; + +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; + +@Path("/loseB") +@Component +public class LoseB { + private boolean value; + @PUT + 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 + public boolean getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/ResultByDrawingA.java b/src/main/java/algoLike/push/ResultByDrawingA.java new file mode 100644 index 0000000..8917448 --- /dev/null +++ b/src/main/java/algoLike/push/ResultByDrawingA.java @@ -0,0 +1,48 @@ +package algoLike.push; + +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; + +@Path("/resultByDrawingA") +@Component +public class ResultByDrawingA { + private Client client = ClientBuilder.newClient(); + private Map.Entry value; + @PUT + 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 + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/ResultByDrawingB.java b/src/main/java/algoLike/push/ResultByDrawingB.java new file mode 100644 index 0000000..49a1944 --- /dev/null +++ b/src/main/java/algoLike/push/ResultByDrawingB.java @@ -0,0 +1,48 @@ +package algoLike.push; + +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; + +@Path("/resultByDrawingB") +@Component +public class ResultByDrawingB { + private Client client = ClientBuilder.newClient(); + private Map.Entry value; + @PUT + 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 + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/ResultBySelectingA.java b/src/main/java/algoLike/push/ResultBySelectingA.java new file mode 100644 index 0000000..1e724ef --- /dev/null +++ b/src/main/java/algoLike/push/ResultBySelectingA.java @@ -0,0 +1,33 @@ +package algoLike.push; + +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; + +@Path("/resultBySelectingA") +@Component +public class ResultBySelectingA { + private Client client = ClientBuilder.newClient(); + private Map.Entry> value; + @PUT + 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 + public Map.Entry> getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/ResultBySelectingB.java b/src/main/java/algoLike/push/ResultBySelectingB.java new file mode 100644 index 0000000..4aac012 --- /dev/null +++ b/src/main/java/algoLike/push/ResultBySelectingB.java @@ -0,0 +1,33 @@ +package algoLike.push; + +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; + +@Path("/resultBySelectingB") +@Component +public class ResultBySelectingB { + private Client client = ClientBuilder.newClient(); + private Map.Entry> value; + @PUT + 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 + public Map.Entry> getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/TargetA.java b/src/main/java/algoLike/push/TargetA.java new file mode 100644 index 0000000..72e2406 --- /dev/null +++ b/src/main/java/algoLike/push/TargetA.java @@ -0,0 +1,24 @@ +package algoLike.push; + +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; + +@Path("/targetA") +@Component +public class TargetA { + private int value; + @PUT + public void setTargetA(@FormParam("a") int a) { + this.value = a; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/algoLike/push/TargetB.java b/src/main/java/algoLike/push/TargetB.java new file mode 100644 index 0000000..04a58de --- /dev/null +++ b/src/main/java/algoLike/push/TargetB.java @@ -0,0 +1,24 @@ +package algoLike.push; + +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; + +@Path("/targetB") +@Component +public class TargetB { + private int value; + @PUT + public void setTargetB(@FormParam("b") int b) { + this.value = b; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getValue() { + return value; + } +} \ No newline at end of file