Newer
Older
algoLike.pull / src / main / java / algoLike / pull / LoseA.java
Shinji on 25 Jan 2023 1 KB pullに変更
package algoLike.pull;
import java.util.*;
import java.util.stream.Collectors;
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;

import javax.ws.rs.client.*;
import pushPullRefactor.PullReference;
import pushPullRefactor.Pushable;

@Path("/loseA")
@Component
@Resource("loseA")
public class LoseA {
    private Client client = ClientBuilder.newClient();

    @PullReference("handsA")
    @Pushable
    String handsA= "/handsA";
    @Produces(MediaType.APPLICATION_JSON)
    @GET
    @Getter
    public boolean getValue() {
        List<Map<String, Boolean>> handsA_json = client.target("http://localhost:8080").path(this.handsA).request().get(ArrayList.class);
        List<Map.Entry<Integer,Boolean>> handsA = new ArrayList<>();
        for (Map<String, Boolean> i: handsA_json) {
            handsA.add(new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue()));
        }
        return (handsA.stream().filter(item -> item.getValue() == false).collect(Collectors.toList()).size() == 0);
    }
}