
/**
 * The PartsNumber class is used by a Peer that has requested a resource from another peer.
 * Since it knows the resource size in bytes and the number of bytes per part 
 * (except for the last part), it is able to calculate the number of parts it 
 * will need to get from that other peer in order to have the complete resource (file).
 * 
 * The Peer is going to request a part periodically, but, since it is IP, it doesn't know 
 * if that request will arrive of if that part will be received. So, it keeps track of the 
 * parts it has received using the values in range thing.
 * 
 * It continues to get missing part numbers from the values in range and keeps updating 
 * the values in range when it receives parts until all parts have been received.


I am still confused about the getBytes method because you only know the total number of parts missing and not the individual part numbers
 * 
 * 
 * */


public class PartNumbers
{
	/*
	Courtney Karppi
	CISC 370 - GossipProtocol
	May 11, 2015

	Class Variables:
		numberOfParts
			An int containing the total number of parts
		numberOfPartsMissing
			An int containg the total number of missing parts
	Constructors:
		PartNumbers(int numberOfParts)
			sets the instance variable numberOfParts
	Methods:
		public int get()
			Returns the instance variable numberOfParts
		public static byte[] getBytes(int size)

		public static int getLengthInBytes()
			Returns 4
		public int numberOfMissingParts()
			Returns the instance variable numberOfPartsMissing
	*/
	private int numberOfParts;
	private int numberOfPartsMissing;

	public PartNumbers(int numberOfParts)
	{
		if(numberOfParts>0)
		{
			this.numberOfParts = numberOfParts;
		}
	}//constructor

	public int get()
	{
		//Returns the instance variable numberOfParts
		return this.numberOfParts;
	}//get

//CONFUSED ON THIS
	public static byte[] getBytes(int size)
	{
		//
		byte[]	array;

		array = new byte[size];

		return array;
	}//getBytes()
	/*
		public static boolean[] getBytes(int size)
	{
		//
		boolean[]	array;

		array = new boolean[size];
		for(int i=0; i<size; i++)
		{
			array[i] = false;
		}

		return array;
	}//getBytes()
	*/
	public static int getLengthInBytes()
	{
		//Returns 4
		return 4;
	}//getLengthInBytes

	public int numberOfMissingParts()
	{
		//Returns the instance variable numberOfPartsMissing
		return this.numberOfPartsMissing;
	}//numberOfMissingParts

}//class

@@ -1,923 +1,4 @@
-%0A/**%0A * The PartsNumber class is used by a Peer that has requested a resource from another peer.%0A * Since it knows the resource size in bytes and the number of bytes per part %0A * (except for the last part), it is able to calculate the number of parts it %0A * will need to get from that other peer in order to have the complete resource (file).%0A * %0A * The Peer is going to request a part periodically, but, since it is IP, it doesn't know %0A * if that request will arrive of if that part will be received. So, it keeps track of the %0A * parts it has received using the values in range thing.%0A * %0A * It continues to get missing part numbers from the values in range and keeps updating %0A * the values in range when it receives parts until all parts have been received.%0A%0A%0AI am still confused about the getBytes method because you only know the total number of parts missing and not the individual part numbers%0A * %0A * %0A * */%0A%0A%0A
 publ
@@ -543,41 +543,28 @@
 s()%0A
-%09%09%09Returns the instance variable 
+%0A%09*/%0A%09private int %09%09
 numb
@@ -576,20 +576,12 @@
 arts
-Missing%0A%09*/%0A
+;%0A//
 %09pri
@@ -581,32 +581,34 @@
 %0A//%09private int 
+%09%09
 numberOfParts;%0A%09
@@ -608,151 +608,356 @@
 arts
-;%0A%09private int numberOfPartsMissing;%0A%0A%09public PartNumbers(int numberOfParts)%0A%09%7B%0A%09%09if(numberOfParts%3E0)%0A%09%09%7B%0A%09%09%09this.numberOfParts = numberOfParts
+Missing;%0A// everything in the boolean%5B%5D is set to false whenever the object is created%0A%0A%09private boolean%5B%5D%09partsReceived;%0A%0A%09public PartNumbers(int numberOfParts)%0A%09%7B%0A%09%09if(numberOfParts%3E0)%0A%09%09%7B%0A%09%09%09this.numberOfParts = numberOfParts;%0A%09%09%7D%0A%09%09partsReceived = new boolean%5BnumberOfParts%5D;%0A%09%09for(int i=0; i%3CnumberOfParts; i++)%0A%09%09%7B%0A%09%09%09partsReceived%5Bi%5D = false
 ;%0A%09%09
@@ -1086,329 +1086,224 @@
 et%0A%0A
+%0A
 //
-CONFUSED ON THIS%0A%09public static byte%5B%5D getBytes(int size)%0A%09%7B%0A%09%09//%0A%09%09byte%5B%5D%09array;%0A%0A%09%09array = new byte%5Bsize%5D;%0A%0A%09%09return array;%0A%09%7D//getBytes()%0A%09/*%0A%09%09public static boolean%5B%5D getBytes(int size)%0A%09%7B%0A%09%09//%0A%09%09boolean%5B%5D%09array;%0A%0A%09%09array = new boolean%5Bsize%5D;%0A%09%09for(int i=0; i%3Csize; i++)%0A%09%09%7B%0A%09%09%09array%5Bi%5D = false;%0A%09%09%7D%0A%0A%09%09return array
+after each part number is recieved, you then call this to change it to true(received)%0A%09public boolean%5B%5D getBytes(int numberReceived)%0A%09%7B%0A%09%09//%0A%09%09this.partsReceived%5BnumberReceived%5D = true;%0A%09%09return this.partsReceived
 ;%0A%09%7D
@@ -1315,19 +1315,16 @@
 Bytes()%0A
-%09*/
 %0A%09public
@@ -1316,39 +1316,32 @@
 ytes()%0A%0A%09public 
-static 
 int getLengthInB
@@ -1442,95 +1442,185 @@
 %7B%0A%09%09
-//Returns the instance variable numberOf
+int missingParts;%0A%09%09missingParts = 0;%0A%09%09for(int i=0; i%3Cget(); i++)%0A%09%09%7B%0A%09%09%09if(this.partsReceived%5Bi%5D==false)%0A%09%09%09%7B%0A%09%09%09%09missing
 Parts
-M
+ = m
 issing
-%0A%09%09return this.numberOfPartsMissing
+Parts+1;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return missingParts
 ;%0A%09%7D

Update PartNumbers.java