diff --git a/src/main/java/algoLike/push/HandsA.java b/src/main/java/algoLike/push/HandsA.java new file mode 100644 index 0000000..d3c1d5f --- /dev/null +++ b/src/main/java/algoLike/push/HandsA.java @@ -0,0 +1,128 @@ +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.*; + +@Path("/handsA") +@Resource("handsA") +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 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; + } + value = temp_if17; + + 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); + } + + @Message({}) + public void updateResultByDrawingA(Map.Entry resultByDrawingA, + List> deck) throws JsonProcessingException { + this.resultByDrawingA = resultByDrawingA; + List> temp_if18; + 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; + } 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; + } + value = temp_if18; + + 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); + } + + @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; + } else { + temp_if20 = this.value; + } + value = temp_if20; + + 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); + } + + @Message({}) + public void updateResultBySelectingA(Map.Entry> resultBySelectingA) + throws JsonProcessingException { + this.resultBySelectingA = resultBySelectingA; + List> temp_if21; + if (resultBySelectingA.getKey()) { + temp_if21 = this.value; + } else { + this.value.set(resultBySelectingA.getValue().getValue(), new AbstractMap.SimpleEntry<>( + this.value.get(resultBySelectingA.getValue().getValue()).getKey(), true)); + temp_if21 = this.value; + } + value = temp_if21; + + 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; + } +} \ No newline at end of file