Create Agenda
This commit is contained in:
@@ -0,0 +1,188 @@
|
|||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Agenda implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private ArrayList<Stage> stages;
|
||||||
|
private ArrayList<Event> events;
|
||||||
|
private ArrayList<Artist> artists;
|
||||||
|
|
||||||
|
public Agenda() {
|
||||||
|
stages = new ArrayList<Stage>();
|
||||||
|
events = new ArrayList<Event>();
|
||||||
|
artists = new ArrayList<Artist>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStage(Stage stage) {
|
||||||
|
stages.add(stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEvent(Event event) {
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addArtist(Artist artist) {
|
||||||
|
artists.add(artist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillArtists() {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream("artists.dat");
|
||||||
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
|
Object object;
|
||||||
|
object = ois.readObject();
|
||||||
|
try {
|
||||||
|
while (object != null) {
|
||||||
|
artists.add((Artist) object);
|
||||||
|
object = ois.readObject();
|
||||||
|
}
|
||||||
|
} catch (EOFException e) {
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillEvents() {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream("events.dat");
|
||||||
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
|
Object object;
|
||||||
|
object = ois.readObject();
|
||||||
|
try {
|
||||||
|
while (object != null) {
|
||||||
|
events.add((Event) object);
|
||||||
|
object = ois.readObject();
|
||||||
|
}
|
||||||
|
} catch (EOFException e) {
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillStages() {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream("stages.dat");
|
||||||
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
|
Object object;
|
||||||
|
object = ois.readObject();
|
||||||
|
try {
|
||||||
|
while (object != null) {
|
||||||
|
stages.add((Stage) object);
|
||||||
|
object = ois.readObject();
|
||||||
|
}
|
||||||
|
} catch (EOFException e) {
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveStages() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
File file = new File("stages.dat");
|
||||||
|
if (!file.exists()){
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
for (Stage stage : stages) {
|
||||||
|
oos.writeObject(stage);
|
||||||
|
}
|
||||||
|
oos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveEvents() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
File file = new File("events.dat");
|
||||||
|
if (!file.exists()){
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
for (Event event : events) {
|
||||||
|
oos.writeObject(event);
|
||||||
|
}
|
||||||
|
oos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveArtists() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
File file = new File("artists.dat");
|
||||||
|
if (!file.exists()){
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
for (Artist artist : artists) {
|
||||||
|
oos.writeObject(artist);
|
||||||
|
}
|
||||||
|
oos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEvents()
|
||||||
|
{
|
||||||
|
int ID = 0;
|
||||||
|
for (Stage stage : stages)
|
||||||
|
{
|
||||||
|
ID = stage.getID();
|
||||||
|
for (Event event : events)
|
||||||
|
{
|
||||||
|
if ( ID == event.getID())
|
||||||
|
{
|
||||||
|
stage.addEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAll()
|
||||||
|
{
|
||||||
|
saveArtists();
|
||||||
|
saveEvents();
|
||||||
|
saveStages();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillAll()
|
||||||
|
{
|
||||||
|
fillArtists();
|
||||||
|
fillEvents();
|
||||||
|
fillStages();
|
||||||
|
addEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user