类org.springframework.util.ConcurrentReferenceHashMap.Entry源码实例Demo

下面列出了怎么用org.springframework.util.ConcurrentReferenceHashMap.Entry的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
protected ReferenceManager createReferenceManager() {
	return new ReferenceManager() {
		@Override
		public Reference<K, V> createReference(Entry<K, V> entry, int hash, @Nullable Reference<K, V> next) {
			if (TestWeakConcurrentCache.this.disableTestHooks) {
				return super.createReference(entry, hash, next);
			}
			return new MockReference<>(entry, hash, next, TestWeakConcurrentCache.this.queue);
		}
		@Override
		public Reference<K, V> pollForPurge() {
			if (TestWeakConcurrentCache.this.disableTestHooks) {
				return super.pollForPurge();
			}
			return TestWeakConcurrentCache.this.queue.isEmpty() ? null : TestWeakConcurrentCache.this.queue.removeFirst();
		}
	};
}
 
@Override
protected ReferenceManager createReferenceManager() {
	return new ReferenceManager() {
		@Override
		public Reference<K, V> createReference(Entry<K, V> entry, int hash, @Nullable Reference<K, V> next) {
			if (TestWeakConcurrentCache.this.disableTestHooks) {
				return super.createReference(entry, hash, next);
			}
			return new MockReference<>(entry, hash, next, TestWeakConcurrentCache.this.queue);
		}
		@Override
		public Reference<K, V> pollForPurge() {
			if (TestWeakConcurrentCache.this.disableTestHooks) {
				return super.pollForPurge();
			}
			return TestWeakConcurrentCache.this.queue.isEmpty() ? null : TestWeakConcurrentCache.this.queue.removeFirst();
		}
	};
}
 
@Override
protected ReferenceManager createReferenceManager() {
	return new ReferenceManager() {
		@Override
		public Reference<K, V> createReference(Entry<K, V> entry, int hash,
				Reference<K, V> next) {
			if (TestWeakConcurrentCache.this.disableTestHooks) {
				return super.createReference(entry, hash, next);
			}
			return new MockReference<K, V>(entry, hash, next, TestWeakConcurrentCache.this.queue);
		}
		@Override
		public Reference<K, V> pollForPurge() {
			if (TestWeakConcurrentCache.this.disableTestHooks) {
				return super.pollForPurge();
			}
			return TestWeakConcurrentCache.this.queue.isEmpty() ? null : TestWeakConcurrentCache.this.queue.removeFirst();
		}
	};
}
 
@Test
public void shouldRemoveViaEntrySet() {
	this.map.put(1, "1");
	this.map.put(2, "2");
	this.map.put(3, "3");
	Iterator<Map.Entry<Integer, String>> iterator = this.map.entrySet().iterator();
	iterator.next();
	iterator.next();
	iterator.remove();
	iterator.next();
	assertThat(iterator.hasNext(), is(false));
	assertThat(this.map.size(), is(2));
	assertThat(this.map.containsKey(2), is(false));
}
 
@Test
public void shouldSetViaEntrySet() {
	this.map.put(1, "1");
	this.map.put(2, "2");
	this.map.put(3, "3");
	Iterator<Map.Entry<Integer, String>> iterator = this.map.entrySet().iterator();
	iterator.next();
	iterator.next().setValue("2b");
	iterator.next();
	assertThat(iterator.hasNext(), is(false));
	assertThat(this.map.size(), is(3));
	assertThat(this.map.get(2), is("2b"));
}
 
@Test
public void shouldRemoveViaEntrySet() {
	this.map.put(1, "1");
	this.map.put(2, "2");
	this.map.put(3, "3");
	Iterator<Map.Entry<Integer, String>> iterator = this.map.entrySet().iterator();
	iterator.next();
	iterator.next();
	iterator.remove();
	iterator.next();
	assertThat(iterator.hasNext(), is(false));
	assertThat(this.map.size(), is(2));
	assertThat(this.map.containsKey(2), is(false));
}
 
@Test
public void shouldSetViaEntrySet() {
	this.map.put(1, "1");
	this.map.put(2, "2");
	this.map.put(3, "3");
	Iterator<Map.Entry<Integer, String>> iterator = this.map.entrySet().iterator();
	iterator.next();
	iterator.next().setValue("2b");
	iterator.next();
	assertThat(iterator.hasNext(), is(false));
	assertThat(this.map.size(), is(3));
	assertThat(this.map.get(2), is("2b"));
}
 
@Test
public void shouldRemoveViaEntrySet() throws Exception {
	this.map.put(1, "1");
	this.map.put(2, "2");
	this.map.put(3, "3");
	Iterator<Map.Entry<Integer, String>> iterator = this.map.entrySet().iterator();
	iterator.next();
	iterator.next();
	iterator.remove();
	iterator.next();
	assertThat(iterator.hasNext(), is(false));
	assertThat(this.map.size(), is(2));
	assertThat(this.map.containsKey(2), is(false));
}
 
@Test
public void shouldSetViaEntrySet() throws Exception {
	this.map.put(1, "1");
	this.map.put(2, "2");
	this.map.put(3, "3");
	Iterator<Map.Entry<Integer, String>> iterator = this.map.entrySet().iterator();
	iterator.next();
	iterator.next().setValue("2b");
	iterator.next();
	assertThat(iterator.hasNext(), is(false));
	assertThat(this.map.size(), is(3));
	assertThat(this.map.get(2), is("2b"));
}
 
public MockReference(Entry<K, V> entry, int hash, Reference<K, V> next, LinkedList<MockReference<K, V>> queue) {
	this.hash = hash;
	this.entry = entry;
	this.next = next;
	this.queue = queue;
}
 
@Override
public Entry<K, V> get() {
	return this.entry;
}
 
public MockReference(Entry<K, V> entry, int hash, Reference<K, V> next, LinkedList<MockReference<K, V>> queue) {
	this.hash = hash;
	this.entry = entry;
	this.next = next;
	this.queue = queue;
}
 
@Override
public Entry<K, V> get() {
	return this.entry;
}
 
public MockReference(Entry<K, V> entry, int hash, Reference<K, V> next, LinkedList<MockReference<K, V>> queue) {
	this.hash = hash;
	this.entry = entry;
	this.next = next;
	this.queue = queue;
}
 
@Override
public Entry<K, V> get() {
	return this.entry;
}
 
 类所在包
 类方法
 同包方法