📄 cameramanager.java
字号:
package sept.model;import java.util.*;/** * Class CameraManager (IPCameraModel) * * CameraManager is a container class that stores all camera information. * It contains a list of cameras, and its core functionality includes * adding, removing, and retrieving camera information. * * @author Goran Mateski * @since v1.0 */public class CameraManager { private ArrayList<Camera> cameras; /* List of cameras */ private static final short INITIAL_CAPACITY = 2; /* Initial size of camera list */ /** * Constructor for the CameraManager. * Initializes the array-list of cameras */ public CameraManager(){ this.cameras = new ArrayList<Camera>(INITIAL_CAPACITY); } /** * Constructor for the CameraManager. * Initializes the array-list of cameras, and adds a camera * * @param location the directory where a camera stores its images * @param cameraName name of the camera */ public CameraManager(String location, String cameraName){ this.cameras = new ArrayList<Camera>(INITIAL_CAPACITY); addCamera(location, cameraName); } /** * Add a camera to the Camera Manager. * * @param location The directory or URL where the camera stores images * @param cameraName User defined name for the camera. * @return Returns true if the camera was added. Returns false if the camera was not added. */ public boolean addCamera(String location, String cameraName){ try { cameras.add(new Camera(cameraName, location)); } catch (Exception e) { return false; } return true; /* later will check if directory of camera is valid, return false if invalid. */ } /** * Remove a camera from the Camera Manager * * @param cameraName the name of camera to remove * @return returns true if the camera exists and is removed, returns * false if the camera did not exist. */ public boolean removeCamera(String cameraName){ int position = 0; boolean exists = false; for(int i = 0; i < cameras.size(); i++){ if( (cameras.get(i).getName()).equalsIgnoreCase(cameraName) ){ exists = true; position = i; } } if (exists){ cameras.remove(position); return true; } return false; } /** * Method getImages * * Retrieve all the images taken by a specific camera * * @param cameraName The name of the camera * @return Returns the images in an arrayList. */ public ArrayList<Photo> getPhotos(String cameraName){ for(int i = 0; i < cameras.size(); i++){ if(cameraName.equals(cameras.get(i).getName())) return (cameras.get(i).getPhotos()); } return null; } /** * Method searchForPhoto * * Searches for a photo that was taken at a specific date and time. * * @param date The date in the form YYYY-MM-DD * @param time The time in the form HH:MM * @param cameraName The camera whose photos are to be searched. * @return Returns the photo taken at the time specified, if it exists. * Otherwise it returns null. */ public Photo searchForPhoto(String date, String time, String cameraName){ /* TODO: Look into pattern matching/regex classes. All photos * have the same pattern to their filenames. */ return null; } /** * Get the number of cameras. * * @return returns an integer value representing the number of cameras. */ public int numberOfCameras(){ return cameras.size(); } /** * Method getCameraList * * Accessor method that retrieves a list of cameras. * * @return Returns all cameras in an Array List. */ public ArrayList<Camera> getCameraList(){ return cameras; } /** * Method update * * Updates all cameras, re-downloads images if necessary */ public void update(){ for(int i = 0; i < this.numberOfCameras(); i++){ cameras.get(i).updateImageList(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -