package unsw.blackout; import java.util.Optional; import unsw.utils.Angle; import unsw.utils.MathsHelper; import static unsw.utils.MathsHelper.RADIUS_OF_JUPITER; public abstract class DeviceBase extends EntityBase { /** * DeviceBase is an abstract class containing common functionality between devices. */ public DeviceBase(String deviceID, Angle position) { super(deviceID, position, RADIUS_OF_JUPITER); } @ Override final public double getVelocity() { return 0.0; // Devices do not move. } @ Override final protected boolean isSupportedEntity(EntityBase entity) { if (entity instanceof DeviceBase) { return false; } return true; } @ Override final protected boolean isPhysicallyReachable(EntityBase entity) { if (!(entity instanceof SatelliteBase)) { return false; } if (!MathsHelper.isVisible(entity.getHeight(), entity.getAngle(), this.getAngle())) { return false; } if (MathsHelper.getDistance(entity.getHeight(), entity.getAngle(), this.getAngle()) > this.getRange()) { return false; } return true; } final protected Optional getFileStoreLimit() { return Optional.empty(); // Infinite file storage limit. } final protected Optional getByteStoreLimit() { return Optional.empty(); // Infinite byte storage limit. } final protected Optional getByteDownloadSpeed() { return Optional.empty(); // Infinite download speed } final protected Optional getByteUploadSpeed() { return Optional.empty(); // Infinite upload speed. } /** * Adds a file without any bandwidth operation taking place. */ void addFile(String filename, String contents) { this.getReceivedFiles().add(new File(filename, contents, contents.length(), this.getId())); } }