📄 dxabstractmap.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: DxAbstractMap.java,v 1.9 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.9 $Date: 2000/10/28 16:55:14 $ */public abstract class DxAbstractMap extends DxAbstractCollection implements DxMap, Externalizable { final static long serialVersionUID = 1L; public Object clone( DxMap newMap ) { try { DxIterator it = iterator(); Object obj; while ((obj = it.next()) != null) { newMap.addForKey( obj, it.key() ); } return newMap; } catch (Exception e) { throw new RuntimeException( e.toString() ); } } public DxCollection valueClone() { throw new RuntimeException( getClass().getName() + ".valueClone() not implemented." ); } /** * Compares two maps for equality. Returns true if the keySets are * equal. */ public boolean equals( Object obj ) { if (obj != null && obj instanceof DxMap) { DxMap rhs = (DxMap)obj; if (this == obj) { return true; } // FIXME: direct call to DxSet.equlas() is "ambigous"... Object keySet = keySet(); return keySet.equals( rhs.keySet() ); } else { return false; } } public synchronized boolean add( Object obj ) { return addForKey( obj, buildKey( obj ) ); } public synchronized boolean addAll( DxCollection coll ) { if (coll instanceof DxMap) { boolean answer = false; DxIterator it = coll.iterator(); Object obj; while ((obj = it.next()) != null) { if (addForKey( obj, it.key() )) { answer = true; } } return answer; } else { return super.addAll( coll ); } } public synchronized boolean removeAllKeys( DxCollection coll ) { boolean answer = false; if (!coll.isEmpty() && !isEmpty()) { DxIterator it = coll.iterator(); Object key; while ((key = it.next()) != null) { if (removeForKey( key ) != null) { answer = true; } } } return answer; } /** * This method is not declared abstract because it does not need to * be implemented in any case. */ public Object buildKey( Object obj ) { return obj; // throw new RuntimeException ("buildKey(): subclass responsibility"); } public boolean containsKey( Object key ) { return elementForKey( key ) != null; } public DxSet keySet() { DxSet answer = new DxHashSet(); DxIterator it = iterator(); while (it.next() != null) { answer.add( it.key() ); } return answer; } public DxSet elementSet() { DxSet answer = new DxHashSet(); answer.addAll( this ); return answer; } public void writeExternal( ObjectOutput out ) throws IOException { // System.out.println (getClass().getName() + ".writeExternal()..."); 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 { // System.out.println ("abstract.readExternal()..."); int count = in.readInt(); for (; count > 0; count--) { addForKey( in.readObject(), in.readObject() ); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -