Skip to content
Snippets Groups Projects
Commit fd70b1d3 authored by Max Gaukler's avatar Max Gaukler
Browse files

improve LaserProperty and subclasses: add .equals(), .hashCode() so that the...

improve LaserProperty and subclasses: add .equals(), .hashCode() so that the GUI can compare laserProperties and see if they have been changed
also add .toString() for some of the subclasses - helpful for the dummy driver
parent d81f7fd4
No related branches found
No related tags found
No related merge requests found
......@@ -215,7 +215,7 @@ public class FloatPowerSpeedFocusFrequencyProperty implements LaserProperty
{
throw new IllegalArgumentException("Unknown setting '"+name+"'");
}
}
}
@Override
public Object[] getPossibleValues(String name)
......@@ -223,4 +223,39 @@ public class FloatPowerSpeedFocusFrequencyProperty implements LaserProperty
return null;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final FloatPowerSpeedFocusFrequencyProperty other = (FloatPowerSpeedFocusFrequencyProperty) obj;
if (Float.floatToIntBits(this.power) != Float.floatToIntBits(other.power)) {
return false;
}
if (Float.floatToIntBits(this.speed) != Float.floatToIntBits(other.speed)) {
return false;
}
if (Float.floatToIntBits(this.focus) != Float.floatToIntBits(other.focus)) {
return false;
}
if (this.frequency != other.frequency) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 67 * hash + Float.floatToIntBits(this.power);
hash = 67 * hash + Float.floatToIntBits(this.speed);
hash = 67 * hash + Float.floatToIntBits(this.focus);
hash = 67 * hash + this.frequency;
return hash;
}
}
......@@ -41,4 +41,9 @@ public interface LaserProperty extends Cloneable, Customizable
public abstract Object[] getPossibleValues(String name);
public abstract LaserProperty clone();
// Please override equals so that it works well
// Otherwise there is trouble in the GUI when it tries to compare laser settings
@Override
public abstract boolean equals(Object obj);
}
......@@ -128,4 +128,30 @@ public class PowerSpeedFocusFrequencyProperty extends PowerSpeedFocusProperty
p.setFocus(getFocus());
return p;
}
@Override
public int hashCode() {
int hash = 7*frequency + super.hashCode();
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PowerSpeedFocusFrequencyProperty other = (PowerSpeedFocusFrequencyProperty) obj;
if (this.frequency != other.frequency) {
return false;
}
return super.equals(obj);
}
public String toString()
{
return "PowerSpeedFocusFrequencyProperty(power="+getPower()+",speed="+getSpeed()+",focus="+getFocus()+",frequency="+getFrequency()+")";
}
}
......@@ -197,4 +197,42 @@ public class PowerSpeedFocusProperty implements LaserProperty
{
return null;
}
@Override
public String toString()
{
return "PowerSpeedFocusFrequencyProperty(power="+getPower()+",speed="+getSpeed()+",focus="+getFocus()+")";
}
@Override
public int hashCode() {
int hash = 3;
hash = 71 * hash + this.power;
hash = 71 * hash + this.speed;
hash = 71 * hash + Float.floatToIntBits(this.focus);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PowerSpeedFocusProperty other = (PowerSpeedFocusProperty) obj;
if (this.power != other.power) {
return false;
}
if (this.speed != other.speed) {
return false;
}
if (Float.floatToIntBits(this.focus) != Float.floatToIntBits(other.focus)) {
return false;
}
return true;
}
}
......@@ -124,5 +124,33 @@ public class LaosCutterProperty extends FloatPowerSpeedFocusFrequencyProperty {
}
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LaosCutterProperty other = (LaosCutterProperty) obj;
if (this.ventilation != other.ventilation) {
return false;
}
if (this.purge != other.purge) {
return false;
}
return super.equals(other);
}
@Override
public int hashCode() {
int hash = 5;
hash = 97 * hash + (this.ventilation ? 1 : 0);
hash = 97 * hash + (this.purge ? 1 : 0);
hash = 97 * hash + super.hashCode();
return hash;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment