From 4ed9cdf46a5fbe77911c7eb0468a728b00e734f7 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 12 Apr 2024 14:08:11 +0200 Subject: [PATCH] add comments to java impl --- .../app/src/main/java/pl/jacekpoz/GF.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lab2/zad2/app/src/main/java/pl/jacekpoz/GF.java b/lab2/zad2/app/src/main/java/pl/jacekpoz/GF.java index 18161e8..b77d66a 100644 --- a/lab2/zad2/app/src/main/java/pl/jacekpoz/GF.java +++ b/lab2/zad2/app/src/main/java/pl/jacekpoz/GF.java @@ -15,18 +15,30 @@ public class GF { this.value = value; } + /* + * `this` + `rhs` + * throws IllegalArgumentException on different characteristics + */ public GF add(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); return new GF(this.characteristic, (this.value + rhs.value) % this.characteristic); } + /* + * `this` += `rhs` + * throws IllegalArgumentException on different characteristics + */ public void addAssign(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); this.value = this.add(rhs).value; } + /* + * `this` - `rhs` + * throws IllegalArgumentException on different characteristics + */ public GF subtract(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); if (this.value < rhs.value) { @@ -35,24 +47,41 @@ public class GF { return new GF((this.value - rhs.value), this.characteristic); } + /* + * `this` -= `rhs` + * throws IllegalArgumentException on different characteristics + */ public void subtractAssign(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); this.value = this.subtract(rhs).value; } + /* + * `this` * `rhs` + * throws IllegalArgumentException on different characteristics + */ public GF multiply(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); return new GF(this.characteristic, (this.value * rhs.value) % this.characteristic); } + /* + * `this` *= `rhs` + * throws IllegalArgumentException on different characteristics + */ public void multiplyAssign(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); this.value = this.multiply(rhs).value; } + /* + * `this` / `rhs` + * throws IllegalArgumentException on division by 0 + * throws IllegalArgumentException on different characteristics + */ public GF divide(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); if (rhs.value == 0) { @@ -71,16 +100,28 @@ public class GF { return this.multiply(inverse); } + /* + * `this` /= `rhs` + * throws IllegalArgumentException on different characteristics + */ public void divideAssign(final GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs); this.value = this.divide(rhs).value; } + /* + * returns the characteristic of `this` + * throws IllegalArgumentException on different characteristics + */ public int getCharacteristic() { return this.characteristic; } + /* + * returns the value of `this` + * throws IllegalArgumentException on different characteristics + */ public int getValue() { return this.value; } @@ -98,6 +139,10 @@ public class GF { return false; } + /* + * compares `this` and `rhs` + * throws IllegalArgumentException on different characteristics + */ public int compare(GF rhs) throws IllegalArgumentException { verifyCharacteristics(this, rhs);