/**
  * @author Anaaktge
  */

import java.io.*;
import java.util.*;

public class Node{

		public boolean isUsing;
		public ArrayList friends;
		public double prob;
		// distance to start node
		public  int distToMaven;
		
		public Node(double  myprob, int numNodes)
		{
			// an impossible distance 
			distToMaven = -1 ;
			friends = new ArrayList(numNodes);
			prob = myprob;
			isUsing = false;
		}

	public String toString()
	{
		return "Node -"+isUsing +" numfriends " + friends.size() + "prob is"
			+prob +"distToMaven" +distToMaven+ ">"; 
	}
		/** @brief run rand to see if this node adopts, ret T if so */
		public boolean willAdopt()
		{
	
			//		 set isUsing T
			// walk through friends looking for distance to lowest, non neg dist to maven 
		
			double considerIdea = Math.random();

			// will convert
			if(considerIdea <= prob)
			{
				isUsing = true;
				int lowestDist = ((Node)probControlNetwork.network.get(((Integer)friends.get(0)).intValue())).distToMaven;

				for(int i = 0; i< this.friends.size(); i++)
				{
					int temp =
						((Node)probControlNetwork.network.get(((Integer)friends.get(i)).intValue())).distToMaven;
					if((temp >= 0) && (temp < lowestDist))
					{
						lowestDist = temp;
					}
				// the friend of yours with the shortest path
				// +1 for their link to you 
				this.distToMaven = lowestDist + 1;
				}
				return true;
			}

			// nah, not this time 
			return false;
		}
}

