/*
 * Created on Jan 29, 2005
 *
 * Advanced Data Management Group
 * Center for Advanced Computing and Informatics Studies
 * University of Puerto Rico, Mayaguez
 * 
 */
package ece.uprm.admg.cs2.p1;

import ece.uprm.admg.cs2.util.*;

/**
 * 	Class MapTester is used to test the functions of the DynamicMap class,
 *  @author Manuel Rodriguez
 *
 */

public class MapTester {

    public void start(){
        Map M1 = new DynamicMap();
        
        System.out.println("Adding part 001");
        Part P1 = new Part("001", "Bolt", "Silver", (float) 0.40, "Tin");
        M1.put(P1.getKey(), P1);
        System.out.println("Adding part 003");
        P1 = new Part("003", "Battery", "Black", (float) 50.0, "Lead");
        M1.put(P1.getKey(), P1);
        System.out.println("Adding part 004");
        P1 = new Part("004", "Muffler", "Grey", (float) 240.99, "Steel");
        M1.put(P1.getKey(), P1);
        Object[] values = M1.toArray();
        int len = values.length;
        for(int i=0; i < len; ++i){
            System.out.println(values[i].toString());
        }   
        
        if (M1.get("003") != null){
            System.out.println("Part with key 003 was found.");
        }
        else {
            System.out.println("Part with key 003 was not found.");         
        }
        
        System.out.println("M1.remove(\"002\"): " + M1.remove("002"));
        System.out.println("M1.remove(\"001\"): " + M1.remove("001"));
        values = M1.toArray();
        len = values.length;
        for(int i=0; i < len; ++i){
            System.out.println(values[i].toString());
        }   
          
        System.out.println("M1.size(): " + M1.size());
        System.out.println("M1.containsKey(\"001\"): " + M1.containsKey("001"));
        System.out.println("M1.containsKey(\"004\"): " + M1.containsKey("004"));
        System.out.println("Getting part with key 004:");
        P1 = (Part) M1.get("004");
        if (P1 == null){
            System.out.println("Part with key 004 was not found.");
        }
        else {
            System.out.println("Part with key 004 is: " + P1.toString());
        }    
        System.out.println("Making the M1 empty.");
        M1.makeEmpty();
        if (M1.isEmpty()){
            System.out.println("M1 is an empty Map.");
        }
        else {
            System.out.println("M1 is not an empty Map.");
        }
        
        System.out.println("Done!");
    }
    
    public static void main(String[] args) {
        MapTester tester = new MapTester();
        try {
            tester.start();
        }
        catch(Exception e){
            e.printStackTrace();
        }
            
    }
}
