10. december 2001 - 11:11
#3
Her et udsnit af en klasse.
public class FreeTimeCollection
{
.
.
.
/**
* Konstruerer en collection af ledige tider, hvor dagens aftaler skal overføres
*/
public FreeTimeCollection
(Appointment[] appointments, Ressource ressource,
PublicCalendar date, int interval, int appointmentLength)
throws java.rmi.RemoteException , java.sql.SQLException
{
this.appointment = appointments;
this.ressource = ressource;
.
.
.
}
/**
* næste ledige tid. fx 27112001 10.30 - 11.00
*/
public TimeLength getNext()
{
return (TimeLength)freeAppointments.get(freeAppNo++);
}
hvorfor får jeg så kun javadoc på metoderne
10. december 2001 - 11:27
#7
\"kigger det forkerte sted\"?? Jeg stiller nok ikke spørgsmål om javadoc i konstruktører hvis jeg ikke havde set at der var problemer.
disky, jeg forstår slet ikke dit sidste svar, det har jo ikke noget at gøre med det jeg spørger om.
kresten, den tager alle metoder med, kommentarene til konstruktørene er der bare stadigvæk ikke.
Jeg ved ikke hvornår I har prøvet at lave javadoc, kan det være en ændring ved de seneste versioner
10. december 2001 - 11:44
#11
Ja I har nok ret, jeg står lidt uforstående over for problemet
lavede lige hurtigt denne lille test
public class JavadocTest
{
/**
* tom konstruktør
*/
public JavadocTest()
{}
/**
* tom metode
*/
public void metode()
{}
}
Den virker perfekt, den klasse jeg ikke kan få det til at virke på er her:
package appobook;
import java.util.*;
public class FreeTimeCollection
{
private Ressource ressource;
private int day, timeNumber = 0, freeAppNo = 0;
private List freeTimes, freeAppointments;
private PublicCalendar date;
private Appointment[] appointment;
// aftalelængden i minutter
private int appointmentLength;
// standard interval i minutter
private static final int DEFAULT_INTERVAL = 30;
/**
* Konstruerer en collection af ledige tider, hvor dagens aftaler skal overføres
*/
public FreeTimeCollection
(Appointment[] appointments, Ressource ressource,
PublicCalendar date, int interval, int appointmentLength)
throws java.rmi.RemoteException , java.sql.SQLException
{
this.appointment = appointments;
this.ressource = ressource;
this.date = (PublicCalendar)date.clone();
this.appointmentLength = appointmentLength;
freeTimes = calculateFreeTimes();
freeAppointments = calculateFreeAppointments(interval);
freeAppNo = 0;
timeNumber = 0;
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
/**
Konstruerer en collection af ledige tider med standard interval
*/
public FreeTimeCollection
(Appointment[] appointments, Ressource ressource,
PublicCalendar date, int appointmentLength)
throws java.rmi.RemoteException, java.sql.SQLException
{
this(appointments, ressource, date, DEFAULT_INTERVAL, appointmentLength);
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
/**
Konstruerer en collection af ledige tider hvor dagens aftaler hentes automatisk
*/
public FreeTimeCollection
(Ressource r, PublicCalendar date, int appLength)
throws java.rmi.RemoteException, java.sql.SQLException
{
this(null, r, date, appLength);
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
List calculateFreeTimes() throws java.rmi.RemoteException
, java.sql.SQLException
{
// Tiderne der \"tælles\" på
Appointment appElement;
AppointmentCollection appCol = Build01Driver.appointmentCollection();
WorkingCalendarCollection workCal = Build01Driver.workingCalendarCollection();
WorkingCalendarRow workCalRow = null;
int appointmentNo = 0, periodNo = 0;
Vector appointments, workingPeriods = null;
PublicCalendar hStart, hEnd, appStart = null,
appEnd = null, currentTime;
freeTimes = new LinkedList();
TimeLength freeTime;
Condition condition = new Condition();
String hStartString, hEndString;
// find ud af om dagen er afvigende
Object resId = ressource.getAttribute(\"id\");
int deviating = 1;
condition = new Condition();
condition.setSubCondition(\"deviating=\" + deviating);
condition.setSubCondition(\"id=\" + resId + \" and months_between(\"
+ date.toDate() + \", p_start) >= 0 and months_between\"+
\"(p_end, \" + date.toDate() + \") >= 0 and day = to_char(\" +
date.toDate() + \", \'d\')\");
workCal = Build01Driver.workingCalendarCollection();
workingPeriods = workCal.getElement(condition);
// ingen resultater hvis dagen ikke er i en afvigende periode
if (workingPeriods.size() == 0)
deviating = 0;
// arbejdstider for en dag en ressource
condition = new Condition();
condition.setSubCondition(\"deviating=\" + deviating + \" and id=\" + resId+
\" and months_between(\" + date.toDate() + \", p_start) >= 0 and \" +
\"months_between(p_end, \" + date.toDate() + \")>=0 and \" +
\"day = to_char(\" + date.toDate() + \", \'d\')\");
workingPeriods = workCal.getElement(condition);
// appointments
// System.out.println (ressource.getAttribute (\"id\"));
condition = new Condition();
condition.setSubCondition (\"ressource_id = \" +
ressource.getAttribute(\"id\") + \" and to_char(a_date, \'\" +
date.sqlFormat() + \"\') = \'\" + date + \"\'\");
appointments = appCol.getElement(condition);
// aftale
if (appointmentNo < appointments.size())
{
appElement = (Appointment)appointments.get (appointmentNo++);
// start, slut på aftale
String appStartString = (String)appElement.getAttribute(\"a_start\");
String appEndString = (String)appElement.getAttribute(\"a_end\");
appStart = stringToCalendar(appStartString);
appEnd = stringToCalendar(appEndString);
}
// gennemløber arbejdsperioder (imellem aftaler)
do
{
workCalRow = (WorkingCalendarRow)workingPeriods.get(periodNo++);
// start, slut på arbejdstidsperiode
hStartString = (String)workCalRow.getAttribute(\"h_start\");
hEndString = (String)workCalRow.getAttribute(\"h_end\");
hStart = stringToCalendar(hStartString);
hEnd = stringToCalendar(hEndString);
if (appStart == null)
appStart = stringToCalendar(hEndString);
if (appEnd == null)
appEnd = stringToCalendar(hEndString);
// gennemløber aftaler i enkelt arbejdstidsrum (fx 8.00 - 12.00)
currentTime = hStart;
// aftalestart skal være før eller lig med næste pause
while (currentTime.before(hEnd) &&
(appStart.before(hEnd) || appStart.equals(hEnd)))
{
// Er der en aftale (nuværende starttid før aftale start)
if (currentTime.before(appStart))
{
// Tidsrum imellem aftaler (eller pause-tider)
freeTime = new TimeLength (currentTime, appStart);
freeTimes.add(freeTime);
}
currentTime = appEnd;
if (appointmentNo < appointments.size())
{
appElement = (Appointment)appointments.get(appointmentNo++);
// start, slut på aftale
appStart = stringToCalendar((String)appElement.getAttribute(\"a_start\"));
appEnd = stringToCalendar((String)appElement.getAttribute(\"a_end\"));
}
else
appStart = appEnd = hEnd;
}// while (
}// do - while
// flere arbejdsperioder
while (periodNo < workingPeriods.size());
// System.out.println (\"workper size: \" + workingPeriods.size());
return freeTimes;
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
private List calculateFreeAppointments (int interval) throws java.rmi.RemoteException
, java.sql.SQLException
{
PublicCalendar currentEndTime; // holder for sluttidspunkt
TimeLength newTime;
List freeAppointments = new LinkedList();
TimeLength currentTimeLength;
PublicCalendar currentTime;
if (freeTimes == null) freeTimes = calculateFreeTimes();
// gennemløber dagens perioder
while (hasMorePeriods())
{
currentTimeLength = getNextPeriod();
// System.out.println (\"periode: \" + currentTimeLength.startTime() +
// \" - \" + currentTimeLength.endTime());
currentTime = currentTimeLength.startTime();
// gennemløber en periode
boolean ok;
do
{
currentEndTime = (PublicCalendar)currentTime.clone();
currentEndTime.add(Calendar.MINUTE, appointmentLength);
// starttidspunkt + aftalelængde skal være før periodeslutning
ok = currentEndTime.beforeOrEqual(currentTimeLength.endTime());
if (ok) // fri aftaletid fundet
{
newTime = new TimeLength((PublicCalendar)currentTime.clone(),
(PublicCalendar)currentEndTime.clone());
freeAppointments.add(newTime);
}
currentTime.add(Calendar.MINUTE, interval);
}
while (currentTime.before(currentTimeLength.endTime()));
} // while(hasMore...
return freeAppointments;
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
// konverterer string af HHMM til PublicCalendar
// tilpasset formatet for de tidsvariable i tabellerne
private PublicCalendar stringToCalendar(String time)
{
int hour = Integer.parseInt(time.substring(0,2));
int minute = Integer.parseInt(time.substring(2,4));
PublicCalendar calTime = new PublicCalendar(hour, minute);
calTime.set(PublicCalendar.SECOND, 0);
calTime.setIsTime(true);
calTime.setIsDate(false);
return calTime;
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
/**
næste ledige tid. fx 27112001 10.30 - 11.00
*/
public TimeLength getNext()
{
return (TimeLength)freeAppointments.get(freeAppNo++);
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
/**
næste frie arbejdsperiode dvs. tiden imellem 2 pauser. fx 8.00 - 12.00
*/
public TimeLength getNextPeriod()
{
return (TimeLength)freeTimes.get(timeNumber++);
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
/** true hvis der findes flere ledige tider i denne collection
*/
public boolean hasMore()
{
return (freeAppointments.size() > freeAppNo);
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
/** true hvis der findes flere ledige arbejdsperioder i denne collection
*/
public boolean hasMorePeriods()
{
return (freeTimes.size() > timeNumber);
}
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
// test
/*
public static void main(String[] args) throws Exception
{
Condition c = new Condition();
c.setSubCondition(\"id = 1\");
Vector ressCol = Build01Driver.ressourceCollection ().getElement(c);
Ressource ress = (Ressource)ressCol.get(0);
PublicCalendar dato = new PublicCalendar();
dato.set(2001, 11, 23);
int aLength = 30;
long tid = System.currentTimeMillis();
FreeTimeCollection test = new FreeTimeCollection(ress, dato, aLength);
// System.out.println (\"tid millis (450ms på 350Mhz win2k) \" + (System.currentTimeMillis() - tid));
//while(test.hasMorePeriods())
// System.out.println (\"\\nMAIN \" + test.getNextPeriod());
}*/
}