Class CityManager

java.lang.Object
collectionManagers.CityManager
All Implemented Interfaces:
CollectionManager<TreeSet<City>,City>

public class CityManager extends Object implements 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 Details

    • CityManager

      public CityManager()
  • Method Details

    • getInstance

      public static CityManager getInstance()
      Gets singleton instance of CityManager.
      Returns:
      the singleton instance of CityManager
    • loadCollection

      public void loadCollection(String envKey)
      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

      public void addElementToCollection(City value)
      Adds a City element to the collection managed by the CityManager.
      Specified by:
      addElementToCollection in interface CollectionManager<TreeSet<City>,City>
      Parameters:
      value - the City element to be added to the collection
    • getFirstOrNew

      public City getFirstOrNew()
      Returns first element of collection.
      Specified by:
      getFirstOrNew in interface CollectionManager<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 interface CollectionManager<TreeSet<City>,City>
    • setCollection

      public void setCollection(TreeSet<City> cityTreeSet)
      Sets the collection of cities.
      Specified by:
      setCollection in interface CollectionManager<TreeSet<City>,City>
      Parameters:
      cityTreeSet - the TreeSet collection of City objects to set
    • getCollection

      public TreeSet<City> getCollection()
      Returns the collection of cities.
      Specified by:
      getCollection in interface CollectionManager<TreeSet<City>,City>
      Returns:
      the TreeSet collection of cities
    • setPathToDataFile

      public static void setPathToDataFile(String pathToDataFile)
      Sets the path to the .csv file.
      Parameters:
      pathToDataFile - the path to the .csv file to set