-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCabinList.java
69 lines (61 loc) · 1.52 KB
/
CabinList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.ArrayList;
import java.util.UUID;
public class CabinList
{
private static ArrayList<Cabin> cabins;
private static CabinList cabinList;
/**
* private constructor that sets the arraylist cabins = to the datareader getCabins method
*/
private CabinList()
{
cabins = DataReader.getCabins();
}
/**
* if there is no cabinList a new object cabinList is created and returns it.
* @return cabinList
*/
public static CabinList getInstance()
{
if(cabinList == null) return cabinList = new CabinList();
return cabinList;
}
/**
* adds a name into the cabins list
* @param name
*/
public void addCabin(String name)
{
cabinList.cabins.add(new Cabin(name));
}
/**
* Loops through cabins and checks if the UUID matches the getUUID method.
* If they match theCabin will be returned else return null
* @param UUID checking for the UUID
* @return null
*/
public static Cabin getCabin(UUID UUID)
{
for(Cabin theCabin : cabins)
{
if(theCabin.getUUID() == UUID) return theCabin;
}
return null;
}
/**
* getter method that gets cabins
* @return this.cabins
*/
public ArrayList<Cabin> getCabins()
{
return this.cabins;
}
/**
* uses the method from the data writer to save the cabins
* @param cabin saves cabins
*/
public void saveCabin()
{
DataWriter.saveCabins();
}
}