Esempio n. 1
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (!(obj instanceof HSBType)) {
     return false;
   }
   HSBType other = (HSBType) obj;
   if ((getHue() != null && other.getHue() == null)
       || (getHue() == null && other.getHue() != null)
       || (getSaturation() != null && other.getSaturation() == null)
       || (getSaturation() == null && other.getSaturation() != null)
       || (getBrightness() != null && other.getBrightness() == null)
       || (getBrightness() == null && other.getBrightness() != null)) {
     return false;
   }
   if (!getHue().equals(other.getHue())
       || !getSaturation().equals(other.getSaturation())
       || !getBrightness().equals(other.getBrightness())) {
     return false;
   }
   return true;
 }
  /**
   * Transforms the given {@link HSBType} into a light state.
   *
   * @param hsbType HSB type
   * @return light state representing the {@link HSBType}.
   */
  public static StateUpdate toColorLightState(HSBType hsbType) {
    int hue = (int) Math.round(hsbType.getHue().doubleValue() * HUE_FACTOR);
    int saturation = (int) Math.round(hsbType.getSaturation().doubleValue() * SATURATION_FACTOR);
    int brightness = (int) Math.round(hsbType.getBrightness().doubleValue() * BRIGHTNESS_FACTOR);

    StateUpdate stateUpdate = new StateUpdate().setHue(hue).setSat(saturation);
    if (brightness > 0) {
      stateUpdate.setBrightness(brightness);
    }
    return stateUpdate;
  }