aboutsummaryrefslogtreecommitdiff
path: root/comp2511/blackout/File.java
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
commit98cef5e9a772602d42acfcf233838c760424db9a (patch)
tree5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp2511/blackout/File.java
initial commit
Diffstat (limited to 'comp2511/blackout/File.java')
-rw-r--r--comp2511/blackout/File.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/comp2511/blackout/File.java b/comp2511/blackout/File.java
new file mode 100644
index 0000000..df43e17
--- /dev/null
+++ b/comp2511/blackout/File.java
@@ -0,0 +1,87 @@
+package unsw.blackout;
+
+public class File {
+ private String filename;
+ private String contents;
+ private int transmitted;
+ private String target_id;
+
+ /**
+ * File represents a potentially in flight transmission. Transmitted should be <= contents.size().
+ */
+ File(String filename, String contents, int transmitted, String target_id) {
+ this.filename = filename;
+ this.contents = contents;
+ this.transmitted = transmitted;
+ this.target_id = target_id;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+ public String getContents() {
+ return contents;
+ }
+ public String getTransmittedContents() {
+ return this.contents.substring(0, this.transmitted);
+ }
+ public int getTransmitted() {
+ return transmitted;
+ }
+ public int getContentsSize() {
+ return contents.length();
+ }
+ public String getTargetId() {
+ return this.target_id;
+ }
+
+ /**
+ * Returns true if the file has fully transmitted, false otherwise.
+ */
+ public boolean hasFullyTransmitted() {
+ return this.transmitted == this.contents.length();
+ }
+ /**
+ * Returns true if the file contains quantum, false otherwise.
+ */
+ public boolean isQuantum() {
+ return this.contents.contains("quantum");
+ }
+
+
+ /**
+ * Add bytes to the transmitted content, clamps to the 0 and the filesize.
+ */
+ public void addBytes(int bytes) {
+ this.transmitted = Math.min(this.contents.length(), this.transmitted + bytes);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ File other = (File) obj;
+ if (contents == null) {
+ if (other.contents != null)
+ return false;
+ } else if (!contents.equals(other.contents))
+ return false;
+ if (filename == null) {
+ if (other.filename != null)
+ return false;
+ } else if (!filename.equals(other.filename))
+ return false;
+ if (target_id == null) {
+ if (other.target_id != null)
+ return false;
+ } else if (!target_id.equals(other.target_id))
+ return false;
+ if (transmitted != other.transmitted)
+ return false;
+ return true;
+ }
+}