diff --git a/app/src/main/java/com/example/simpleparadox/listycity/CityList.java b/app/src/main/java/com/example/simpleparadox/listycity/CityList.java index 05b2c1cac..9fe0e0f0d 100644 --- a/app/src/main/java/com/example/simpleparadox/listycity/CityList.java +++ b/app/src/main/java/com/example/simpleparadox/listycity/CityList.java @@ -22,6 +22,22 @@ public void add(City city) { cities.add(city); } + /** + * This delete a city to the list if the city exists + * @param city + * This is a candidate city to delete + */ + public void delete(City city) { + if (cities.contains(city)) { + cities.remove(city); + + } + else{ + throw new IllegalArgumentException(); + } + + } + /** * This returns a sorted list of cities * @return @@ -32,5 +48,14 @@ public List getCities() { Collections.sort(list); return list; } + + /** + * This returns a number of cities + * @return + * Return the total sum of city number + */ + public int getCount() { + return cities.size(); + } } diff --git a/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java b/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java index 42106e9bf..54314aec7 100644 --- a/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java +++ b/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java @@ -54,5 +54,45 @@ void testGetCities() { assertEquals(0, city.compareTo(cityList.getCities().get(0))); assertEquals(0, mockCity().compareTo(cityList.getCities().get(1))); } + + @Test + void testDelete() { + CityList cityList = mockCityList(); + + assertEquals(1, cityList.getCities().size()); + + City city = new City("Edmonton", "Alberta"); + cityList.delete(city); + + assertEquals(0, cityList.getCities().size()); + assertFalse(cityList.getCities().contains(city)); + } + + @Test + void testDeleteException() { + CityList cityList = mockCityList(); + + City city = new City("Yellowknife", "Northwest Territories"); + cityList.delete(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.delete(city); + }); + } + @Test + void testGetCount() + { + CityList cityList = mockCityList(); + + assertEquals(0, cityList.getCount()); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + assertEquals(1, cityList.getCount()); + + City city2 = new City("Yellowknife", "Northwest Territories"); + cityList.add(city2); + assertEquals(2, cityList.getCount()); + } -} \ No newline at end of file +} diff --git a/index.html b/index.html new file mode 100644 index 000000000..43bba5016 --- /dev/null +++ b/index.html @@ -0,0 +1,373 @@ + + + + + +CityList + + + + + + + + + + + + + + +
+ +
+ +
+
+ +

Class CityList

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.example.simpleparadox.listycity.CityList
    • +
    +
  • +
+
+
    +
  • +
    +
    public class CityList
    +extends java.lang.Object
    +
    This is a class that keeps track of a list of city objects
    +
  • +
+
+
+
    +
  • + +
    +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + +
      Constructors 
      ConstructorDescription
      CityList() 
      +
    • +
    +
    + +
    +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidadd​(com.example.simpleparadox.listycity.City city) +
      This adds a city to the list if the city does not exist
      +
      voiddelete​(com.example.simpleparadox.listycity.City city) +
      This delete a city to the list if the city exists
      +
      java.util.List<com.example.simpleparadox.listycity.City>getCities() +
      This returns a sorted list of cities
      +
      intgetCount() +
      This returns a number of cities
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
    +
  • +
+
+
+
    +
  • + +
    +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        CityList

        +
        public CityList()
        +
      • +
      +
    • +
    +
    + +
    +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        add

        +
        public void add​(com.example.simpleparadox.listycity.City city)
        +
        This adds a city to the list if the city does not exist
        +
        +
        Parameters:
        +
        city - This is a candidate city to add
        +
        +
      • +
      + + + +
        +
      • +

        delete

        +
        public void delete​(com.example.simpleparadox.listycity.City city)
        +
        This delete a city to the list if the city exists
        +
        +
        Parameters:
        +
        city - This is a candidate city to delete
        +
        +
      • +
      + + + +
        +
      • +

        getCities

        +
        public java.util.List<com.example.simpleparadox.listycity.City> getCities()
        +
        This returns a sorted list of cities
        +
        +
        Returns:
        +
        Return the sorted list
        +
        +
      • +
      + + + +
        +
      • +

        getCount

        +
        public int getCount()
        +
        This returns a number of cities
        +
        +
        Returns:
        +
        Return the total sum of city number
        +
        +
      • +
      +
    • +
    +
    +
  • +
+
+
+
+ + + + diff --git a/package-summary.html b/package-summary.html new file mode 100644 index 000000000..e29063670 --- /dev/null +++ b/package-summary.html @@ -0,0 +1,164 @@ + + + + + +com.example.simpleparadox.listycity + + + + + + + + + + + + + + +
+ +
+
+
+

Package com.example.simpleparadox.listycity

+
+
+
    +
  • + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    CityList +
    This is a class that keeps track of a list of city objects
    +
    +
  • +
+
+
+ + + diff --git a/package-tree.html b/package-tree.html new file mode 100644 index 000000000..bf9359e21 --- /dev/null +++ b/package-tree.html @@ -0,0 +1,155 @@ + + + + + +com.example.simpleparadox.listycity Class Hierarchy + + + + + + + + + + + + + + +
+ +
+
+
+

Hierarchy For Package com.example.simpleparadox.listycity

+
+
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • com.example.simpleparadox.listycity.CityList
    • +
    +
  • +
+
+
+
+ + +