| 1 | |
package org.webslinger.lang; |
| 2 | |
|
| 3 | |
import java.util.Collection; |
| 4 | |
import java.util.Comparator; |
| 5 | |
import java.util.Map; |
| 6 | |
import java.util.SortedMap; |
| 7 | |
import java.util.SortedSet; |
| 8 | |
import java.util.Set; |
| 9 | |
|
| 10 | 0 | public class ConcurrentUtil { |
| 11 | |
private static final SortedMapCreator sortedMapCreator; |
| 12 | |
private static final SortedSetCreator sortedSetCreator; |
| 13 | |
static { |
| 14 | 1 | sortedMapCreator = (SortedMapCreator) ClassUtil.loadImplementation("ConcurrentSortedMap", new String[] {"org.webslinger.lang.ConcurrentUtil$Java6ConcurrentSkipListMapCreator", "org.webslinger.lang.ConcurrentUtil$JSR166BackportConcurrentSkipListMapCreator"}, ConcurrentUtil.class.getClassLoader()); |
| 15 | 1 | sortedSetCreator = (SortedSetCreator) ClassUtil.loadImplementation("ConcurrentSortedSet", new String[] {"org.webslinger.lang.ConcurrentUtil$Java6ConcurrentSkipListSetCreator", "org.webslinger.lang.ConcurrentUtil$JSR166BackportConcurrentSkipListSetCreator"}, ConcurrentUtil.class.getClassLoader()); |
| 16 | 1 | } |
| 17 | |
|
| 18 | |
public static <K, V> SortedMap<K, V> createSortedMap() { |
| 19 | 145 | return sortedMapCreator.createMap(); |
| 20 | |
} |
| 21 | |
|
| 22 | |
public static <K, V> SortedMap<K, V> createSortedMap(Comparator<? super K> comparator) { |
| 23 | 0 | return sortedMapCreator.createMap(comparator); |
| 24 | |
} |
| 25 | |
|
| 26 | |
public static <K, V> SortedMap<K, V> createSortedMap(Map<K, V> map) { |
| 27 | 0 | return sortedMapCreator.createMap(map); |
| 28 | |
} |
| 29 | |
|
| 30 | |
public static <K, V> SortedMap<K, V> createSortedMap(SortedMap<K, V> map) { |
| 31 | 0 | return sortedMapCreator.createMap(map); |
| 32 | |
} |
| 33 | |
|
| 34 | |
public static <V> SortedSet<V> createSortedSet() { |
| 35 | 0 | return sortedSetCreator.createSet(); |
| 36 | |
} |
| 37 | |
|
| 38 | |
public static <V> SortedSet<V> createSortedSet(Comparator<? super V> comparator) { |
| 39 | 0 | return sortedSetCreator.createSet(comparator); |
| 40 | |
} |
| 41 | |
|
| 42 | |
public static <V> SortedSet<V> createSortedSet(Set<V> set) { |
| 43 | 0 | return sortedSetCreator.createSet(set); |
| 44 | |
} |
| 45 | |
|
| 46 | |
public static <V> SortedSet<V> createSortedSet(SortedSet<V> set) { |
| 47 | 0 | return sortedSetCreator.createSet(set); |
| 48 | |
} |
| 49 | |
|
| 50 | 1 | public static abstract class SortedMapCreator { |
| 51 | |
protected abstract <K, V> SortedMap<K, V> createMap(); |
| 52 | |
protected abstract <K, V> SortedMap<K, V> createMap(Comparator<? super K> comparator); |
| 53 | |
protected abstract <K, V> SortedMap<K, V> createMap(Map<K, V> map); |
| 54 | |
protected abstract <K, V> SortedMap<K, V> createMap(SortedMap<K, V> map); |
| 55 | |
} |
| 56 | |
|
| 57 | 1 | public static class Java6ConcurrentSkipListMapCreator extends SortedMapCreator { |
| 58 | |
protected <K, V> SortedMap<K, V> createMap() { |
| 59 | 145 | return new java.util.concurrent.ConcurrentSkipListMap<K, V>(); |
| 60 | |
} |
| 61 | |
|
| 62 | |
protected <K, V> SortedMap<K, V> createMap(Comparator<? super K> comparator) { |
| 63 | 0 | return new java.util.concurrent.ConcurrentSkipListMap<K, V>(comparator); |
| 64 | |
} |
| 65 | |
|
| 66 | |
protected <K, V> SortedMap<K, V> createMap(Map<K, V> map) { |
| 67 | 0 | return new java.util.concurrent.ConcurrentSkipListMap<K, V>(map); |
| 68 | |
} |
| 69 | |
|
| 70 | |
protected <K, V> SortedMap<K, V> createMap(SortedMap<K, V> map) { |
| 71 | 0 | return new java.util.concurrent.ConcurrentSkipListMap<K, V>(map); |
| 72 | |
} |
| 73 | |
} |
| 74 | |
|
| 75 | 0 | public static class JSR166BackportConcurrentSkipListMapCreator extends SortedMapCreator { |
| 76 | |
protected <K, V> SortedMap<K, V> createMap() { |
| 77 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListMap(); |
| 78 | |
} |
| 79 | |
|
| 80 | |
protected <K, V> SortedMap<K, V> createMap(Comparator<? super K> comparator) { |
| 81 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListMap(comparator); |
| 82 | |
} |
| 83 | |
|
| 84 | |
protected <K, V> SortedMap<K, V> createMap(Map<K, V> map) { |
| 85 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListMap(map); |
| 86 | |
} |
| 87 | |
|
| 88 | |
protected <K, V> SortedMap<K, V> createMap(SortedMap<K, V> map) { |
| 89 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListMap(map); |
| 90 | |
} |
| 91 | |
} |
| 92 | |
|
| 93 | 1 | public static abstract class SortedSetCreator { |
| 94 | |
protected abstract <V> SortedSet<V> createSet(); |
| 95 | |
protected abstract <V> SortedSet<V> createSet(Comparator<? super V> comparator); |
| 96 | |
protected abstract <V> SortedSet<V> createSet(Set<V> set); |
| 97 | |
protected abstract <V> SortedSet<V> createSet(SortedSet<V> set); |
| 98 | |
} |
| 99 | |
|
| 100 | 1 | public static class Java6ConcurrentSkipListSetCreator extends SortedSetCreator { |
| 101 | |
protected <V> SortedSet<V> createSet() { |
| 102 | 0 | return new java.util.concurrent.ConcurrentSkipListSet<V>(); |
| 103 | |
} |
| 104 | |
|
| 105 | |
protected <V> SortedSet<V> createSet(Comparator<? super V> comparator) { |
| 106 | 0 | return new java.util.concurrent.ConcurrentSkipListSet<V>(comparator); |
| 107 | |
} |
| 108 | |
|
| 109 | |
protected <V> SortedSet<V> createSet(Set<V> set) { |
| 110 | 0 | return new java.util.concurrent.ConcurrentSkipListSet<V>(set); |
| 111 | |
} |
| 112 | |
|
| 113 | |
protected <V> SortedSet<V> createSet(SortedSet<V> set) { |
| 114 | 0 | return new java.util.concurrent.ConcurrentSkipListSet<V>(set); |
| 115 | |
} |
| 116 | |
} |
| 117 | |
|
| 118 | 0 | public static class JSR166BackportConcurrentSkipListSetCreator extends SortedSetCreator { |
| 119 | |
protected <V> SortedSet<V> createSet() { |
| 120 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListSet(); |
| 121 | |
} |
| 122 | |
|
| 123 | |
protected <V> SortedSet<V> createSet(Comparator<? super V> comparator) { |
| 124 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListSet(comparator); |
| 125 | |
} |
| 126 | |
|
| 127 | |
protected <V> SortedSet<V> createSet(Set<V> set) { |
| 128 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListSet(set); |
| 129 | |
} |
| 130 | |
|
| 131 | |
protected <V> SortedSet<V> createSet(SortedSet<V> set) { |
| 132 | 0 | return new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentSkipListSet(set); |
| 133 | |
} |
| 134 | |
} |
| 135 | |
} |