package com.atlassian.stash.internal.hazelcast;

import com.google.common.collect.ImmutableSet;
import com.hazelcast.core.Member;
import com.hazelcast.core.MemberSelector;

import java.util.Collections;
import java.util.Set;

/**
 * Matches one or more cluster member by ID
 */
public class NodeIdMemberSelector implements MemberSelector {

    private final Set<String> nodeIds;

    public NodeIdMemberSelector(String nodeId) {
        this(Collections.singleton(nodeId));
    }

    public NodeIdMemberSelector(Iterable<String> nodeIds) {
        this.nodeIds = ImmutableSet.copyOf(nodeIds);
    }

    @Override
    public boolean select(Member member) {
        return nodeIds.contains(member.getUuid());
    }
}
