scheduler.generate
Class DayAvail

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector<java.lang.Boolean>
              extended by scheduler.generate.DayAvail
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.lang.Boolean>, java.util.Collection<java.lang.Boolean>, java.util.List<java.lang.Boolean>, java.util.RandomAccess

public class DayAvail
extends java.util.Vector<java.lang.Boolean>

Represents a Days availability.

Author:
Eric Liebowitz
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DayAvail()
          Creates a 48-entry array of availability for a day (one entry for every half-hour in the day).
 
Method Summary
 boolean book(Time fakeStart, Time fakeEnd)
          Books a given time range.
private static java.lang.Object[] compute(Time fakeStart, Time fakeEnd)
          For use when iterating through the vector of availability.
 boolean isFree(Time fakeStart, Time fakeEnd)
          Determines whether a given span of time is free.
 java.lang.String toString()
          Simple way to print out the availability of each time slot in the day.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

DayAvail

public DayAvail()
Creates a 48-entry array of availability for a day (one entry for every half-hour in the day). Sets each slot to "true".
 Post:
 
    //Size must be 48, for each half hour of the day
    this.size() = 48

       &&

    //Each entry is "true"
    for (Boolean b: this)
    {
       b;
    }

Method Detail

book

public boolean book(Time fakeStart,
                    Time fakeEnd)
             throws EndBeforeStartException
Books a given time range. Times are rounded out to take as much time as possible. Thus, a range from from 1:15 to 2:45 will be treated the same as a range from 1:00 to 3:00.
 Pre:
 
    //Can't end before it begins
    fakeEnd.compareTo(fakeStart) > 0

 Post:

    // { Only if "isFree" returned true for "fakeStart" and "fakeEnd" } //
    //Entries corresponding to the half hour slots between fakeStart and
    //fakeEnd (rounded down and rounded up to the nearest half hour, 
    //respectively) must be asserted. Any other slots should remain as they
    //were before the booking
    for (int i = 0; i < this.size(); i ++)
    {
       if (this.get(i) != this'.get(i))
       { 
          startSlot < i < endSlot;
       }
    } 
    //See "compute()" for a break down of how "startSlot" and "endSlot"
    //are computed and used. The logic is too much to put here.

Parameters:
fakeStart - beginning of the time range (not yet rounded)
fakeEnd - end of the time range (not yet rounded)
Returns:
true if the time was free, and thus booked. False otherwise.
Throws:
EndBeforeStartException

isFree

public boolean isFree(Time fakeStart,
                      Time fakeEnd)
               throws EndBeforeStartException
Determines whether a given span of time is free. Times are rounded out to take as much time as possible. Thus, a range from from 1:15 to 2:45 will be treated the same as a range from 1:00 to 3:00.
  Pre:

    //Can't end before it starts
    fakeEnd.compareTo(fakeStart) > 0

 

Parameters:
fakeStart - beginning of the time range (not yet rounded)
fakeEnd - end of the time range (not yet rounded)
Returns:
true if the time was free. False otherwise.
Throws:
EndBeforeStartException

compute

private static java.lang.Object[] compute(Time fakeStart,
                                          Time fakeEnd)
                                   throws EndBeforeStartException
For use when iterating through the vector of availability. Modifies the start and end times to fit on hour and half-hour boundaries. Returns the new start and end times, along with the base hour for iteration and the number of half-hour slots between the start time and the end time.

Parameters:
fakeStart - The start time to modify (round down)
fakeEnd - The end time to modif (round up)
Returns:
An Object array with 4 values: start time, end time, base, and number of slots. Yes, this is a very dirty way of doing it, but it works.
Throws:
EndBeforeStartException

toString

public java.lang.String toString()
Simple way to print out the availability of each time slot in the day.

Overrides:
toString in class java.util.Vector<java.lang.Boolean>