From 98cef5e9a772602d42acfcf233838c760424db9a Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Thu, 13 Feb 2025 18:00:17 +1100 Subject: initial commit --- comp2511/blackout/DeviceBase.java | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 comp2511/blackout/DeviceBase.java (limited to 'comp2511/blackout/DeviceBase.java') diff --git a/comp2511/blackout/DeviceBase.java b/comp2511/blackout/DeviceBase.java new file mode 100644 index 0000000..8f0b06e --- /dev/null +++ b/comp2511/blackout/DeviceBase.java @@ -0,0 +1,62 @@ +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())); + } +} \ No newline at end of file -- cgit v1.2.3