📄 dxabstractcollection.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-@year@ by SMB GmbH. All rights reserved.//// $Id: DxAbstractCollection.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $package org.ozoneDB.DxLib;import org.ozoneDB.io.stream.ResolvingObjectInputStream;import java.io.*;/** * Common super class of all collection classes. */public abstract class DxAbstractCollection extends DxObject implements DxCollection, Externalizable { final static long serialVersionUID = 2L; public DxAbstractCollection() { } /** * Construct the collection out of an array of objects. */ // public DxAbstractCollection (Object[] objs) { // for (int i=0; i<objs.length; i++) // add (objs[i]); // } public Object clone( DxCollection newInstance ) { try { DxIterator it = iterator(); Object obj; while ((obj = it.next()) != null) { newInstance.add( obj ); } return newInstance; } catch (Exception e) { throw new RuntimeException( e.toString() ); } } /** * erzeugt einen clone der collection und der objekte; * Achtung: alle objekte in der collection muessen DxCompatible sein */ public DxCollection valueClone() { try { DxCollection coll = (DxCollection)getClass().newInstance(); DxIterator it = iterator(); while (it.next() != null) { Object obj = it.object(); if (obj instanceof DxCompatible) { coll.add( ((DxCompatible)obj).clone() ); } else if (obj instanceof Serializable) { ByteArrayOutputStream bout = new ByteArrayOutputStream( 4096 ); ObjectOutputStream out = new ObjectOutputStream( bout ); out.writeObject( obj ); out.close(); ObjectInputStream in = new ResolvingObjectInputStream( new ByteArrayInputStream( bout.toByteArray() ) ); coll.add( in.readObject() ); } else { throw new CloneNotSupportedException(); } } return coll; } catch (Exception e) { throw new RuntimeException( e.toString() ); } } public Object[] toArray() { Object[] result = new Object[count()]; DxIterator it = iterator(); Object obj; for (int i = 0; (obj = it.next()) != null; i++) { result[i] = obj; } return result; } /** * Compares two collections for equality. * You have to override this method in the implementation of an actual * collections in order to provide another behaviour than the one implemented in * Objects.equals(). */ public boolean equals( Object obj ) { return super.equals( obj ); // if (obj instanceof DxCollection && obj != null) { // // if (this == obj) // return true; // // boolean answer = true; // DxIterator it = iterator(); // while (it.next() != null) { // if (!((DxCollection)obj).contains (it.object())) { // answer = false; // break; // } // } // if (answer) { // it = ((DxCollection)obj).iterator(); // while (it.next() != null) { // if (!contains (it.object())) { // answer = false; // break; // } // } // } // return answer; // } // else // return false; } public synchronized boolean addAll( DxCollection coll ) { boolean answer = false; DxIterator it = coll.iterator(); Object obj; while ((obj = it.next()) != null) { if (add( obj )) { answer = true; } } return answer; } public synchronized boolean addAll( Object[] objs ) { boolean answer = false; for (int i = 0; i < objs.length; i++) { if (add( objs[i] )) { answer = true; } } return answer; } /** * Remove the first occurence of an object that equals the the * specified object. */ public synchronized boolean remove( Object obj ) { boolean answer = false; DxIterator it = iterator(); Object cursor; while ((cursor = it.next()) != null) { if (obj.equals( cursor )) { it.removeObject(); answer = true; } } return answer; } public synchronized boolean removeAll( DxCollection coll ) { boolean answer = false; if (!coll.isEmpty() && !isEmpty()) { DxIterator it = coll.iterator(); Object obj; while ((obj = it.next()) != null) { if (remove( obj )) { answer = true; } } } return answer; } /** * Returns true is this collection contains an object that equals * to the specified object. */ public boolean contains( Object obj ) { DxIterator it = iterator(); Object cursor; while ((cursor = it.next()) != null) { if (obj.equals( cursor )) { return true; } } return false; } public boolean containsAll( DxCollection coll ) { DxIterator it = coll.iterator(); Object cursor; while ((cursor = it.next()) != null) { if (!contains( cursor )) { return false; } } return true; } 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 ); } } public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { int count = in.readInt(); for (; count > 0; count--) { add( in.readObject() ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -