J'écris du code qui crée un carnet de rendez-vous et j'ai donc plusieurs classes différentes. Je ne peux pas voir pour se débarrasser de cette erreur. Il dit que j'ai une méthode non contrôlée. Voilà ce que je reçois:Message de compilation: Invocation de méthode non vérifiée; <t> sort (java.util.list <T>)
java:25: warning: [unchecked] unchecked method invocation: <T>sort(java.util.List<T>) in java.util.Collections is applied to (java.util.ArrayList<Appointment>)
Mon code
import java.io.*;
import java.util.*;
import java.util.ArrayList;
/*is a collection of Appointment objects. As such, the class must include
* a data structure to store an arbitrary number of Appointments*/
public class ApptBook implements Iterable {
private ArrayList<Appointment> list;
private Date startRange,endRange;
public ApptBook(Date _startRange, Date _endRange)
{
ArrayList ls =new ArrayList();
endRange=_endRange;
startRange=_startRange;
}
public void printAppointments(Date start, Date end)
{
startRange=start;
endRange=end;
Collections.sort(list);
System.out.println("Result list:");
for(Appointment counter: list){
System.out.println(counter.toString());
}
}
public void saveToFile() throws FileNotFoundException, IOException
{
OutputStream f = new FileOutputStream("apptbook.dat");
OutputStreamWriter writer = new OutputStreamWriter(f);
BufferedWriter out = new BufferedWriter(writer);
int i;
for(i=0;i<list.size();i++)
{
out.write("##\n");
out.write(list.get(i).forFile());
out.write("#\n");
}
out.close();
}
public void LoadFromFile() throws FileNotFoundException, IOException
{
InputStream f = new FileInputStream("apptbook.dat");
InputStreamReader reader = new InputStreamReader(f);
BufferedReader in = new BufferedReader(reader);
String str;
while ((str = in.readLine()) != null) {
if(str.equals("##"))//start read new object
{
//read date:
str = in.readLine();
String []param=str.split(" ");
//public Date(int _month, int _day, int _year)
// <year> <month> <day>
Date start=new Date(Integer.parseInt(param[1]),Integer.parseInt(param[2]),Integer.parseInt(param[0]));
//read time:
str = in.readLine();
String []paramTime=str.split(" ");
Time time=new Time(Integer.parseInt(paramTime[0]),Integer.parseInt(paramTime[1]));
int duration;
str=in.readLine();
duration=Integer.parseInt(str);
str=in.readLine();
Appointment newApp=new Appointment(start, time, duration, str);
addAppt(newApp);
str=in.readLine();//read #
}
}
in.close();
}
//should add a to this ApptBook, provided that a does not overlap
//with an Appointment that is already stored.
public boolean addAppt(Appointment a)
{
//check for overlap:
int cursor;
boolean isOverlap=false;
for(cursor = 0;cursor<list.size();cursor++)
if(a.overlaps(list.get(cursor)))
{
isOverlap=true;
break;
}
if(!isOverlap)
{
list.add(a);
}
return isOverlap;
}
public boolean removeAppt(Date d, Time t)
{
throw new UnsupportedOperationException("removal not implemented");
}
//@Override
public Iterator iterator() {
return new ApptBookIterator(list,startRange,endRange);
}
// Inner class example
private class ApptBookIterator implements
Iterator {
/*
ApptBookIterator
*/
private int cursor;
private Date startRange;
private Date endRange;
ArrayList<Appointment> list;
public ApptBookIterator(ArrayList<Appointment> _list,Date _startRange,Date _EndRange) {
list=_list;
startRange=_startRange;
endRange=_EndRange;
//find first in range:
boolean isFind=false;
for(cursor = 0;cursor<list.size();cursor++)
{
Appointment temp=list.get(cursor);
if(temp.isInDateRange(startRange,endRange))
{
isFind=true;
break;
}
}
if(!isFind)
cursor=-1;
}
public boolean hasNext() {
if(cursor==-1)
return false;
boolean isFind=false;
for(int i=cursor;i<list.size();i++)
{
Appointment temp=list.get(i);
if(temp.isInDateRange(startRange,endRange))
{
isFind=true;
break;
}
}
if(!isFind)
return false;
return true;
}
public Integer next() {
if(this.hasNext()) {
for(;cursor<list.size();cursor++)
{
Appointment temp=list.get(cursor);
if(temp.isInDateRange(startRange,endRange))
break;
}
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}
Ce n'est pas une erreur, c'est juste un avertissement. – Thevenin