package cuckoomodel;

import java.util.ArrayList;

public class Node {

	
	private Interval current;
	
	private final boolean evil;
	
	/**
	 * @return the evil
	 */
	public boolean isEvil() {
		return evil;
	}


	public Node(boolean evil) {
		this.evil = evil;
	}
	
	
	public void join(Interval interval,boolean useCuckooRule) {
		if (current != null) {
			leave();
		}
		if (useCuckooRule) {
			for (Node n: new ArrayList<Node>(interval.getPeers())) {
				n.join(interval.getNetwork().getRandomInterval(), false);
			}
		}
		
		this.current = interval;
		interval.add(this);
		
		
	}
	
	
	
	public void leave() {
		if (current == null) {
			throw new IllegalStateException();
		}
		current.remove(this);
		current = null;
	}
	
}
