// File: JavaExamples/Lists/PROFLIST.java
 
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;

public class PROFLIST extends DList {
// note: DList is Object Space's list<Object>

// note: as the code for hire/fire is generic, you can use other containers:
//       Array, Deque, OrderedSet

public int fire(String badprof)
{// remove element from sorted list;
 // return 0 if removal was successful;

   DListIterator p = (DListIterator)Finding.findIf(
                       begin(),
                       end(),
                       new PROF.comp_w_lastname(badprof)
                     );
 
   if ( p.equals( end() ) ) return 1; // not found
   if ( ! ((PROF)p.get()).lname.equals( badprof ) ) return 1; // not found
 
   remove(p);
   return 0;
} // end fire

public int hire( PROF goodprof)
{// insert goodprof in alphabetic order;
 // returns 0 if successful, 1 if goodprof already there,
 //  -1 if no more memory

   boolean found;

   // uses findIf because there is no lowerBound on DList in JGL :-(
   DListIterator p = (DListIterator)Finding.findIf(
                       begin(),
                       end(),
                       new PROF.comp_w_lastname(goodprof.lname)
                     );
 
   if ( p.equals( end() ) ) found = false; // not found
   else {if ( ((PROF)p.get()).equals( goodprof ) ) found = true;
         else found = false;
        }

   if(found) return 1; // already there

   if( size() == maxSize() ) return -1; // out of memory
   // max_size is how large the list can get at most

   insert(p, goodprof);

   return 0;
} // end hire

} // end class PROFLIST
