edu.ntnu.ecosim.agents.consumers
Class FriendList

java.lang.Object
  extended by edu.ntnu.ecosim.agents.consumers.FriendList

public class FriendList
extends java.lang.Object

The Class FriendList. This class is meant as an alternative to ArrayList to save memory. Since the number of consumers can be quite extensive, this class is intended to reduce the memory usage of each consumer.


Constructor Summary
protected FriendList(int maxFriends)
          The Constructor of a friend list.
 
Method Summary
protected  void add(int friend)
          Add one friend to the list.
protected  boolean contains(int friend)
          Method saying whether or not the list contains the specified friend
protected  int get(int place)
          Getter method for the friendlist.
protected  int size()
          Method to get the size of the list
protected  void sortList()
          Method used to sort the list of friends.
protected  int[] toIntegerArray()
          Method to get the list of friends represented as an integer array containing the unique IDs of the friends
protected  void trimList()
          Method to trim the friend list, removing unused length of the array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FriendList

protected FriendList(int maxFriends)
The Constructor of a friend list.

Parameters:
maxFriends - the maximum number of friends allowed in this friendlist
Method Detail

add

protected void add(int friend)
            throws java.lang.IndexOutOfBoundsException
Add one friend to the list.

Parameters:
friend - the friend
Throws:
java.lang.IndexOutOfBoundsException - thrown if the list is full

contains

protected boolean contains(int friend)
Method saying whether or not the list contains the specified friend

Parameters:
friend - the friend
Returns:
true, if contains

get

protected int get(int place)
           throws java.lang.IndexOutOfBoundsException
Getter method for the friendlist.

Parameters:
place - the place where the friend is located
Returns:
an int with the ID of the consumer
Throws:
java.lang.IndexOutOfBoundsException - thrown if the place is out of bounds

size

protected int size()
Method to get the size of the list

Returns:
the number of friends in the list

sortList

protected void sortList()
Method used to sort the list of friends.


toIntegerArray

protected int[] toIntegerArray()
Method to get the list of friends represented as an integer array containing the unique IDs of the friends

Returns:
an integer array containing the uniqe ids of the friends

trimList

protected void trimList()
Method to trim the friend list, removing unused length of the array