Skip to content
Snippets Groups Projects
Commit 41902a6e authored by René Schöne's avatar René Schöne
Browse files

Make TupleHSB immutable.

parent 1200d613
Branches
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ aspect ItemHandling {
// TupleHSB and String work like default
eq ColorItem.getStateAsDouble() {
logger.warn("getStateAsDouble called on item " + getLabel() + ". Using brightness.");
return getState().brightness;
return getState().getBrightness();
}
eq DateTimeItem.getStateAsDouble() = getState().getTime();
eq ItemWithBooleanState.getStateAsDouble() = getState() ? 1 : 0;
......@@ -87,7 +87,7 @@ aspect ItemHandling {
public abstract void Item.setStateFromLong(long value);
public void ColorItem.setStateFromLong(long value) {
// only set brightness
this.setState(TupleHSB.of(getState().hue, getState().saturation, Math.toIntExact(value)));
this.setState(getState().withDifferentBrightness(Math.toIntExact(value)));
}
public void DateTimeItem.setStateFromLong(long value) {
this.setState(new Date(value));
......@@ -167,10 +167,10 @@ aspect ItemHandling {
logger.warn("Ignoring color update using {} for {}", this, value);
}
public void ItemWithBooleanState.setStateFromColor(TupleHSB value) {
this.setState(value != null && value.brightness > 0);
this.setState(value != null && value.getBrightness() > 0);
}
public void ItemWithDoubleState.setStateFromColor(TupleHSB value) {
this.setState(value.brightness);
this.setState(value.getBrightness());
}
public void ItemWithStringState.setStateFromColor(TupleHSB value) {
this.setState(value.toString());
......@@ -358,9 +358,7 @@ aspect ItemHandling {
}
private void ColorItem.setBrightness(int value) {
TupleHSB newState = getState().clone();
newState.brightness = value;
setState(newState);
setState(getState().withDifferentBrightness(value));
}
//--- ItemPreference.apply ---
......
......@@ -8,9 +8,9 @@ import java.util.Objects;
* @author rschoene - Initial contribution
*/
public class TupleHSB implements Cloneable {
public int hue;
public int saturation;
public int brightness;
private int hue;
private int saturation;
private int brightness;
public static TupleHSB of(int hue, int saturation, int brightness) {
TupleHSB result = new TupleHSB();
result.hue = hue;
......@@ -19,6 +19,30 @@ public class TupleHSB implements Cloneable {
return result;
}
public int getHue() {
return hue;
}
public int getSaturation() {
return saturation;
}
public int getBrightness() {
return brightness;
}
public TupleHSB withDifferentHue(int hue) {
return TupleHSB.of(hue, this.saturation, this.brightness);
}
public TupleHSB withDifferentSaturation(int saturation) {
return TupleHSB.of(this.hue, saturation, this.brightness);
}
public TupleHSB withDifferentBrightness(int brightness) {
return TupleHSB.of(this.hue, this.saturation, brightness);
}
public String toString() {
return String.format("%s,%s,%s", hue, saturation, brightness);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment