HashObject之LinkedHashObjectMap(1)

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值