/**
	* Vertices Class describe vertices in graph
	* this class describe edges and function to handle vertex easily
	**/
	
// this Class is a memeber of GCRawData package
package GCRawData;

import java.util.*;
import java.awt.*;

public class Vertices
{
	private LinkedList Ver, Col;
	private int index = 0;
		
	// constructor
	public Vertices() {
		Ver = new LinkedList();
		Col = new LinkedList();
	}
  
	// create Vertices class by coping argVer Vertices
  public Vertices(Vertices argVer) {
		this.Ver = (LinkedList)argVer.Ver.clone();
    this.Col = (LinkedList)argVer.Col.clone();
  }
  
  // add vertex to list
	public String add(String val) {
		Ver.add(val);
		Col.add("GC_NULL");
                
                return val;
	}
	
	// set vertex color
	public boolean setColor(String val, Color col) {
		index = Ver.indexOf(val);
		if (index == -1) return false;
		Col.add(index, col.getRed()+"."+col.getGreen()+"."+col.getBlue());
			
		return true;
	}
  
	// get start vertex 
  public String getStartVertex() {
  	setStart();
                
    return getNextVertex();
  }
  
  // get vertex from index
  public String getNextVertex() {
    System.out.println("[Debug] Vertices.getNextVertex().index: "+index);
    try {
    	String tmp = new String( (String)Ver.get(index) );
      index++;
      return tmp;
    } catch (Exception e) {
    	return "GC_NULL";
    }
  }
  
	// get vertex which has the color
	public String getVertexFromColor(Color col) {
		index = Col.indexOf( col.getRed()+"."+col.getGreen()+"."+col.getBlue() );
		if (index == -1) return "GC_NULL";
		//System.out.println("[debug]Vertices.getVertex(): "+index);
		
		return new String ((String)Ver.get(index));
	}
	
  // get end vertex
	public String getEndVertex() {
    return new String ((String)Ver.get(size()-1));
  }
  
	// get next vertex which has the color
	public String getVertexFromColorNext(Color col) {
		ListIterator lt = Col.listIterator(index);
    String tester = new String( col.getRed()+"."+col.getGreen()+"."+col.getBlue() );
		try {
			lt.next();	//start from end of list
			while(true)	{
				if ( tester.equals((String)lt.next()) ) return new String ((String)Ver.get(++index));	
				index++;
			}
		} catch (NoSuchElementException e)
		{
			return "GC_NULL";
		}
	}
	
	// set index = 0
	public void setStart() {
		index = 0;
	}
	
	// set color to next vertex 
	public boolean setNextColor(Color col) {
		if (index == Ver.size()) return false;
		
		Col.remove(index);
		Col.add(index, col.getRed()+"."+col.getGreen()+"."+col.getBlue());
		
		index++;
		return true;
	}
	
	// get size of vertices
	public int size() {
		return Ver.size();
	}
	
	// get size of colors
	public int getColorSize() {
		Vector temp = new Vector();
		for (int i=0; i<Col.size(); i++) 
			if ( !((String)Col.get(i)).equals("GC_NULL") && !temp.contains(Col.get(i))) {
    		temp.add(Col.get(i));
        System.out.println("[Debug] Vertices.colorSize():  "+Col.get(i));
      }
      
		return temp.size();
	}
	// get Color which return the Color of val(Vertex)
	public Color getColor(String val) {
		int ind = Ver.indexOf(val);
		if (ind == -1) return null;
		
		StringTokenizer st = new StringTokenizer( (String)Col.get(ind), "." );
                
    return new Color( Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()) ); 
	}
	
	// is there some Vertex in Graph?
	public boolean containsVer(String val) {
		return Ver.contains(val);
	}
	
	// etc func -priveta: user never call
	private boolean containsColor(String col) {
		return Col.contains(col);
	}
		
		
}