/*
 * Copyright (C) 1999-2006 <a href="mailto:paschke@in.tum.de">Adrian Paschke</a>
 * 
 * The OWL2Prova library is part of the Rule Based Service Level Agreement (RBSLA)
 * framework, available at 
 * <a href=" http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA</a>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package rbsla.owl.converter.dlp;

import java.util.*;
/**
 * List of MapperElements
 * @version 0.1 <1 Feb 2005>
 * @since 0.1
 */
public class MapperList {

	private LinkedList MapList;
	
	/**
	 * Constructor
	 */
	
	public MapperList () {
			MapList = new LinkedList();
	}
	
	/**
	 * Add a MapperElement to the MapList
	 * @param mElement the MapperElement
	 */
	
	public void add(MapperElement mElement){
		MapList.add(mElement);
	}
	
	/**
	 * Demands a special element at index i
	 * @param i index of demand Element
	 * @return MapperElement
	 */
	
	public MapperElement getAtIndex (int i){
		return (MapperElement) MapList.get(i);
	}
	
	/**
	 * Removes an element at index i
	 * @param i the index
	 */
	
	public void removeAtIndex(int i){
		MapList.remove(i);
	}
	
	/**
	 * Returns if a special element is member of the mapping
	 * @param element the String element
	 * @return boolean
	 */
	
	public boolean isElementOfMapping (String element){
		boolean result = false;
		for (int i = 0; i < this.size(); i++){
			result = result || this.getAtIndex(i).getIndiList().isElementOfList(element);
		}
		return result;
	}
	
	/**
	 * Returns the highest Hasch Code
	 * @param indi the String element
	 * @return int the highest Hash Code
	 */
	
	public int getGreatestHashCode(){
		int gHC = 0;
		for (int i = 0; i < this.size(); i++){
			if (this.getAtIndex(i).getHash() > gHC){
				gHC = this.getAtIndex(i).getHash();
			}
		}
		return gHC;
	}
	
	/**
	 * Queries the Hash Code of a special element
	 * @param element the String element
	 * @return int the Hash Code
	 */
	
	public int getHashOfElement (String element){
		for (int i = 0; i < this.size(); i++){
			if (this.getAtIndex(i).getIndiList().isElementOfList(element)){
				return this.getAtIndex(i).getHash();
			}
		}
		return 0;
	}
	
	public int size(){
		return MapList.size();
	}
	
	public void printList(){
		for (int i = 0; i < this.size(); i++){
			System.out.print(this.getAtIndex(i).getHash() + " := ");
			this.getAtIndex(i).getIndiList().listToString();
			System.out.println("----------------------------");
		}
		
	}
	
}
