Stops are now a hashmap
This commit is contained in:
@@ -57,6 +57,7 @@ public class MainController extends Controller{
|
|||||||
public void login() throws Exception {
|
public void login() throws Exception {
|
||||||
//validate login
|
//validate login
|
||||||
if (validateLogin(username.getText(), password.getText())){
|
if (validateLogin(username.getText(), password.getText())){
|
||||||
|
Session.session.getDataManager().newLogged();//sets new arrays for new log ins
|
||||||
getNotifications();
|
getNotifications();
|
||||||
changeScene(SceneCode.HOME);
|
changeScene(SceneCode.HOME);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
private Map<String, ObservableList<Ride>> rides;
|
private Map<String, ObservableList<Ride>> rides;
|
||||||
private ObservableList<Stop> stops;
|
private Map<String, ObservableList<Stop>> stops;
|
||||||
private ObservableList<Route> routes;
|
private ObservableList<Route> routes;
|
||||||
private ObservableList<Trip> trips;
|
private ObservableList<Trip> trips;
|
||||||
private ObservableList<SharedTrip> sharedTrips;
|
private ObservableList<SharedTrip> sharedTrips;
|
||||||
@@ -23,9 +23,9 @@ public class DataManager {
|
|||||||
private Map<String, Driver> drivers;//seperated from users as they are two different types of accounts
|
private Map<String, Driver> drivers;//seperated from users as they are two different types of accounts
|
||||||
private Map<String, List<String>> notifications; //indexed by user name
|
private Map<String, List<String>> notifications; //indexed by user name
|
||||||
|
|
||||||
public DataManager(Map<String, List<Ride>> rides, List stops, List routes, List trips, List sharedTrips, Map users, Map drivers, Map<String, List<String>> notifications){
|
public DataManager(Map<String, List<Ride>> rides, Map<String, List<Stop>> stops, List routes, List trips, List sharedTrips, Map users, Map drivers, Map<String, List<String>> notifications){
|
||||||
this.rides = convertRideMapToObserver(rides);
|
this.rides = convertRideMapToObserver(rides);
|
||||||
this.stops = FXCollections.observableArrayList(stops);
|
this.stops = convertStopMapToObserver(stops);
|
||||||
this.routes = FXCollections.observableArrayList(routes);
|
this.routes = FXCollections.observableArrayList(routes);
|
||||||
this.trips = FXCollections.observableArrayList(trips);
|
this.trips = FXCollections.observableArrayList(trips);
|
||||||
this.sharedTrips = FXCollections.observableArrayList(sharedTrips);
|
this.sharedTrips = FXCollections.observableArrayList(sharedTrips);
|
||||||
@@ -35,9 +35,14 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DataManager(){
|
public DataManager(){
|
||||||
this(new HashMap<String, List<Ride>>(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), new HashMap<String, User>(), new HashMap<String, Driver>(), new HashMap<String, List<String>>());
|
this(new HashMap<>(), new HashMap<>(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), new HashMap<String, User>(), new HashMap<String, Driver>(), new HashMap<String, List<String>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
//Map to Observer or List functions
|
||||||
|
////////////////////////////////////////
|
||||||
|
//Ride
|
||||||
|
////////////////////////////////////////
|
||||||
private Map<String, ObservableList<Ride>> convertRideMapToObserver(Map<String, List<Ride>> rides){
|
private Map<String, ObservableList<Ride>> convertRideMapToObserver(Map<String, List<Ride>> rides){
|
||||||
HashMap<String, ObservableList<Ride>> ob = new HashMap<>();
|
HashMap<String, ObservableList<Ride>> ob = new HashMap<>();
|
||||||
for (String key: rides.keySet()){
|
for (String key: rides.keySet()){
|
||||||
@@ -49,7 +54,7 @@ public class DataManager {
|
|||||||
private Map<String, List<Ride>> convertRideMapToList(Map<String, ObservableList<Ride>> rides){
|
private Map<String, List<Ride>> convertRideMapToList(Map<String, ObservableList<Ride>> rides){
|
||||||
HashMap<String, List<Ride>> ob = new HashMap<>();
|
HashMap<String, List<Ride>> ob = new HashMap<>();
|
||||||
for (String key: rides.keySet()){
|
for (String key: rides.keySet()){
|
||||||
ob.put(key, new ArrayList<Ride>(rides.get(key)));
|
ob.put(key, new ArrayList<>(rides.get(key)));
|
||||||
}
|
}
|
||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
@@ -58,29 +63,55 @@ public class DataManager {
|
|||||||
return convertRideMapToList(rides);
|
return convertRideMapToList(rides);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
//STop
|
||||||
|
//////////////////////////////////
|
||||||
|
private Map<String, ObservableList<Stop>> convertStopMapToObserver(Map<String, List<Stop>> stops){
|
||||||
|
HashMap<String, ObservableList<Stop>> ob = new HashMap<>();
|
||||||
|
for (String key: stops.keySet()){
|
||||||
|
ob.put(key, FXCollections.observableArrayList(stops.get(key)));
|
||||||
|
}
|
||||||
|
return ob;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, List<Stop>> convertStopMapToList(Map<String, ObservableList<Stop>> stops){
|
||||||
|
HashMap<String, List<Stop>> ob = new HashMap<>();
|
||||||
|
for (String key: stops.keySet()){
|
||||||
|
ob.put(key, new ArrayList<>(stops.get(key)));
|
||||||
|
}
|
||||||
|
return ob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<Stop>> stopsMapSerialised(){
|
||||||
|
return convertStopMapToList(stops);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void newLogged(){
|
||||||
|
rides.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
|
||||||
|
stops.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
|
||||||
|
notifications.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
|
||||||
|
}
|
||||||
|
//////////////////////////////
|
||||||
|
//Getters and Setters
|
||||||
|
//////////////////////////////
|
||||||
public ObservableList<Ride> getRides() {
|
public ObservableList<Ride> getRides() {
|
||||||
return rides.get(Session.session.getUser().getID());
|
return rides.get(Session.session.getUser().getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRides(Ride ride){
|
public void addRides(Ride ride){
|
||||||
rides.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
|
|
||||||
rides.get(Session.session.getUser().getID()).add(ride);
|
rides.get(Session.session.getUser().getID()).add(ride);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRide(Ride ride){
|
public void removeRide(Ride ride){
|
||||||
if (rides.get(Session.session.getUser().getID()) != null) {
|
|
||||||
rides.get(Session.session.getUser().getID()).remove(ride);
|
rides.get(Session.session.getUser().getID()).remove(ride);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRide(int i){
|
public void removeRide(int i){
|
||||||
if (rides.get(Session.session.getUser().getID()) != null) {
|
|
||||||
rides.get(Session.session.getUser().getID()).remove(i);
|
rides.get(Session.session.getUser().getID()).remove(i);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<Stop> getStops() {
|
public ObservableList<Stop> getStops() {
|
||||||
return stops;
|
return stops.get(Session.session.getUser().getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addStop(Stop stop){
|
public boolean addStop(Stop stop){
|
||||||
@@ -89,7 +120,7 @@ public class DataManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stops.add(stop);
|
stops.get(Session.session.getUser().getID()).add(stop);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class DataManagerSerialiser extends Serialiser {
|
|||||||
public boolean serialise(DataManager dataManager){
|
public boolean serialise(DataManager dataManager){
|
||||||
//ArrayList<Ride> rides = new ArrayList<>(dataManager.getRides());
|
//ArrayList<Ride> rides = new ArrayList<>(dataManager.getRides());
|
||||||
Map<String, List<Ride>> rides = dataManager.rideMapSerialised();
|
Map<String, List<Ride>> rides = dataManager.rideMapSerialised();
|
||||||
ArrayList<Stop> stops = new ArrayList<>(dataManager.getStops());
|
Map<String, List<Stop>> stops = dataManager.stopsMapSerialised();
|
||||||
ArrayList<Route> routes = new ArrayList<>(dataManager.getRoutes());
|
ArrayList<Route> routes = new ArrayList<>(dataManager.getRoutes());
|
||||||
ArrayList<Trip> trips = new ArrayList<>(dataManager.getTrips());
|
ArrayList<Trip> trips = new ArrayList<>(dataManager.getTrips());
|
||||||
ArrayList<SharedTrip> sharedTrips = new ArrayList<>(dataManager.getSharedTrips());
|
ArrayList<SharedTrip> sharedTrips = new ArrayList<>(dataManager.getSharedTrips());
|
||||||
@@ -170,7 +170,7 @@ public class DataManagerSerialiser extends Serialiser {
|
|||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
Reader reader2 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/stops.json"), "UTF-8");
|
Reader reader2 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/stops.json"), "UTF-8");
|
||||||
ArrayList<Stop> stops = gson.fromJson(reader2, new TypeToken<ArrayList<Stop>>(){}.getType());
|
HashMap<String, List<Stop>> stops = gson.fromJson(reader2, new TypeToken<HashMap<String, ArrayList<Stop>>>(){}.getType());
|
||||||
reader2.close();
|
reader2.close();
|
||||||
|
|
||||||
Reader reader3 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/routes.json"), "UTF-8");
|
Reader reader3 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/routes.json"), "UTF-8");
|
||||||
|
|||||||
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
[{"address":"1 Avonhead Road"},{"address":"100 Yaldhurst Road"},{"address":"120 Maidstone Road"},{"address":"1 University Drive"},{"address":"1 Homestead Lane"}]
|
{"79984862":[{"address":"1 Avonhead Road"},{"address":"100 Yaldhurst Road"},{"address":"120 Maidstone Road"},{"address":"1 University Drive"},{"address":"1 Homestead Lane"}]}
|
||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user