aboutsummaryrefslogtreecommitdiff
path: root/comp2511/blackout/DeviceBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'comp2511/blackout/DeviceBase.java')
-rw-r--r--comp2511/blackout/DeviceBase.java62
1 files changed, 62 insertions, 0 deletions
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<Integer> getFileStoreLimit() {
+ return Optional.empty(); // Infinite file storage limit.
+ }
+ final protected Optional<Integer> getByteStoreLimit() {
+ return Optional.empty(); // Infinite byte storage limit.
+ }
+ final protected Optional<Integer> getByteDownloadSpeed() {
+ return Optional.empty(); // Infinite download speed
+ }
+ final protected Optional<Integer> 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