improved IFavorites and TestFavorites

This commit is contained in:
paul-loedige 2020-12-27 21:53:05 +01:00
parent 0d04bdadc2
commit b24fc37dc3
3 changed files with 50 additions and 21 deletions

View File

@ -1,21 +0,0 @@
package com.example.aped.utils;
import java.util.List;
public class Favorites implements IFAVORITES{
@Override
public List<String> getFavorites() {
return null;
}
@Override
public String addFavorite(String deviceName) {
return null;
}
@Override
public String removeFavorite(String deviceName) {
return null;
}
}

View File

@ -2,8 +2,28 @@ package com.example.aped.utils;
import java.util.List; import java.util.List;
/**
* Interface for managing the favorites.
*/
public interface IFAVORITES { public interface IFAVORITES {
/**
* Returns the names of the favorite devices.
* @return list of strings
*/
List<String> getFavorites(); List<String> getFavorites();
/**
* Adds a favorite to the list.
* @param deviceName the name of the device to be added
* @return the name of the device addition worked
*/
String addFavorite(String deviceName); String addFavorite(String deviceName);
/**
* Removes a device from the favorite list.
* @param deviceName the name of the device to be removed
* @return the name of the device if the removal worked
*/
String removeFavorite(String deviceName); String removeFavorite(String deviceName);
} }

View File

@ -0,0 +1,30 @@
package com.example.aped.utils;
import java.util.ArrayList;
import java.util.List;
public class TestFavorites implements IFAVORITES{
private List<String> favorites = new ArrayList<>();
@Override
public List<String> getFavorites() {
return favorites;
}
@Override
public String addFavorite(String deviceName) {
if (!favorites.contains(deviceName)) {
favorites.add(deviceName);
}
return deviceName;
}
@Override
public String removeFavorite(String deviceName) {
if (favorites.contains(deviceName)) {
favorites.remove(deviceName);
}
return deviceName;
}
}