// Copyright 1997 Object UK Ltd.
// Author Andrew Carmichael
// Updated Tim Shelley
//
// Date
// Version 0.2
// Email: objectuk@objectuk.co.uk
// Web: http://www.objectuk.co.uk
package ProblemDomain;
// Generated by Together/J
import java.util.*;
/**@version 0.1
@author Tim Shelley
@note This class holds the default methods for the common methods
between the sub-classes.
@stereotype time box*/
public abstract class LifeEvent {
/**@note Notes concerning the LifeEvent.
@shapeType AssociationLink*/
private Note comments;
/**@note Date of LifeEvent */
private Calendar date = Calendar.getInstance();
/** Note: this constructor uses Date not Calendar */
public LifeEvent(String date, String place, String comments) {
this.setDate(date);
this.setPlace(place);
this.setComments(comments);
}
/**@note Returns the data of the life event from the date (Calender)
object.*/
public Date getDate() {
return date.getTime();}
/**@note Sets the date of when the life event took place. Although the
method is passed a Date object, it passes on the time
information to the internal Calendar object called 'date'.*/
public void setDate(Date d) {
this.date.setTime(d);}
public void setDate(String d) {}
/**@note Place of LifeEvent */
private String place = "";
/**@note Returns the place where this life event took place.*/
public String getPlace() {
return this.place;
}
/**@note Set/change the place where the life event took place.
@param s - a short description of place name.*/
public void setPlace(String s) {
this.place = s;
}
/**@note Get the comments (Note object) associated with this object.
@return String - representing the comments return by the Note object*/
public String getComments() {
return this.comments.getComments();}
public abstract String getTextRecordIdentifier();
/**@note Setting the comments for the object with a string - carriage
returns are '\n' characters.*/
public void setComments(String s) {
this.comments = new Note(s);}
// CONSTRUCTORS
public LifeEvent() {
}
/** @note This constructor uses Date not Calendar */
public LifeEvent(Date date, String place, String comments) {
this.setDate(date);
this.setPlace(place);
this.setComments(comments);
}
/**@note Takes a long date string and extracts the parts of the date the
application requires.
@param String longDate - Calendar date.getTime().toString()
@return Short string representation of date.*/
public String dateConverter(String longDate) {
int counter = 0;
String convertedDate = new String();
String buffer;
StringTokenizer parser = new StringTokenizer(longDate);
while(parser.hasMoreTokens()) {
counter++;
buffer = (String)parser.nextElement();
if(counter == 2) convertedDate = buffer;
if(counter == 3) {
if(buffer.charAt(0) == '0')
convertedDate = buffer.substring(1) + " " + convertedDate;
else convertedDate = buffer + " " + convertedDate;
}
if(counter == 6) convertedDate = convertedDate + " " + buffer;
}
return convertedDate;
}
/**@note Default getDetails() method if not overridden in sub-classes.
@return A string representation of the date, place and any notes/comments.*/
public String getDetails() {
String s = new String();
if (this.date != null) s = s + "Date: 10 \n";
if (this.place != "") s = s + "Place: Somewhere\n";
if (this.comments != null) s = s + this.comments.getDetails();
return s;
}
/** Outputs string for the LifeEvent. Each line begins with a String
defined by the parameter. If this string converts to an integer,
the prefix for contained objects will be incremented by 1. */
public String toString(String sn) {
String s = sn + " " + getTextRecordIdentifier() + "\n";
try {
sn = Integer.toString(Integer.parseInt(sn)+1);}
catch (NumberFormatException e) {
sn = sn + " ";}
if (this.date != null) s = s + sn + " " + "DATE 10 \n";
if (this.place != "") s = s + sn + " " + "PLAC Somewhere \n";
if (this.comments != null) s = s + sn + " " + this.comments.toString(sn);
return s;
}
}
|