1 16 package org.apache.commons.collections.set; 17 18 import java.util.Comparator ; 19 import java.util.SortedSet ; 20 21 import org.apache.commons.collections.collection.SynchronizedCollection; 22 23 36 public class SynchronizedSortedSet extends SynchronizedCollection implements SortedSet { 37 38 39 private static final long serialVersionUID = 2775582861954500111L; 40 41 47 public static SortedSet decorate(SortedSet set) { 48 return new SynchronizedSortedSet(set); 49 } 50 51 58 protected SynchronizedSortedSet(SortedSet set) { 59 super(set); 60 } 61 62 69 protected SynchronizedSortedSet(SortedSet set, Object lock) { 70 super(set, lock); 71 } 72 73 78 protected SortedSet getSortedSet() { 79 return (SortedSet ) collection; 80 } 81 82 public SortedSet subSet(Object fromElement, Object toElement) { 84 synchronized (lock) { 85 SortedSet set = getSortedSet().subSet(fromElement, toElement); 86 return new SynchronizedSortedSet(set, lock); 89 } 90 } 91 92 public SortedSet headSet(Object toElement) { 93 synchronized (lock) { 94 SortedSet set = getSortedSet().headSet(toElement); 95 return new SynchronizedSortedSet(set, lock); 98 } 99 } 100 101 public SortedSet tailSet(Object fromElement) { 102 synchronized (lock) { 103 SortedSet set = getSortedSet().tailSet(fromElement); 104 return new SynchronizedSortedSet(set, lock); 107 } 108 } 109 110 public Object first() { 111 synchronized (lock) { 112 return getSortedSet().first(); 113 } 114 } 115 116 public Object last() { 117 synchronized (lock) { 118 return getSortedSet().last(); 119 } 120 } 121 122 public Comparator comparator() { 123 synchronized (lock) { 124 return getSortedSet().comparator(); 125 } 126 } 127 128 } 129 | Popular Tags |