Java Reference
In-Depth Information
public class DayLog {
public static final int MIN_TIME = 6 * 60;
public static final int MAX_TIME = 22 * 60;
public static final int MIN_VALUE = 40;
public static final int MAX_VALUE = 280;
public static final int MIN_BORDER = 70;
public static final int MAX_BORDER = 160;
int date; // yymd per byte
Vector entries = new Vector();
class Entry {
int time; // minutes since midnight
int value;
}
}
For creating new DayLog s, a constructor, initializing the structure with the given date, is required:
public DayLog (int date) {
this.date = date;
}
In order to fill the structure with data, a set method, adding a new entry, is needed. The following
method adds a new entry with respect to the correct time ordering of the entries. If an entry for the
given point of time already exists, it is overwritten:
public void set (int minutes, int value) {
Entry entry = new Entry();
entry.time = minutes;
entry.value = value;
for (int i = getCount()-1; i >= 0; i--) {
int minutesI = getTime (i);
if (minutes <= minutesI) {
if (minutes == minutesI)
entries.setElementAt (entry, i);
else
entries.insertElementAt (entry, i+1);
return;
}
}
entries.insertElementAt (entry, 0);
}
Storing information in the day log data structure does not make sense if the information cannot be read
back. Thus, we add access methods for the date, the number of entries, and the time and value of an
entry at a given index:
public int getDate() {
return date;
}
public int getCount() {
return entries.size();
Search WWH ::




Custom Search