⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deathobjectbuffer.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Core License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id$

package org.ozoneDB.core.storage.classicStore;

import org.ozoneDB.DxLib.DxHashMap;
import org.ozoneDB.DxLib.DxMap;
import org.ozoneDB.core.ObjectID;
import org.ozoneDB.core.storage.classicStore.DeathObject;

/**
 * @author <a href="http://www.softwarebuero.de/">SMB</a>
 */
public class DeathObjectBuffer extends Object {

    /** all objects ordered by their ObjectID */
    public DxMap objects;

    /** head and tail of the double linked list */
    DeathObject head;
    DeathObject tail;

    int bufferSize = 0;


    /** the constructor */
    public DeathObjectBuffer() {
        objects = new DxHashMap();
        head = new DeathObject();
        tail = new DeathObject();
        head.previous = tail;
        tail.next = head;
    }


    /** returns the current size of the buffer */
    public final int size() {
        return bufferSize;
    }


    /** returns the current count of objects of the buffer */
    public final int count() {
        return objects.count();
    }


    /**
     */
    public void updateSize( DeathObject obj, boolean sub ) {
        bufferSize += sub ? -obj.size() : obj.size();
    }


    /**
     * adds the object to the bottom of the stack
     */
    public boolean add( DeathObject obj ) {
        boolean result = objects.addForKey( obj, obj.objID() );
        if (result) {
            popOnTop( obj );
            bufferSize += obj.size();
        }
        return result;
    }


    /**
     * removes the object from the stack
     */
    public DeathObject remove( ObjectID oid ) {
        //env.logWriter.newEntry ("DeathObjectBuffer.remove: " + oid, LogWriter.DEBUG3);
        DeathObject obj = (DeathObject)objects.removeForKey( oid );
        if (obj != null) {
            removeFromStack( obj );
            bufferSize -= obj.size();
        }
        return obj;
    }


    /**
     * moves the specified object to the top of the stack
     */
    public boolean moveToTop( ObjectID oid ) {
        DeathObject obj = (DeathObject)objects.elementForKey( oid );
        if (obj != null) {
            removeFromStack( obj );
            popOnTop( obj );
        }
        return obj != null;
    }


    /**
     * removes and returns the object at the bottom
     */
    public DeathObject pushFromBottom() {
        DeathObject obj = tail.next;
        if (obj == head) {
            return null;
        }
        return remove( obj.objID() );
    }


    /**
     * returns the DeathObject for the specified ObjectID
     */
    public DeathObject objectForId( ObjectID oid ) {
        return (DeathObject)objects.elementForKey( oid );
    }


    /**
     * pops the object on the top of the stack
     */
    private void popOnTop( DeathObject obj ) {
        head.previous.next = obj;
        obj.previous = head.previous;
        obj.next = head;
        head.previous = obj;
    }


    /**
     * pops the object on the bottom of the stack
     */
    private void popOnBottom( DeathObject obj ) {
        tail.next.previous = obj;
        obj.next = tail.next;
        obj.previous = tail;
        tail.next = obj;
    }


    /**
     * removes the object from the stack
     */
    private void removeFromStack( DeathObject obj ) {
        obj.previous.next = obj.next;
        obj.next.previous = obj.previous;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -