Exemple #1
0
 public boolean containsKey(Bauernhof b) {
   BauernhofIterator it = new BauernhofIterator(this.keys);
   Bauernhof elem = null;
   while (it.hasNext()) {
     elem = it.getNext();
     if (elem.getName().equals(b.getName())) return true;
   }
   return false;
   // returns whether specific key is in map or not
 }
Exemple #2
0
 public String toString() {
   StringBuffer buf = new StringBuffer();
   BauernhofIterator it = new BauernhofIterator(this.keys);
   Bauernhof b = null;
   buf.append("Map enthaelt: \n");
   while (it.hasNext()) {
     b = it.getNext();
     buf.append("KEY: " + b.getName());
     buf.append('\n');
     buf.append("VALUES:\n" + b.getTraktorList().toString());
     buf.append('\n');
   }
   return buf.toString();
 }
Exemple #3
0
 public void putTraktorList(Bauernhof b, TraktorList t_list) {
   if (!containsKey(b)) {
     this.keys.append(b);
   }
   b.addTraktorList(t_list);
   // new entry consinsting of a farm b and its corresponding tractorlist t_list has been inserted
 }
Exemple #4
0
 public Bauernhof getKey(Traktor t) {
   BauernhofIterator it = new BauernhofIterator(this.keys);
   Bauernhof b = null;
   TraktorList list = null;
   Traktor elem = null;
   while (it.hasNext()) { // first iterate through farms
     b = it.getNext();
     list = b.getTraktorList();
     TraktorIterator traktoren = new TraktorIterator(list);
     while (traktoren.hasNext()) { // next iterate through corresponding lists of tractors
       elem = traktoren.getNext();
       if (elem.getID() == t.getID()) return b;
     }
   }
   return null;
   // returns: if tractor t is in map: corresponding farm b
   //         else: null
 }
Exemple #5
0
 public void removeTraktor(Traktor t) {
   Bauernhof b = getKey(t);
   if (b == null) return;
   b.remove(t);
   // tractor t has been removed(only if t previously was in map!!)
 }
Exemple #6
0
 public TraktorList getTraktorList(Bauernhof b) {
   if (!containsKey(b)) return null;
   return b.getTraktorList();
   // returns: if farm b is in map: corresponding tractor list
   //         else: null
 }