Back to slide -- Keyboard shortcut: 'u'  next        LiteratureCollection.java - Klassen LiteratureCollection.Lecture 8 - slide 9 : 26
Program 3

package microbib;

import oopcourse.util.*;
import COM.objectspace.jgl.*;
import java.util.Enumeration;
import java.io.*;

/** A set of literature */
public class LiteratureCollection implements Serializable{
  
  private Array store = new Array();

  /** Construct an empty collection of literature. */
  public LiteratureCollection () {
    }

  /** Insert the parameter into this collection of literature. */
  public void insert (Literature lit){
    store.add(lit);
  }

  /** Search for searchString in this collection of Literature,
      and return a new collection of matching literaure. */
  public LiteratureCollection search (String searchString){
    ArrayIterator it = store.begin();
    LiteratureCollection res = new LiteratureCollection();

    while (it.hasMoreElements()) {
      Literature currentLit = (Literature)it.nextElement();
      if (currentLit.match(searchString))
         res.insert(currentLit);
    };
    return(res);
  } // end search

  /** Return the number of literature entries in this collection */
  public int length () {
    return(store.size());
  }

  /** Delete all literature in this collection. */
  public void deleteCollection() {
    store.clear();
  }

  /** Return literature element number n from this
      literature Collection */
  public Literature element(int n){return((Literature)store.at(n));}


  /** Print this collection of literature via multiple activation
      of Literature's print */
  public void print(){
    ArrayIterator it = store.begin();
    while (it.hasMoreElements()) {
      Literature currentLit = (Literature)it.nextElement();
      currentLit.print();
    }      
  } // end print

}