本文整理汇总了Java中java.beans.VetoableChangeListener.equals方法的典型用法代码示例。如果您正苦于以下问题:Java VetoableChangeListener.equals方法的具体用法?Java VetoableChangeListener.equals怎么用?Java VetoableChangeListener.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.VetoableChangeListener
的用法示例。
在下文中一共展示了VetoableChangeListener.equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addVetoableChangeListenerIfAbsent
import java.beans.VetoableChangeListener; //导入方法依赖的package包/类
/**
* Add a PropertyChangeListener to the listener list if it is
* not already present.
* The listener is registered for all properties.
* The operation maintains Set semantics: If the listener is already
* registered, the operation has no effect.
*
* @param listener The PropertyChangeListener to be added
* @exception NullPointerException If listener is null
*/
public synchronized void addVetoableChangeListenerIfAbsent(VetoableChangeListener listener) {
if (listener == null) throw new NullPointerException();
// Copy while checking if already present.
int len = listeners.length;
VetoableChangeListener[] newArray = new VetoableChangeListener[len + 1];
for (int i = 0; i < len; ++i) {
newArray[i] = listeners[i];
if (listener.equals(listeners[i]))
return; // already present -- throw away copy
}
newArray[len] = listener;
listeners = newArray;
}
示例2: removeVetoableChangeListener
import java.beans.VetoableChangeListener; //导入方法依赖的package包/类
/**
* Remove an occurrence of a VetoableChangeListener from the listener list.
* It removes at most one occurrence of the given listener.
* If the listener was added multiple times it must be removed
* mulitple times.
* This removes a VetoableChangeListener that was registered
* for all properties, and has no effect if registered for only
* one or more specified properties.
*
* @param listener The VetoableChangeListener to be removed
*/
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
int newlen = listeners.length-1;
if (newlen < 0 || listener == null) return;
// Copy while searching for element to remove
VetoableChangeListener[] newArray = new VetoableChangeListener[newlen];
for (int i = 0; i < newlen; ++i) {
if (listener.equals(listeners[i])) {
// copy remaining and exit
for (int k = i + 1; k <= newlen; ++k) newArray[k-1] = listeners[k];
listeners = newArray;
return;
}
else
newArray[i] = listeners[i];
}
// special-case last cell
if (listener.equals(listeners[newlen]))
listeners = newArray;
}