import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.log4j.Logger;
/**
* 这个LinkedHashObjectMap主要是在HashObjectMap基础上
* 实现了双向链表功能。该类不是线程安全的。
*
* @param <T>
*/
public class LinkedHashObjectMap<T extends LinkedBaseHashObject> extends HashObjectMap<T> {
private transient LinkedBaseHashObject header;
private final boolean accessOrder;
private int maxUserCount = 10000;
private static final Logger log = Logger.getLogger(LinkedHashObjectMap.class);
public LinkedHashObjectMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
accessOrder = false;
}
/**
* Constructs an empty insertion-ordered <tt>LinkedHashObjectMap</tt> instance
* with the specified initial capacity and a default load factor (0.75).
*
* @param initialCapacity the initial capacity
* @throws IllegalArgumentException if the initial capacity is negative
*/
public LinkedHashObjectMap(int initialCapacity) {
super(initialCapacity);
accessOrder = false;
}
/**
* Constructs an empty insertion-ordered <tt>LinkedHashObjectMap</tt> instance
* with the default initial capacity (16) and load factor (0.75).
*/
public LinkedHashObjectMap() {
super();
accessOrder = false;
}
public LinkedHashObjectMap(int initialCapacity,
float loadFactor,
boolean accessOrder) {
super(initialCapacity, loadFactor);
this.accessOrder = accessOrder;
}
public void init() {
header = new HeaderLinkedBaseHashObject();
header.before = header.after = header;
}
void transfer(LinkedBaseHashObject[] newTable) {
int newCapacity = newTable.length;
for (LinkedBaseHashObject e = header.after; e != header; e = e.after) {
int index = indexFor(e.keyHashCode(), newCapacity);
e.next = newTable[index];
newTable[index] = e;
}
}
public T get(LinkedBaseHashObject object) {
T e = getObject(object);
if (e == null)
return null;
e.recordAccess(this);
return e;
}
/**
* Removes all of the mappings from this map.
* The map will be empty after this call returns.
*/
public void clear() {
super.clear();
header.before = header.after = header;
}
/**
* 双向链表的头
* @author l90004506
*
*/
class HeaderLinkedBaseHashObject extends LinkedBaseHashObject{
public HeaderLinkedBaseHashObject(){
this.keyHashcode = -1;
}
public void copyObject(BaseHashObject object) {
// TODO Auto-generated method stub
}
public boolean equalsHashObject(BaseHashObject object) {
// TODO Auto-generated method stub
return false;
}
public boolean keyEquals(BaseHashObject object) {
// TODO Auto-generated method stub
return false;
}
}
/**
* 是否按访问顺序排序,即将访问过的对象置顶。
* @return
*/
public boolean isAccessOrder() {
return accessOrder;
}
/**
* 获取链表头
* @return
*/
protected LinkedBaseHashObject getHeader() {
return header;
}
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.log4j.Logger;
/**
* 这个LinkedHashObjectMap主要是在HashObjectMap基础上
* 实现了双向链表功能。该类不是线程安全的。
*
* @param <T>
*/
public class LinkedHashObjectMap<T extends LinkedBaseHashObject> extends HashObjectMap<T> {
private transient LinkedBaseHashObject header;
private final boolean accessOrder;
private int maxUserCount = 10000;
private static final Logger log = Logger.getLogger(LinkedHashObjectMap.class);
public LinkedHashObjectMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
accessOrder = false;
}
/**
* Constructs an empty insertion-ordered <tt>LinkedHashObjectMap</tt> instance
* with the specified initial capacity and a default load factor (0.75).
*
* @param initialCapacity the initial capacity
* @throws IllegalArgumentException if the initial capacity is negative
*/
public LinkedHashObjectMap(int initialCapacity) {
super(initialCapacity);
accessOrder = false;
}
/**
* Constructs an empty insertion-ordered <tt>LinkedHashObjectMap</tt> instance
* with the default initial capacity (16) and load factor (0.75).
*/
public LinkedHashObjectMap() {
super();
accessOrder = false;
}
public LinkedHashObjectMap(int initialCapacity,
float loadFactor,
boolean accessOrder) {
super(initialCapacity, loadFactor);
this.accessOrder = accessOrder;
}
public void init() {
header = new HeaderLinkedBaseHashObject();
header.before = header.after = header;
}
void transfer(LinkedBaseHashObject[] newTable) {
int newCapacity = newTable.length;
for (LinkedBaseHashObject e = header.after; e != header; e = e.after) {
int index = indexFor(e.keyHashCode(), newCapacity);
e.next = newTable[index];
newTable[index] = e;
}
}
public T get(LinkedBaseHashObject object) {
T e = getObject(object);
if (e == null)
return null;
e.recordAccess(this);
return e;
}
/**
* Removes all of the mappings from this map.
* The map will be empty after this call returns.
*/
public void clear() {
super.clear();
header.before = header.after = header;
}
/**
* 双向链表的头
* @author l90004506
*
*/
class HeaderLinkedBaseHashObject extends LinkedBaseHashObject{
public HeaderLinkedBaseHashObject(){
this.keyHashcode = -1;
}
public void copyObject(BaseHashObject object) {
// TODO Auto-generated method stub
}
public boolean equalsHashObject(BaseHashObject object) {
// TODO Auto-generated method stub
return false;
}
public boolean keyEquals(BaseHashObject object) {
// TODO Auto-generated method stub
return false;
}
}
/**
* 是否按访问顺序排序,即将访问过的对象置顶。
* @return
*/
public boolean isAccessOrder() {
return accessOrder;
}
/**
* 获取链表头
* @return
*/
protected LinkedBaseHashObject getHeader() {
return header;
}