Newer
Older
algoLike.push / src / main / java / algoLike / push / LoseA.java
Shinji on 23 Jan 2023 1 KB HandsAとLoseAのみ追加
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;

@Path("/loseA")
@Resource("loseA")
public class LoseA {
	@State
	private boolean value;

	@PUT
	@Message({"handsA"})
	public void updateHandsA(@FormParam("handsA") List<String> handsA_json) throws JsonProcessingException {
		List<Map.Entry<Integer, Boolean>> handsA = new ArrayList<>();
		for (String str : handsA_json) {
			Map<String, Boolean> i = new ObjectMapper().readValue(str, HashMap.class);
			handsA.add(new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getKey()),
					i.entrySet().iterator().next().getValue()));
		}
		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;
	}
}