public static Object removeListener(Object bag, Object listener)
    {
        if (listener == null) throw new IllegalArgumentException();
        if (listener instanceof Object[]) throw new IllegalArgumentException();

        if (bag == listener) {
            bag = null;
        } else if (bag instanceof Object[]) {
            Object[] array = (Object[])bag;
            int L = array.length;
            // bag has at least 2 elements if it is array
            if (L < 2) throw new IllegalArgumentException();
            if (L == 2) {
                if (array[1] == listener) {
                    bag = array[0];
                } else if (array[0] == listener) {
                    bag = array[1];
                }
            } else {
                int i = L;
                do {
                    --i;
                    if (array[i] == listener) {
                        Object[] tmp = new Object[L - 1];
                        System.arraycopy(array, 0, tmp, 0, i);
                        System.arraycopy(array, i + 1, tmp, i, L - (i + 1));
                        bag = tmp;
                        break;
                    }
                } while (i != 0);
            }
        }

        return bag;
    }
public static Object removeListener ( Object bag , Object listener ) { if ( listener == null ) throw new IllegalArgumentException ( ) ; if ( listener instanceof Object [ ] ) throw new IllegalArgumentException ( ) ; if ( bag == listener ) { bag = null ; } else if ( bag instanceof Object [ ] ) { Object [ ] array = ( Object [ ] ) bag ; int L = array . length ; if ( L < 2 ) throw new IllegalArgumentException ( ) ; if ( L == 2 ) { if ( array [ 1 ] == listener ) { bag = array [ 0 ] ; } else if ( array [ 0 ] == listener ) { bag = array [ 1 ] ; } } else { int i = L ; do { -- i ; if ( array [ i ] == listener ) { Object [ ] tmp = new Object [ L - 1 ] ; System . arraycopy ( array , 0 , tmp , 0 , i ) ; System . arraycopy ( array , i + 1 , tmp , i , L - ( i + 1 ) ) ; bag = tmp ; break ; } } while ( i != 0 ) ; } } return bag ; }
Remove <i>listener</i> from <i>bag</i> of listeners.
The function does not modify <i>bag</i> and return a new collection
containing all listeners from <i>bag</i> except <i>listener</i>.
If <i>bag</i> does not contain <i>listener</i>, the function returns
<i>bag</i>.
<p>
For usage example, see {@link #addListener(Object bag, Object listener)}.

@param listener Listener to remove from <i>bag</i>
@param bag Current collection of listeners.
@return A new bag containing all listeners from <i>bag</i> except
<i>listener</i>.
@see #addListener(Object bag, Object listener)
@see #getListener(Object bag, int index)