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

📄 dxmultimap.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: DxMultiMap.java,v 1.8 2000/10/28 16:55:14 daniela Exp $package org.ozoneDB.DxLib;import java.io.*;/** *  *  * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.8 $Date: 2000/10/28 16:55:14 $ */public class DxMultiMap extends DxAbstractCollection implements DxMap, Externalizable {        final static long serialVersionUID = 1L;        protected transient DxMap map;    protected transient DxCollection containerFactory;    protected transient int multiItemCount = 0;            public DxMultiMap() {        map = new DxHashMap();        containerFactory = new DxArrayBag( 8 );    }            public DxMultiMap( DxMap _map, DxCollection _containerFactory ) {        map = _map;        containerFactory = _containerFactory;    }            public Object clone() {        try {            DxMultiMap answer = (DxMultiMap)getClass().newInstance();            answer.map = (DxMap)map.getClass().newInstance();            answer.containerFactory = (DxCollection)containerFactory.getClass().newInstance();                        DxIterator it = iterator();            Object obj;            while ((obj = it.next()) != null) {                DxCollection newColl = (DxCollection)((DxCollection)obj).clone();                answer.addForKey( newColl, it.key() );            }             return answer;        } catch (Exception e) {            throw new RuntimeException( e.toString() );        }     }             public DxCollection valueClone() {        throw new RuntimeException( getClass().getName() + ".valueClone() not implemented." );    }             /**     * Compares two multimaps for equality.     */    public boolean equals( Object obj ) {        if (obj instanceof DxMultiMap && obj != null) {            DxMultiMap rhs = (DxMultiMap)obj;                        if (this == obj) {                return true;            }                         //FIXME: alle keys muessen mit gleichen containern da sein            return false;        } else {            return false;        }     }             public DxSet keySet() {        return map.keySet();    }             public DxSet elementSet() {        DxSet answer = new DxHashSet();        answer.add( this );        return answer;    }             public synchronized boolean add( Object obj ) {        return addForKey( obj, buildKey( obj ) );    }             public Object buildKey( Object obj ) {        return obj;    }             public synchronized boolean addForKey( Object obj, Object key ) {        try {            DxCollection coll = (DxCollection)map.elementForKey( key );            if (coll == null) {                coll = (DxCollection)containerFactory.getClass().newInstance();                map.addForKey( coll, key );            }             coll.add( obj );            multiItemCount++;            return true;        } catch (Exception e) {            throw new RuntimeException( e.toString() );        }     }             public DxCollection elementsForKey( Object key ) {        return (DxCollection)map.elementForKey( key );    }             public Object elementForKey( Object key ) {        return map.elementForKey( key );    }             public Object keyForElement( Object obj ) {        DxIterator it = iterator();        while (it.next() != null) {            DxIterator iit = iterator();            while (iit.next() != null) {                if (obj.equals( iit.object() )) {                    return iit.key();                }             }         }         return null;    }             public synchronized Object removeForKey( Object key ) {        DxCollection answer = (DxCollection)map.removeForKey( key );        if (answer != null) {            multiItemCount--;        }         return answer;    }             public boolean removeAllKeys( DxCollection coll ) {        throw new RuntimeException( getClass().getName() + ".removeAllKeys() not implemented." );    }             public boolean containsKey( Object key ) {        return map.containsKey( key );    }             /** */    public DxIterator iterator() {        return new DxMultiIterator( this );    }             /** */    public int count() {        return multiItemCount;    }             /** */    public boolean isEmpty() {        return multiItemCount == 0;    }             public synchronized void clear() {        map.clear();        multiItemCount = 0;    }             public void writeExternal( ObjectOutput out ) throws IOException {        out.writeInt( count() );        DxIterator it = iterator();        Object obj;        while ((obj = it.next()) != null) {            out.writeObject( obj );            out.writeObject( it.key() );        }     }             public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {        int count = in.readInt();        for (; count > 0; count--) {            addForKey( in.readObject(), in.readObject() );        }     }     }

⌨️ 快捷键说明

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