89 *
90 * @param map backing map
91 */
92 private ReferencedKeySet(ReferencedKeyMap<T, ReferenceKey<T>> map) {
93 this.map = map;
94 }
95
96 /**
97 * Create a new {@link ReferencedKeySet} elements.
98 *
99 * @param isSoft true if {@link SoftReference} elements are to
100 * be used, {@link WeakReference} otherwise.
101 * @param supplier {@link Supplier} of the backing map
102 *
103 * @return a new set with {@link Reference} elements
104 *
105 * @param <E> the type of elements maintained by this set
106 */
107 public static <E> ReferencedKeySet<E>
108 create(boolean isSoft, Supplier<Map<ReferenceKey<E>, ReferenceKey<E>>> supplier) {
109 return create(isSoft, false, supplier);
110 }
111
112 /**
113 * Create a new {@link ReferencedKeySet} elements.
114 *
115 * @param isSoft true if {@link SoftReference} elements are to
116 * be used, {@link WeakReference} otherwise.
117 * @param useNativeQueue true if uses NativeReferenceQueue
118 * otherwise use {@link ReferenceQueue}.
119 * @param supplier {@link Supplier} of the backing map
120 *
121 * @return a new set with {@link Reference} elements
122 *
123 * @param <E> the type of elements maintained by this set
124 */
125 public static <E> ReferencedKeySet<E>
126 create(boolean isSoft, boolean useNativeQueue, Supplier<Map<ReferenceKey<E>, ReferenceKey<E>>> supplier) {
127 return new ReferencedKeySet<>(ReferencedKeyMap.create(isSoft, useNativeQueue, supplier));
128 }
129
130 /**
131 * Removes enqueued weak references from set.
132 */
133 public void removeStaleReferences() {
134 map.removeStaleReferences();
135 }
136
137 @Override
138 public Iterator<T> iterator() {
139 return map.keySet().iterator();
140 }
141
142 @Override
143 public int size() {
144 return map.size();
145 }
146
147 @Override
|
89 *
90 * @param map backing map
91 */
92 private ReferencedKeySet(ReferencedKeyMap<T, ReferenceKey<T>> map) {
93 this.map = map;
94 }
95
96 /**
97 * Create a new {@link ReferencedKeySet} elements.
98 *
99 * @param isSoft true if {@link SoftReference} elements are to
100 * be used, {@link WeakReference} otherwise.
101 * @param supplier {@link Supplier} of the backing map
102 *
103 * @return a new set with {@link Reference} elements
104 *
105 * @param <E> the type of elements maintained by this set
106 */
107 public static <E> ReferencedKeySet<E>
108 create(boolean isSoft, Supplier<Map<ReferenceKey<E>, ReferenceKey<E>>> supplier) {
109 return new ReferencedKeySet<>(ReferencedKeyMap.create(isSoft, supplier));
110 }
111
112 /**
113 * Removes enqueued weak references from set.
114 */
115 public void removeStaleReferences() {
116 map.removeStaleReferences();
117 }
118
119 @Override
120 public Iterator<T> iterator() {
121 return map.keySet().iterator();
122 }
123
124 @Override
125 public int size() {
126 return map.size();
127 }
128
129 @Override
|