Skip to content

@BoundPropertySupport @BoundSetter

framiere edited this page Nov 24, 2011 · 5 revisions

@BoundPropertySupport/@BoundSetter

- WORK IN PROGRESS - (Initial copy of old documentation)

Overview

Usage

With Lombok

import lombok.AccessLevel;
import lombok.BoundPropertySupport;
import lombok.BoundSetter;

@BoundPropertySupport
class BoundPropertySupportExample {
  @BoundSetter int i;
  @BoundSetter(AccessLevel.PUBLIC) String s;
  @BoundSetter(AccessLevel.PROTECTED) float f;
  @BoundSetter(AccessLevel.PACKAGE) Object o;
  @BoundSetter(AccessLevel.PRIVATE) double d;
}

Vanilla Java

class BoundPropertySupportExample {
  private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this);

  public static final java.lang.String PROP_I = new java.lang.String("i");
  public static final java.lang.String PROP_S = new java.lang.String("s");
  public static final java.lang.String PROP_F = new java.lang.String("f");
  public static final java.lang.String PROP_O = new java.lang.String("o");
  public static final java.lang.String PROP_D = new java.lang.String("d");

  int i;
  String s;
  float f;
  Object o;
  double d;

  public void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) {
    this.propertySupport.addPropertyChangeListener(listener);
  }

  public void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) {
    this.propertySupport.removePropertyChangeListener(listener);
  }

  public void setI(final int i) {
    final int old = this.i;
    this.i = i;
    this.propertySupport.firePropertyChange(PROP_I, old, this.i);
  }

  public void setS(final String s) {
    final String old = this.s;
    this.s = s;
    this.propertySupport.firePropertyChange(PROP_S, old, this.s);
  }

  protected void setF(final float f) {
    final float old = this.f;
    this.f = f;
    this.propertySupport.firePropertyChange(PROP_F, old, this.f);
  }

  void setO(final Object o) {
    final Object old = this.o;
    this.o = o;
    this.propertySupport.firePropertyChange(PROP_O, old, this.o);
  }

  private void setD(final double d) {
    final double old = this.d;
    this.d = d;
    this.propertySupport.firePropertyChange(PROP_D, old, this.d);
  }
}
Clone this wiki locally