src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java

Print this page

        

*** 33,43 **** * http://creativecommons.org/publicdomain/zero/1.0/ */ package java.util.concurrent; import java.util.*; - import sun.misc.Unsafe; /** * A scalable concurrent {@link NavigableSet} implementation based on * a {@link ConcurrentSkipListMap}. The elements of the set are kept * sorted according to their {@linkplain Comparable natural ordering}, --- 33,42 ----
*** 156,174 **** * instance. (The elements themselves are not cloned.) * * @return a shallow copy of this set */ public ConcurrentSkipListSet<E> clone() { - ConcurrentSkipListSet<E> clone = null; try { ! clone = (ConcurrentSkipListSet<E>) super.clone(); ! clone.setMap(new ConcurrentSkipListMap(m)); } catch (CloneNotSupportedException e) { throw new InternalError(); } - - return clone; } /* ---------------- Set operations -------------- */ /** --- 155,173 ---- * instance. (The elements themselves are not cloned.) * * @return a shallow copy of this set */ public ConcurrentSkipListSet<E> clone() { try { ! @SuppressWarnings("unchecked") ! ConcurrentSkipListSet<E> clone = ! (ConcurrentSkipListSet<E>) super.clone(); ! clone.setMap(new ConcurrentSkipListMap<E,Object>(m)); ! return clone; } catch (CloneNotSupportedException e) { throw new InternalError(); } } /* ---------------- Set operations -------------- */ /**
*** 320,331 **** * of its elements are null */ public boolean removeAll(Collection<?> c) { // Override AbstractSet version to avoid unnecessary call to size() boolean modified = false; ! for (Iterator<?> i = c.iterator(); i.hasNext(); ) ! if (remove(i.next())) modified = true; return modified; } /* ---------------- Relational operations -------------- */ --- 319,330 ---- * of its elements are null */ public boolean removeAll(Collection<?> c) { // Override AbstractSet version to avoid unnecessary call to size() boolean modified = false; ! for (Object e : c) ! if (remove(e)) modified = true; return modified; } /* ---------------- Relational operations -------------- */
*** 466,476 **** * view of {@code s} essentially equivalent to {@code s}. * * @return a reverse order view of this set */ public NavigableSet<E> descendingSet() { ! return new ConcurrentSkipListSet(m.descendingMap()); } // Support for resetting map in clone private void setMap(ConcurrentNavigableMap<E,Object> map) { UNSAFE.putObjectVolatile(this, mapOffset, map); --- 465,475 ---- * view of {@code s} essentially equivalent to {@code s}. * * @return a reverse order view of this set */ public NavigableSet<E> descendingSet() { ! return new ConcurrentSkipListSet<E>(m.descendingMap()); } // Support for resetting map in clone private void setMap(ConcurrentNavigableMap<E,Object> map) { UNSAFE.putObjectVolatile(this, mapOffset, map);
*** 479,489 **** private static final sun.misc.Unsafe UNSAFE; private static final long mapOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class k = ConcurrentSkipListSet.class; mapOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("m")); } catch (Exception e) { throw new Error(e); } --- 478,488 ---- private static final sun.misc.Unsafe UNSAFE; private static final long mapOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class<?> k = ConcurrentSkipListSet.class; mapOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("m")); } catch (Exception e) { throw new Error(e); }