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; import pushPullRefactor.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; @Path("/handsA") @Resource("handsA") @Component public class HandsA { private Client client = ClientBuilder.newClient(); private Map.Entry<Boolean, Integer> resultByDrawingA; private Map.Entry<Boolean, Integer> resultByDrawingB; private Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingA; private Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingB; @State private List<Map.Entry<Integer, Boolean>> value = new ArrayList<Map.Entry<Integer, Boolean>>(); @Path("/resultByDrawingA") @POST @Message({}) public void updateResultByDrawingA(@FormParam("resultByDrawingA") String resultByDrawingA_json, @FormParam("deck") List<String> deck_json) throws JsonProcessingException { List<Map.Entry<Integer, Boolean>> deck = new ArrayList<>(); for (String str: deck_json) { Map<Integer, Boolean> i = new ObjectMapper().readValue(str, HashMap.class); deck.add(i.entrySet().iterator().next()); } Map.Entry<Boolean, Integer> resultByDrawingA; { Map<String, Integer> 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<Map.Entry<Integer, Boolean>> temp_if2; if (resultByDrawingA.getKey()) { this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false)); this.value.sort(Comparator.comparing(Map.Entry<Integer, Boolean>::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<Integer, Boolean>::getKey)); temp_if2 = this.value; } this.value = temp_if2; Form form = new Form(); for (Map.Entry<Integer, Boolean> i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); } @Path("/resultByDrawingB") @POST @Message({}) public void updateResultByDrawingB(@FormParam("resultByDrawingB") String resultByDrawingB_json, @FormParam("deck") List<String> deck_json) throws JsonProcessingException { List<Map.Entry<Integer, Boolean>> deck = new ArrayList<>(); for (String str: deck_json) { Map<Integer, Boolean> i = new ObjectMapper().readValue(str, HashMap.class); deck.add(i.entrySet().iterator().next()); } Map.Entry<Boolean, Integer> resultByDrawingB; { Map<String, Integer> 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<Map.Entry<Integer, Boolean>> 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; Form form = new Form(); for (Map.Entry<Integer, Boolean> i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); } @Path("/resultBySelectingA") @POST @Message({}) public void updateResultBySelectingA(@FormParam("resultBySelectingA") String resultBySelectingA_json) throws JsonProcessingException { Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingA; { Map<String, Map<String, Integer>> 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<Map.Entry<Integer, Boolean>> 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; Form form = new Form(); for (Map.Entry<Integer, Boolean> i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/loseA").request().put(entity, String.class); } @Path("/resultBySelectingB") @POST @Message({}) public void updateResultBySelectingB(@FormParam("resultBySelectingB") String resultBySelectingB_json) throws JsonProcessingException { Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingB; { Map<String, Map<String, Integer>> 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<Map.Entry<Integer, Boolean>> 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<Integer, Boolean> i: this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> 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<Map.Entry<Integer, Boolean>> getValue() { return value; } }