import java.io.*; import java.util.Vector; public class TagsCollection implements CollectionIF { private String dbname; private Vector vTags; public TagsCollection( String filename ) { dbname = filename; vTags = new Vector(); } public int getNextID() { if ( vTags.isEmpty() ) return 1; int nextid = ((Tags) (vTags.lastElement())).getID() + 1; System.out.println("nextid = " + nextid); return nextid; } public void addRecord( Vector v ) { Tags Tag = new Tags(); Tag.setID( (Integer.parseInt( (String)v.elementAt(0)))); vTags.addElement( Tag ); } public void loadRecords() { DataInputStream infile_Tag = null; Tags Tag; try { infile_Tag = new DataInputStream( new FileInputStream( dbname ) ); } catch ( FileNotFoundException e ) {} while ( true ) { Tag = new Tags(); try { Tag.retrieve( infile_Tag ); infile_Tag.readByte(); vTags.addElement( Tag ); } catch ( EOFException eof ) { System.out.println("We have hit end of file!"); break; } catch ( IOException e ){ } } } public void storeRecords() { DataOutputStream outfile_Tag = null; try { outfile_Tag = new DataOutputStream( new FileOutputStream( dbname ) ); } catch ( IOException e ) {} for ( int i = 0; i < vTags.size(); i++ ) { Tags Tag = (Tags) vTags.elementAt( i ); Tag.persist( outfile_Tag ); try { outfile_Tag.writeByte( (byte) '¬' ); } catch ( IOException e ) {} } } public void modifyRecord( Vector v ) { for ( int i = 0; i < vTags.size(); i++ ) if ( ( (Tags) vTags.elementAt( i )).equals( v ) ) { ( (Tags) vTags.elementAt( i ) ).update( v ); } } public void deleteRecord( int i ) { vTags.removeElementAt( i ); } public PersistentObject getRecord( int i ) { return (PersistentObject) vTags.elementAt( i ); } public PersistentObject getRecord( String tag ) { for ( int i = 0; i < vTags.size(); i++ ) { if ( ((Tags)(vTags.elementAt(i))).getTagText().equals( tag) ) return (Tags)(vTags.elementAt(i)); } return null; } public int size() { return vTags.size(); } }