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

import org.springframework.stereotype.Component;
import pushPullRefactor.Getter;
import pushPullRefactor.PullReference;
import pushPullRefactor.Pushable;
import pushPullRefactor.Resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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

    @PullReference("handsA")
    @Pushable
    private final 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);
    }
}