//------------------------------------------------------
// Datenstruktur: ArrayList
//------------------------------------------------------

function ArrayList(){

  this.index = new Array();
  this.value = new Array();
  
  // Gibt den Index zum key zurück
  ArrayList.prototype.getIndex = function(key){
    var i = 0;
    var valueFound = false;
    while(i < this.index.length){
      if(this.index[i] == key){
        valueFound = true;
        break;
      }
      i++;
    }
    if(valueFound)
      return i;
    return -1;
  }
  
  // Gibt alle Keys zurück
  ArrayList.prototype.getKeys = function(){
    return this.index;
  }

  // Gibt die Anzahl der Daten zurück
  ArrayList.prototype.length = function(){
    return this.index.length;
  }

  // Prüft ob key enthalten
  ArrayList.prototype.contains = function(key){
    var keyIndex = this.getIndex(key);
    if(keyIndex >= 0)
      return true;
    return false;
  }

  // Gibt Wert mit dem key zurück
  ArrayList.prototype.get = function(key){
    var keyIndex = this.getIndex(key);
    if(keyIndex >= 0)
      return this.value[keyIndex];
  }
  
  // Entfernt Wert mit dem key
  ArrayList.prototype.sub = function(key){
    var keyIndex = this.getIndex(key);
    if(keyIndex >= 0){
      this.index.del(keyIndex);
      this.value.del(keyIndex);
      return true;
    }
    return false;
  }

  // Fügt obj mit dem key hinzu
  ArrayList.prototype.add = function(key, obj){
    var keyIndex = this.getIndex(key);
    if(keyIndex >= 0){
      this.index[keyIndex] = key;
      this.value[keyIndex] = obj;
      return true;
    } else {
      this.index[this.index.length] = key;
      this.value[this.value.length] = obj;
      return true;
    }
    return false;
  }
  
  // Löscht alle Elemente
  ArrayList.prototype.clear = function(){
    this.index = new Array();
    this.value = new Array();
  }

} 
