首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

HashObject之LinkedHashObjectMap(一)

2012-12-25 
HashObject之LinkedHashObjectMap(1)import java.util.ConcurrentModificationExceptionimport java.util

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;
}
   

热点排行