代码拉取完成,页面将自动刷新
package second_term.sixth_chapter;
import java.io.*;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class ProgramOfStudy implements Iterable<Course>,Serializable {
private List<Course> list;
public ProgramOfStudy()
{
list = new LinkedList<Course>();
}
public void addCourse(Course course)
{
if (course != null)
list.add(course);
}
public Course find(String prefix, int number)
{
for (Course course : list)
if (prefix.equals(course.getPrefix()) &&
number == course.getNumber())
return course;
return null;
}
public void addCourseAfter(Course target, Course newCourse)
{
if (target == null || newCourse == null)
return;
int targetIndex = list.indexOf(target);
if (targetIndex != -1)
list.add(targetIndex + 1, newCourse);
}
public void replace(Course target, Course newCourse)
{
if (target == null || newCourse == null)
return;
int targetIndex = list.indexOf(target);
if (targetIndex != -1)
list.set(targetIndex, newCourse);
}
public void sort(){
Collections.sort(list);
}
public String toString()
{
String result = "";
for (Course course : list)
result += course + "\n";
return result;
}
public Iterator<Course> iterator()
{
return list.iterator();
}
public void save(String fileName) throws IOException
{
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(this);
oos.flush();
oos.close();
}
public static ProgramOfStudy load(String fileName) throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream(fileName);
ObjectInputStream ois = new ObjectInputStream(fis);
ProgramOfStudy pos = (ProgramOfStudy) ois.readObject();
ois.close();
return pos;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。