java.util.Observable.hasChanged()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中java.util.Observable.hasChanged()方法的一些代码示例,展示了Observable.hasChanged()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.hasChanged()方法的具体详情如下:
包路径:java.util.Observable
类名称:Observable
方法名:hasChanged

Observable.hasChanged介绍

[英]Returns the changed flag for this Observable.
[中]返回此可观察对象的已更改标志。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public void update(Observable o, Object arg)
{
  if(o.hasChanged())
  {
    // do something
  }
}

代码示例来源:origin: stackoverflow.com

public class Connect extends Observable {

  Connection conn;

  public Connect(Observer o) {
    addObserver(o);
  }

  public void getConnection() {
    // TODO getConnection
    hasChanged();
    notifyObservers();
  }

  public void closeConnection() {
    // TODO closeConnection
    hasChanged();
    notifyObservers();
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: com.jtransc/jtransc-rt

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * If {@code hasChanged()} returns {@code true}, calls the {@code update()}
 * method for every Observer in the list of observers using the specified
 * argument. Afterwards calls {@code clearChanged()}.
 *
 * @param data
 *            the argument passed to {@code update()}.
 */
@SuppressWarnings("unchecked")
public void notifyObservers(Object data) {
  int size = 0;
  Observer[] arrays = null;
  synchronized (this) {
    if (hasChanged()) {
      clearChanged();
      size = observers.size();
      arrays = new Observer[size];
      observers.toArray(arrays);
    }
  }
  if (arrays != null) {
    for (Observer observer : arrays) {
      observer.update(this, data);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public class Student extends Observable {

  private int age;

  Student(int age) {
    this.age = age;
  }

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    if (this.age != age) {
      setChanged();
    }

    this.age = age;

    if (hasChanged()) {
      notifyObservers();
    }
  }

  @Override
  public String toString() {
    return "Student [age=" + age + "]";
  }
}

代码示例来源:origin: stackoverflow.com

if(!changing && hasChanged()){
 notifyObservers();

代码示例来源:origin: stackoverflow.com

if (!changing && hasChanged()) {
 notifyObservers();

相关文章