alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.mdr.persistence.btreeimpl.btreeindex;
import org.netbeans.mdr.persistence.btreeimpl.btreestorage.*;	/* for MOFID */
import org.netbeans.mdr.persistence.SinglevaluedIndex;
import org.netbeans.mdr.persistence.Storage;
import org.netbeans.mdr.persistence.MOFID;
import org.netbeans.mdr.util.Logger;

/**
 * EntryTypeInfo implementation for type MOFID
 *
 * @author	Dana Bergen
 * @version	1.0
 */

public class MOFIDInfo extends EntryTypeInfo{

    private BtreeStorage storage;

    MOFIDInfo(Storage storage) {       
        this.storage = (BtreeStorage) storage;        
    }
        
    public String typeName() {
        return "MOFID";
    }

    /**
     * Compares two MOFIDs byte-by-byte.
     *
     * @param key	byte array containing search key
     * @param buffer	buffer containing target key
     * @param offset	offset into buffer of target key
     * @param length	should always be MOFID.LENGTH
     *
     * @return	Returns one of:
     * 

EQUAL if the two keys are equal *

GREATER if search key is greater than target key *

LESS if search key is less than target key */ public byte compare(byte[] key, byte[] buffer, int offset, int targetLength) { for (int i = 0; i < MOFID.LENGTH; i++) { if (key[i] < buffer[offset+i]) { return LESS; } else if (key[i] > buffer[offset+i]) { return GREATER; } } return EQUAL; } public int getLength() { return MOFID.LENGTH; } public boolean isFixedLength() { return true; } public byte[] toBuffer(Object object) { try { MOFID m = (MOFID) object; if (m != null) { byte[] mofBytes = new byte[MOFID.LENGTH]; Converter.writeLong(mofBytes, 0, m.getSerialNumber()); String storageId = m.getStorageID (); int s; if (storage.getStorageId ().equals(storageId)) { s = BtreeFactory.SAME_PREFIX_CODE; } else if (BtreeFactory.INTERNAL_PREFIX.equals (storageId)) { s = BtreeFactory.INTERNAL_PREFIX_CODE; } else { s = storage.storageIdToNumber (storageId); } Converter.writeShort(mofBytes, 0, (short)s); return mofBytes; } } catch (Exception e) { Logger.getDefault().notify(Logger.INFORMATIONAL, e); } return null; } public Object fromBuffer(byte[] buffer) { try { int storageNumber = Converter.readShort (buffer, 0); String storageId = null; switch (storageNumber) { case BtreeFactory.INTERNAL_PREFIX_CODE: storageId = BtreeFactory.INTERNAL_PREFIX; break; case BtreeFactory.SAME_PREFIX_CODE: storageId = storage.getStorageId (); break; default: storageId = storage.numberToStorageId (storageNumber); } buffer [0] = 0; buffer [1] = 0; long serialNumber = Converter.readLong (buffer, 0); return new MOFID (serialNumber, storageId); } catch (Exception e) { Logger.getDefault().notify(Logger.INFORMATIONAL, e); return null; } } public Object objectFromBuffer(byte[] buffer, SinglevaluedIndex repos) { try { return storage.resolveObject((MOFID) fromBuffer(buffer)); } catch (Exception e) { Logger.getDefault().notify(Logger.INFORMATIONAL, e); } return null; } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.