@Test public void testClone() throws Exception { CallbackRegistry.NotifierCallback<Integer, CallbackRegistryTest, Integer> notifier = new CallbackRegistry.NotifierCallback<Integer, CallbackRegistryTest, Integer>() { @Override public void onNotifyCallback(Integer callback, CallbackRegistryTest sender, int arg, Integer arg2) { } }; registry = new CallbackRegistry<Integer, CallbackRegistryTest, Integer>(notifier); assertTrue(registry.isEmpty()); CallbackRegistry<Integer, CallbackRegistryTest, Integer> registry2 = registry.clone(); Integer callback = 0; registry.add(callback); assertFalse(registry.isEmpty()); assertTrue(registry2.isEmpty()); registry2 = registry.clone(); assertFalse(registry2.isEmpty()); }
@SuppressWarnings("unchecked") public synchronized CallbackRegistry<C, T, A> clone() { CallbackRegistry<C, T, A> clone = null; try { clone = (CallbackRegistry<C, T, A>) super.clone(); clone.mFirst64Removed = 0; clone.mRemainderRemoved = null; clone.mNotificationLevel = 0; clone.mCallbacks = new ArrayList<C>(); final int numListeners = mCallbacks.size(); for (int i = 0; i < numListeners; i++) { if (!isRemoved(i)) { clone.mCallbacks.add(mCallbacks.get(i)); } } } catch (CloneNotSupportedException e) { e.printStackTrace(); } return clone; }
CallbackRegistry implements Cloneable { @SuppressWarnings("unchecked") public synchronized CallbackRegistry<C, T, A> clone() { CallbackRegistry<C, T, A> clone = null; try { clone = (CallbackRegistry<C, T, A>) super.clone(); clone.mFirst64Removed = 0; clone.mRemainderRemoved = null; clone.mNotificationLevel = 0; clone.mCallbacks = new ArrayList<C>(); final int numListeners = mCallbacks.size(); for (int i = 0; i < numListeners; i++) { if (!isRemoved(i)) { clone.mCallbacks.add(mCallbacks.get(i)); } } } catch (CloneNotSupportedException e) { e.printStackTrace(); } return clone; } }
CallbackRegistry implements Cloneable { @SuppressWarnings("unchecked") public synchronized CallbackRegistry<C, T, A> clone() { CallbackRegistry<C, T, A> clone = null; try { clone = (CallbackRegistry<C, T, A>) super.clone(); clone.mFirst64Removed = 0; clone.mRemainderRemoved = null; clone.mNotificationLevel = 0; clone.mCallbacks = new ArrayList<C>(); final int numListeners = mCallbacks.size(); for (int i = 0; i < numListeners; i++) { if (!isRemoved(i)) { clone.mCallbacks.add(mCallbacks.get(i)); } } } catch (CloneNotSupportedException e) { e.printStackTrace(); } return clone; } CallbackRegistry(NotifierCallback<C, T, A> notifier); }
CallbackRegistry implements Cloneable { @SuppressWarnings("unchecked") public synchronized CallbackRegistry<C, T, A> clone() { CallbackRegistry<C, T, A> clone = null; try { clone = (CallbackRegistry<C, T, A>) super.clone(); clone.mFirst64Removed = 0; clone.mRemainderRemoved = null; clone.mNotificationLevel = 0; clone.mCallbacks = new ArrayList<C>(); final int numListeners = mCallbacks.size(); for (int i = 0; i < numListeners; i++) { if (!isRemoved(i)) { clone.mCallbacks.add(mCallbacks.get(i)); } } } catch (CloneNotSupportedException e) { e.printStackTrace(); } return clone; } CallbackRegistry(NotifierCallback<C, T, A> notifier); synchronized void notifyCallbacks(T sender, int arg, A arg2); synchronized void add(C callback); synchronized void remove(C callback); synchronized ArrayList<C> copyCallbacks(); synchronized void copyCallbacks(List<C> callbacks); synchronized boolean isEmpty(); synchronized void clear(); @SuppressWarnings("unchecked") synchronized CallbackRegistry<C, T, A> clone(); }
CallbackRegistry implements Cloneable { @SuppressWarnings("unchecked") public synchronized CallbackRegistry<C, T, A> clone() { CallbackRegistry<C, T, A> clone = null; try { clone = (CallbackRegistry<C, T, A>) super.clone(); clone.mFirst64Removed = 0; clone.mRemainderRemoved = null; clone.mNotificationLevel = 0; clone.mCallbacks = new ArrayList<C>(); final int numListeners = mCallbacks.size(); for (int i = 0; i < numListeners; i++) { if (!isRemoved(i)) { clone.mCallbacks.add(mCallbacks.get(i)); } } } catch (CloneNotSupportedException e) { e.printStackTrace(); } return clone; } CallbackRegistry(NotifierCallback<C, T, A> notifier); synchronized void notifyCallbacks(T sender, int arg, A arg2); synchronized void add(C callback); synchronized void remove(C callback); synchronized ArrayList<C> copyCallbacks(); synchronized void copyCallbacks(List<C> callbacks); synchronized boolean isEmpty(); synchronized void clear(); @SuppressWarnings("unchecked") synchronized CallbackRegistry<C, T, A> clone();  }