/** * This method provides a "snapshot" in time of the bag items. It * does not "lock" or reserve items in any way. Call <code>reserve(T)</code> * on items in the list, or understand the concurrency implications of * modifying items, before performing any action on them. * * @return a possibly empty list of (all) bag items */ @SuppressWarnings("unchecked") public List<T> values() { return (List<T>) sharedList.clone(); }
/** * Attempts to use native {@link Object#clone()} methods on available map * types. If a list cannot be properly cloned, a new {@link ArrayList} is * returned. * * @param list The list input * @param <T> The value type * @return A copied list */ @SuppressWarnings("unchecked") public static <T> List<T> copyList(List<? extends T> list) { try { if (list instanceof ArrayList) { return (List<T>) ((ArrayList<? extends T>) list).clone(); } else if (list instanceof LinkedList) { return (List<T>) ((LinkedList<? extends T>) list).clone(); } else if (list instanceof CopyOnWriteArrayList) { return (List<T>) ((CopyOnWriteArrayList<T>) list).clone(); } } catch (Exception ignored) { } return new ArrayList<>(list); }
@SuppressWarnings("unchecked") private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { return (CopyOnWriteArrayList<Host>) list.clone(); }
final List<Host> hosts = (List<Host>) liveHosts.clone(); final int startIdx = index.getAndIncrement();
@SuppressWarnings ("unchecked") private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { return (CopyOnWriteArrayList<Host>) list.clone(); }
/** * Method returns a cloned List of all {@link XMPPResourceConnection} objects * related to this {@link XMPPSession} object */ @SuppressWarnings({ "unchecked" }) public List<XMPPResourceConnection> getActiveResourcesClone() { return (List<XMPPResourceConnection>) activeResources.clone(); }
/** * This method provides a "snapshot" in time of the bag items. It * does not "lock" or reserve items in any way. Call <code>reserve(T)</code> * on items in the list, or understand the concurrency implications of * modifying items, before performing any action on them. * * @return a possibly empty list of (all) bag items */ @SuppressWarnings("unchecked") public List<T> values() { return (List<T>) sharedList.clone(); }
@SuppressWarnings("unchecked") @Override public List<DependencyContext> getDependencies() { return (List<DependencyContext>) m_dependencies.clone(); }
/** * This method provides a "snapshot" in time of the bag items. It * does not "lock" or reserve items in any way. Call <code>reserve(T)</code> * on items in the list, or understand the concurrency implications of * modifying items, before performing any action on them. * * @return a possibly empty list of (all) bag items */ @SuppressWarnings("unchecked") public List<T> values() { return (List<T>) sharedList.clone(); }
@SuppressWarnings("unchecked") private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { return (CopyOnWriteArrayList<Host>) list.clone(); }
/** * This method provides a "snapshot" in time of the bag items. It * does not "lock" or reserve items in any way. Call <code>reserve(T)</code> * on items in the list, or understand the concurrency implications of * modifying items, before performing any action on them. * * @return a possibly empty list of (all) bag items */ @SuppressWarnings("unchecked") public List<T> values() { return (List<T>) sharedList.clone(); }
@SuppressWarnings("unchecked") private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { return (CopyOnWriteArrayList<Host>)list.clone(); }
@SuppressWarnings("unchecked") private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { return (CopyOnWriteArrayList<Host>) list.clone(); }
@SuppressWarnings("unchecked") private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { return (CopyOnWriteArrayList<Host>) list.clone(); }
public List<T> values() { return (List<T>) sharedList.clone(); }
/** * Gets an unmodifiable list of extensions. * * @return The extensions. * @see #addExtension(rocks.xmpp.extensions.data.model.DataForm) * @see #removeExtension(rocks.xmpp.extensions.data.model.DataForm) * @see <a href="https://xmpp.org/extensions/xep-0128.html">XEP-0128: Service Discovery Extensions</a> */ @SuppressWarnings("unchecked") public final List<DataForm> getExtensions() { return Collections.unmodifiableList((List<DataForm>) extensions.clone()); }
/** * Notifies all registered {@link Listener}s of the given <code>edit</code>. */ private void fireUndoableEditHappened(Edit edit) { // NOTE: We are intentionally dispatching in LIFO order with an iterator // we need to clone before reverse iteration to be thread-safe, see http://stackoverflow.com/a/42046731/336169 List<Listener> listenerListCopy = (List<Listener>) listenerList.clone(); ListIterator<Listener> li = listenerListCopy.listIterator(listenerListCopy.size()); while (li.hasPrevious()) { li.previous().undoableEditHappened(edit); } }
/** delivers the given matcher event to all registered listeners. */ protected final void fireChangedMatcher(MatcherEditor.Event<E> event) { // NOTE: We are intentionally dispatching in LIFO order with an iterator // we need to clone before reverse iteration to be thread-safe, see http://stackoverflow.com/a/42046731/336169 List<Listener<E>> listenerListCopy = (List<Listener<E>>) listenerList.clone(); ListIterator<Listener<E>> li = listenerListCopy.listIterator(listenerListCopy.size()); while (li.hasPrevious()) { li.previous().changedMatcher(event); } }
@Override public E select(C criteria) { @SuppressWarnings("unchecked") final CopyOnWriteArrayList<E> activeHostsSnapshot = (CopyOnWriteArrayList<E>) activeHosts.clone(); if (activeHostsSnapshot.isEmpty()) { log.warn("No active hosts were available. Returning inactive hosts and hoping for the best"); //Overflow protection theNotSoBest.compareAndSet(allHosts.size(), 0); return allHosts.get(theNotSoBest.getAndIncrement()); } else { theBest.compareAndSet(activeHostsSnapshot.size(), 0); return activeHostsSnapshot.get(theBest.getAndIncrement()); } }
@Override public E select(C criteria) { E stickyHost = getStickyHost(criteria); if (stickyHost != null) return stickyHost; @SuppressWarnings("unchecked") final CopyOnWriteArrayList<E> activeHostsSnapshot = (CopyOnWriteArrayList<E>) activeHosts.clone(); if (activeHostsSnapshot.isEmpty()) { log.warn("No active hosts were available. Returning inactive hosts and hoping for the best"); //Overflow protection theNotSoBest.compareAndSet(allHosts.size(), 0); return allHosts.get(theNotSoBest.getAndIncrement()); } else { theBest.compareAndSet(activeHostsSnapshot.size(), 0); final E selectedElement = activeHostsSnapshot.get(theBest.getAndIncrement()); stickyHosts.putIfAbsent(criteria, selectedElement); return selectedElement; } }