U64|128|HashValue: create Builder classes
U64, U128, HashValue gain a Builder class that allows to perform
a series of operations on the values without re-allocating the object.
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/HashValue.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/HashValue.java
index a656dab..3030e3e 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/HashValue.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/HashValue.java
@@ -45,4 +45,58 @@
/** xor this value with another value value of the same type */
H xor(H other);
+
+ /** create and return a builder */
+ Builder<H> builder();
+
+ /** a mutator for HashValues. Allows perfomring a series of
+ * operations on a hashv value without the associated cost of object
+ * reallocation.
+ *
+ * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
+ *
+ * @param <H> - the hashvalue
+ */
+ public interface Builder<H> {
+ /** perform an arithmetic addition of this value and other. Wraps around on
+ * overflow of the defined word size.
+ *
+ * @param other
+ * @return this mutator
+ */
+ Builder<H> add(H other);
+
+ /**
+ * arithmetically substract the given 'other' value from the value stored in this mutator.
+ * around on overflow.
+ *
+ * @param other
+ * @return this mutator
+ */
+ Builder<H> subtract(H other);
+
+ /** bitwise invert the value stored in this mutator
+ *
+ * @return this mutator
+ */
+ Builder<H> invert();
+
+ /** or the value stored in this mutator with another value value of the same type
+ * @return this mutator
+ */
+ Builder<H> or(H other);
+
+ /** and the value stored in this mutator with another value value of the same type
+ * @return this mutator
+ */
+ Builder<H> and(H other);
+
+ /** xor the value stored in this mutator with another value value of the same type
+ * @return this mutator
+ */
+ Builder<H> xor(H other);
+
+ /** @return the hash value */
+ public H build();
+ }
}
\ No newline at end of file
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U128.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U128.java
index 0b4e0f7..ddf4faa 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U128.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U128.java
@@ -147,4 +147,76 @@
return HashValueUtils.prefixBits(this.raw1, numBits);
}
+ @Override
+ public HashValue.Builder<U128> builder() {
+ return new U128Builder(raw1, raw2);
+ }
+
+ static class U128Builder implements HashValue.Builder<U128> {
+ private long raw1, raw2;
+
+ public U128Builder(long raw1, long raw2) {
+ this.raw1 = raw1;
+ this.raw2 = raw2;
+ }
+
+ @Override
+ public Builder<U128> add(U128 other) {
+ raw2 += other.raw2;
+ raw1 += other.raw1;
+ if(UnsignedLongs.compare(raw2, other.raw2) < 0) {
+ // raw2 overflow
+ raw1+=1;
+ }
+ return this;
+ }
+
+ @Override
+ public Builder<U128> subtract(
+ U128 other) {
+ if(UnsignedLongs.compare(this.raw2, other.raw2) >= 0) {
+ raw2 -= other.raw2;
+ raw1 -= other.raw1;
+ } else {
+ // raw2 overflow
+ raw2 -= other.raw2;
+ raw1 = this.raw1 - other.raw1 - 1;
+ }
+ return this;
+ }
+
+ @Override
+ public Builder<U128> invert() {
+ raw1 = ~raw1;
+ raw2 = ~raw2;
+ return this;
+ }
+
+ @Override
+ public Builder<U128> or(U128 other) {
+ raw1 |= other.raw1;
+ raw2 |= other.raw2;
+ return this;
+ }
+
+ @Override
+ public Builder<U128> and(U128 other) {
+ raw1 &= other.raw1;
+ raw2 &= other.raw2;
+ return this;
+ }
+
+ @Override
+ public Builder<U128> xor(U128 other) {
+ raw1 ^= other.raw1;
+ raw2 ^= other.raw2;
+ return this;
+ }
+
+ @Override
+ public U128 build() {
+ return U128.of(raw1, raw2);
+ }
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java
index dcd812d..f15544f 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java
@@ -179,4 +179,59 @@
}
}
+ @Override
+ public HashValue.Builder<U64> builder() {
+ return new U64Builder(raw);
+ }
+
+ static class U64Builder implements Builder<U64> {
+ long raw;
+
+ public U64Builder(long raw) {
+ this.raw = raw;
+ }
+
+ @Override
+ public Builder<U64> add(U64 other) {
+ raw += other.raw;
+ return this;
+ }
+
+ @Override
+ public Builder<U64> subtract(
+ U64 other) {
+ raw -= other.raw;
+ return this;
+ }
+
+ @Override
+ public Builder<U64> invert() {
+ raw = ~raw;
+ return this;
+ }
+
+ @Override
+ public Builder<U64> or(U64 other) {
+ raw |= other.raw;
+ return this;
+ }
+
+ @Override
+ public Builder<U64> and(U64 other) {
+ raw &= other.raw;
+ return this;
+ }
+
+ @Override
+ public Builder<U64> xor(U64 other) {
+ raw ^= other.raw;
+ return this;
+ }
+
+ @Override
+ public U64 build() {
+ return U64.of(raw);
+ }
+ }
+
}