Newer
Older
algoLike.pull / src / main / java / algoLike / pull / HandsB.java
Shinji on 25 Jan 2023 6 KB pullに変更
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.*;

@Path("/handsB")
@Component
@Resource("handsB")
public class HandsB {
	private Client client = ClientBuilder.newClient();
	private Map.Entry<Boolean, Integer> resultByDrawingB;
	private Map.Entry<Boolean, Integer> resultByDrawingA;
	private Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingB;
	private Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingA;
	@State
	private List<Map.Entry<Integer, Boolean>> value = new ArrayList<Map.Entry<Integer, Boolean>>();
	@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<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_if0;
		if (resultByDrawingB.getKey()) {
			this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false));
		this.value.sort(Comparator.comparing(Map.Entry<Integer, Boolean>::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<Integer, Boolean>::getKey));
			temp_if0 = this.value;
		}
		this.value = temp_if0;
		Form form = new Form();
		for (Map.Entry<Integer, Boolean> i: this.value) {
			form.param("handsB", new ObjectMapper().writeValueAsString(i));
		}
		Entity<Form> 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<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_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<Integer, Boolean> i: this.value) {
			form.param("handsB", new ObjectMapper().writeValueAsString(i));
		}
		Entity<Form> 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<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_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<Integer, Boolean> i: this.value) {
			form.param("handsB", new ObjectMapper().writeValueAsString(i));
		}
		Entity<Form> 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<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_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<Integer, Boolean> i: this.value) {
			form.param("handsB", new ObjectMapper().writeValueAsString(i));
		}
		Entity<Form> 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<Map.Entry<Integer, Boolean>> getValue() {
		return value;
	}
}