-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for mutable ints, longs, and doubles
- Loading branch information
Showing
8 changed files
with
571 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
crux-util/src/main/java/com/fizzed/crux/util/MutableDouble.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.fizzed.crux.util; | ||
|
||
import java.util.Objects; | ||
|
||
public class MutableDouble implements Comparable<MutableDouble> { | ||
|
||
private double value; | ||
|
||
public MutableDouble() { | ||
this.value = 0; | ||
} | ||
|
||
public MutableDouble(double value) { | ||
this.value = value; | ||
} | ||
|
||
public double value() { | ||
return value; | ||
} | ||
|
||
public void value(double value) { | ||
this.value = value; | ||
} | ||
|
||
public double increment() { | ||
this.value++; | ||
return this.value; | ||
} | ||
|
||
public double decrement() { | ||
this.value--; | ||
return this.value; | ||
} | ||
|
||
public double add(double value) { | ||
this.value += value; | ||
return this.value; | ||
} | ||
|
||
public double subtract(double value) { | ||
this.value -= value; | ||
return this.value; | ||
} | ||
|
||
public String toString() { | ||
return Double.toString(this.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public int compareTo(MutableDouble o) { | ||
if (o == null) { | ||
return 1; | ||
} | ||
return Double.compare(this.value, o.value); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
// compare to other mutable integers | ||
if (o instanceof MutableDouble) { | ||
MutableDouble that = (MutableDouble) o; | ||
return value == that.value; | ||
} | ||
if (o instanceof Number) { | ||
Number that = (Number) o; | ||
return value == that.doubleValue(); | ||
} | ||
return false; | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
crux-util/src/main/java/com/fizzed/crux/util/MutableInteger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.fizzed.crux.util; | ||
|
||
import java.util.Comparator; | ||
import java.util.Objects; | ||
|
||
public class MutableInteger implements Comparable<MutableInteger> { | ||
|
||
private int value; | ||
|
||
public MutableInteger() { | ||
this.value = 0; | ||
} | ||
|
||
public MutableInteger(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int value() { | ||
return value; | ||
} | ||
|
||
public void value(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int increment() { | ||
this.value++; | ||
return this.value; | ||
} | ||
|
||
public int decrement() { | ||
this.value--; | ||
return this.value; | ||
} | ||
|
||
public int add(int value) { | ||
this.value += value; | ||
return this.value; | ||
} | ||
|
||
public int subtract(int value) { | ||
this.value -= value; | ||
return this.value; | ||
} | ||
|
||
public String toString() { | ||
return Integer.toString(this.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public int compareTo(MutableInteger o) { | ||
if (o == null) { | ||
return 1; | ||
} | ||
return Integer.compare(this.value, o.value); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
// compare to other mutable integers | ||
if (o instanceof MutableInteger) { | ||
MutableInteger that = (MutableInteger) o; | ||
return value == that.value; | ||
} | ||
if (o instanceof Number) { | ||
Number that = (Number) o; | ||
return value == that.intValue(); | ||
} | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.