// $Id: StructureComponentIterator.java,v 1.1 2006/05/20 17:02:06 Sasha Buzko Exp $ // // Copyright (c) 2000-2002 San Diego Supercomputer Center (SDSC), // a facility operated jointly by the University of California, // San Diego (UCSD) and General Atomics, San Diego, California, USA. // // Users and possessors of this source code are hereby granted a // nonexclusive, royalty-free copyright and design patent license to // use this code in individual software. License is not granted for // commercial resale, in whole or in part, without prior written // permission from SDSC. This source is provided "AS IS" without express // or implied warranty of any kind. // // For further information, please see: http://mbt.sdsc.edu // // History: // $Log: StructureComponentIterator.java,v $ // Revision 1.1 2006/05/20 17:02:06 Sasha Buzko // Updated version // // Revision 1.1 2006/04/30 20:14:05 Sasha Buzko // New version of the app // // Revision 1.1 2006/04/15 19:42:27 Sasha Buzko // Initial commit // // Revision 1.1 2005/11/13 04:35:24 Administrator // *** empty log message *** // // Revision 1.3 2003/04/23 17:39:36 moreland // Removed StructureComponentID/scid and replaced it with a "structure" field // in the StructureComponent base class. // Changed "getType" method to "getStructureComponentType" to return dynamic // SC type (ie: class name). // // Revision 1.2 2002/10/24 17:54:01 moreland // Provides implementation for the improved Structure API/implementation. // // Revision 1.1.1.1 2002/07/16 18:00:18 moreland // Imported sources // // Revision 1.0 2002/06/10 23:38:39 moreland // package edu.sdsc.mbt; // MBT import edu.sdsc.mbt.filters.*; // Core import java.util.NoSuchElementException; /** * Defines a standard interface to describe a filter implementation class. * A filter is repsonsible for implementing two methods which should return * values according to what subset of StructureComponent objects it will * accept or reject. The "type" method should return the * StructureComponentRegistry TYPE that it will process (this will also * automatically limit the type of StructureComponent objects passed to * its "accept" method). The "accept" method should return TRUE if the given * StructureComponent object should be accepted or FALSE if it should be * rejected. *
* For example, to define a filter which filters Atom components * which only accepts C-Alpha atoms, one could declare the following * class (in this example, its declared as an internal class): *
*
* StructureComponentFilter filter = new StructureComponentFilter( ) * { * public String type( ) * { * return StructureComponentRegistry.TYPE_ATOM; * } * * public boolean accept( StructureComponent sc ) * { * return ((Atom)sc).name.startsWith( "CA" ); * } * }; * StructureComponentIterator iterator = * structure.getStructureComponentIterator( filter ); **
* @see edu.sdsc.mbt.filters.StructureComponentFilter * @see edu.sdsc.mbt.Structure * @see edu.sdsc.mbt.StructureComponent *
* @author John L. Moreland */ public class StructureComponentIterator implements java.io.Serializable { private Structure structure; private StructureComponentFilter filter; private String type; private int count; private int index; private boolean foundNext; private StructureComponent tmpStructureComponent; /** * Construct a StructureComponentIterator for the given structure * using the given filter to describe the desired subset. *
*/ public StructureComponentIterator( Structure structure, StructureComponentFilter filter ) throws ClassNotFoundException, InstantiationException, IllegalAccessException { this.structure = structure; this.filter = filter; type = filter.type( ); count = structure.getStructureComponentCount( type ); index = 0; foundNext = false; } /** * Return true if the Iterator has more matches or false otherwise. *
*/
public boolean hasMore( )
{
if ( foundNext ) return true;
while ( index
*/
public void next( StructureComponent structureComponent )
throws NoSuchElementException
{
if ( type != structureComponent.getStructureComponentType() )
throw new NoSuchElementException( "StructureComponentIterator.next: type mismatch" );
if ( hasMore( ) )
{
structureComponent.copy( tmpStructureComponent );
index++;
foundNext = false;
return;
}
}
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
out.defaultWriteObject();
}
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
in.defaultReadObject();
}
}