Package collectionManagers
Class CityManager
java.lang.Object
collectionManagers.CityManager
- All Implemented Interfaces:
CollectionManager<TreeSet<City>,
City>
CollectionManager is a class for working with a TreeSet collection of City objects.
It provides methods for loading and writing the collection to a .csv file,
as well as creating a new City object based on user input.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addElementToCollection
(City value) Adds a City element to the collection managed by the CityManager.void
Removes all elements from the cityTreeSet collection.Returns the collection of cities.Returns first element of collection.static CityManager
Gets singleton instance of CityManager.void
loadCollection
(String envKey) Loads the TreeSet collection from a .csv file using the environment variable with the specified key.void
setCollection
(TreeSet<City> cityTreeSet) Sets the collection of cities.static void
setPathToDataFile
(String pathToDataFile) Sets the path to the .csv file.void
Writes TreeSet collection to .csv file
-
Constructor Details
-
CityManager
public CityManager()
-
-
Method Details
-
getInstance
Gets singleton instance of CityManager.- Returns:
- the singleton instance of CityManager
-
loadCollection
Loads the TreeSet collection from a .csv file using the environment variable with the specified key.- Parameters:
envKey
- the key of the environment variable containing the path to the .csv file
-
writeCollection
public void writeCollection()Writes TreeSet collection to .csv file -
addElementToCollection
Adds a City element to the collection managed by the CityManager.- Specified by:
addElementToCollection
in interfaceCollectionManager<TreeSet<City>,
City> - Parameters:
value
- the City element to be added to the collection
-
getFirstOrNew
Returns first element of collection.- Specified by:
getFirstOrNew
in interfaceCollectionManager<TreeSet<City>,
City> - Returns:
- First element of collection. If collection is empty, returns new object.
-
clearCollection
public void clearCollection()Removes all elements from the cityTreeSet collection.- Specified by:
clearCollection
in interfaceCollectionManager<TreeSet<City>,
City>
-
setCollection
Sets the collection of cities.- Specified by:
setCollection
in interfaceCollectionManager<TreeSet<City>,
City> - Parameters:
cityTreeSet
- the TreeSet collection of City objects to set
-
getCollection
Returns the collection of cities.- Specified by:
getCollection
in interfaceCollectionManager<TreeSet<City>,
City> - Returns:
- the TreeSet collection of cities
-
setPathToDataFile
Sets the path to the .csv file.- Parameters:
pathToDataFile
- the path to the .csv file to set
-