edu.rice.comp211.laundry.list
Class BiListUtil

java.lang.Object
  extended by edu.rice.comp211.laundry.list.BiListUtil

public class BiListUtil
extends Object

Singleton class holding the utility methods on BiLists used in the Laundry Simulation.


Field Summary
static BiListUtil ONLY
          Singleton instance
 
Method Summary
<T> boolean
delete(BiListI<T> host, T elt)
          Deletes the first occurrence of elt from host.
<T> T
deleteMatchFront(BiListI<T> host, Predicate<T> pred, T nullValue)
          Delete the first occurrence of an element for which the given Predicate returns true.
<T> T
deleteMatchRear(BiListI<T> host, Predicate<T> pred, T nullValue)
          Delete the first occurrence of an element for which the given Predicate returns true.
<T> boolean
mapDelete(BiListI<BiListI<T>> host, T elt)
          Deletes the first occurrence of elt in each list (of type BiList) in host.
<T> BiListI<T>
remListFront(BiListI<T> host, int size)
          Removes the first size elements from host and returns them as the result.
<T> String
toStringWithCommas(BiListI<T> host)
          Generates a string representation for host with items separated by ", " and no leading or trailing text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONLY

public static final BiListUtil ONLY
Singleton instance

Method Detail

delete

public <T> boolean delete(BiListI<T> host,
                          T elt)
Deletes the first occurrence of elt from host.

Type Parameters:
T - the type of the element being deleted -- inferred from host and elt.
Parameters:
host - the list to delete from
the - element to delete
Returns:
true if the element was deleted, false otherwise

mapDelete

public <T> boolean mapDelete(BiListI<BiListI<T>> host,
                             T elt)
Deletes the first occurrence of elt in each list (of type BiList) in host.

Type Parameters:
T - the type of element that is being deleted -- inferred from host and elt
Parameters:
host - the list to delete from
elt - the element to delete
Returns:
true if the element was deleted, false otherwise

deleteMatchFront

public <T> T deleteMatchFront(BiListI<T> host,
                              Predicate<T> pred,
                              T nullValue)
Delete the first occurrence of an element for which the given Predicate returns true. The list is searched from the front to the rear. Returns the the removed element or the given nullValue if not found.

Type Parameters:
T - The type of element to be removed -- inferred from host, pred and nullValue
Parameters:
host - the list to delete from
pred - the Predicate to use
nullValue - the value used to represent not finding an element to delete.
Returns:
the removed element or nullValue if nothing found.

deleteMatchRear

public <T> T deleteMatchRear(BiListI<T> host,
                             Predicate<T> pred,
                             T nullValue)
Delete the first occurrence of an element for which the given Predicate returns true. The list is searched from the rear to the front. Returns the the removed element or the given nullValue if not found.

Type Parameters:
T - The type of element to be removed -- inferred from host, pred and nullValue
Parameters:
host - the list to delete from
pred - the Predicate to use
nullValue - the value used to represent not finding an element to delete.
Returns:
the removed element or nullValue if nothing found.

remListFront

public <T> BiListI<T> remListFront(BiListI<T> host,
                                   int size)
Removes the first size elements from host and returns them as the result. If size elements are not available, it removes and returns the elements that are available.

Type Parameters:
T - the type of elements to remove -- inferred from host
Parameters:
host - the list to remove from
size - the maximum number of elements to remove
Returns:
a BiList of the removed elements, in their original order

toStringWithCommas

public <T> String toStringWithCommas(BiListI<T> host)
Generates a string representation for host with items separated by ", " and no leading or trailing text.

Type Parameters:
T - the type of elements being processed -- inferred from host
Parameters:
host - the list to process
Returns:
the string representation of the list.