Newer
Older
algoLike.pull / src / main / java / algoLike / pull / HandsA.java
Shinji on 25 Jan 2023 6 KB pullに変更
package algoLike.pull;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Component;
import pushPullRefactor.Getter;
import pushPullRefactor.Message;
import pushPullRefactor.Resource;
import pushPullRefactor.State;

import javax.ws.rs.*;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
import java.util.*;

@Path("/handsA")
@Resource("handsA")
@Component
public class HandsA {
    private final 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({"resultByDrawingA", "deck"})
    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;

    }

    @Path("/resultByDrawingB")
    @POST
    @Message({"resultByDrawingB", "deck"})
    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;

    }

    @Path("/resultBySelectingA")
    @POST
    @Message({"resultBySelecting"})
    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;

    }

    @Path("/resultBySelectingB")
    @POST
    @Message({"resultBySelectingB"})
    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;

    }

    @Produces(MediaType.APPLICATION_JSON)
    @GET
    @Getter
    public List<Map.Entry<Integer, Boolean>> getValue() {
        return value;
    }
}