/*=========================================================================

  Program:   Orbit Visualization Tool
  Source:    $Source: /stor/devel/ovt2g/ovt/datatype/Children.java,v $
  Date:      $Date: 2001/03/29 19:23:10 $
  Version:   $Revision: 1.10 $


Copyright (c) 2000 OVT Team (Kristof Stasiewicz, Mykola Khotyaintsev, 
Yuri Khotyaintsev)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification is permitted provided that the following conditions are met:

 * No part of the software can be included in any commercial package without
written consent from the OVT team.

 * Redistributions of the source or binary code must retain the above
copyright notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT OR
INDIRECT DAMAGES  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.

OVT Team (http://ovt.irfu.se)   K. Stasiewicz, M. Khotyaintsev, Y.
Khotyaintsev

=========================================================================*/

/*
 * Children.java
 *
 * Created on March 14, 2000, 3:28 PM
 */
 
package ovt.datatype;

import ovt.util.*;
import ovt.object.*;
import ovt.interfaces.*;

import java.util.*;

/** 
 *
 * @author  root
 * @version 
 */
public class Children {

  protected Vector keys;
  protected Vector values;

  /** Creates new Children */
  public Children() {
    keys   = new Vector();
    values = new Vector();
  }
  
  /*public void put(NamedObject obj) {
    put(obj.getName(), obj);
  }*/
  public void put(OVTObject obj) {
    put(obj.getName(), obj);
  }  

  protected void put(String key, OVTObject obj) {
    keys.addElement(key);
    values.addElement(obj); 
  }

  public void remove(String key) {
    Object obj = get(key);
    if (obj != null) {
      keys.removeElement(key);
      values.removeElement(obj);
    }
  }

  
  public OVTObject get(String name) { 
    Log.log("Children ::  get(" + name + ")", 7);
    int index = keys.indexOf(name);
    //System.out.println("index=" + index);
    if (index == -1) return null;
    return (OVTObject)values.elementAt(index); 
  }

  
  public Enumeration elements() {
    return values.elements();
  }
  
  public OVTObject getLastChild() {	// added by oleg
    return (OVTObject) values.lastElement();
  }

  /*public static Children add(Children ch1, Children ch2) {
    Enumeration e = ch2.elements();
    NamedObject obj;
    while (e.hasMoreElements()) {
      obj = (NamedObject)e.nextElement();
      ch1.put(obj);
    }
    retur
  }*/

  public void clear() {
    keys.removeAllElements();
    values.removeAllElements();
  }
  
  public int size() {
    return values.size();
  }
  
}