package cuckoomodel;

import java.util.ArrayList;
import java.util.List;

public class Interval {

	private final List<Node> peers = new ArrayList<Node>();
	
	private final Network network;

	
	public Interval(Network net) {
		this.network = net;
	}
	/**
	 * @param e
	 * @return
	 * @see java.util.List#add(java.lang.Object)
	 */
	public boolean add(Node e) {
		return peers.add(e);
	}

	/**
	 * @param o
	 * @return
	 * @see java.util.List#remove(java.lang.Object)
	 */
	public boolean remove(Object o) {
		return peers.remove(o);
	}

	public List<Node> getPeers() {
		return peers;
	}
	
	
	/**
	 * @return the network
	 */
	public Network getNetwork() {
		return network;
	}
	
	public int getNumberOfPeers() {
		return peers.size();
	}
	
	public int getEvilPeers() {
		int i = 0;
		for (Node n: peers) {
			if (n.isEvil()) {
				i++;
			}
		}
		return i;
	}
	
	public int getGoodPeers() {
		return getNumberOfPeers() - getEvilPeers();
	}
	
	public boolean isCompromised() {
		
		return getNumberOfPeers() != 0 && getEvilPeers() >= getGoodPeers();
	}
	
}
