我有一个名为 myRestaurant 的 Restaurant 类型对象,其中包含EmployeesAList、MenuAList 和OrdersAList,每个对象都存储Employee、Menu_Item 和Order 对象的实例。Order 的每个实例都存储整数、字符串和整数数组列表。
当我保存 myRestaurant 时,除了 Orders 类中的 arraylist 之外,每个 arraylist 都会被保存。
有什么建议么?
Runner中的保存方法
public boolean SaveToFile(Restaurant myrest)
{
try
{
File outFile = new File("etrest.rest");
//creates object representing file
FileOutputStream outFileStream = new FileOutputStream(outFile);
//connection between program and file
ObjectOutputStream outObjectStream = new ObjectOutputStream(outFileStream);
//class which is used to pass objects which will be saved to file
//Write serializable ArrayList to file
outObjectStream.writeObject(myrest);
//output done, so close the stream
outObjectStream.close();
return true;
}
catch(IOException IOE)
{
System.out.println(IOE.toString()); //debug purpose
return false;
}
}
餐厅中添加订单的方法
ArrayList OrdersAList = new ArrayList();
public void AddOrder(Order o)
{
OrdersAList.add(o);
}
部分订单类 ArrayList Menu_ItemsIDAList = new ArrayList();
public Order()
{
paid = false;
WaiterNo = 0;
TableNo = 0;
item = 0;
}
public Order(boolean pd, int wN, int tN, int it)
{
paid = pd;
WaiterNo = wN;
TableNo = tN;
item = it;
}
//MENU ITEMS ENTERED PER ORDER
public void AddMenu_ItemID(int item)
{
Menu_ItemsIDAList.add(item);
}
当我创建一个 Order 实例时,我创建了一个循环来填充 Menu_ItemsIDAList