/*
 *  Copyright 2015 Brno University of Technology 
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */
package cz.vutbr.feec.graph;

import java.io.Serializable;
import java.util.Vector;

import cz.vutbr.feec.project.GlobalParameters;

public class Router implements Serializable {
	
	private String data;
	private int xInField;
	private int yInField;
	private Vector<Router> neighbors = new Vector<Router>();
	private Vector<Integer> costs = new Vector<Integer>();

	public Router(int x, int y) {
		xInField = x;
		yInField = y;
		data = x + "," + y;
	}

	public Router() {
		// TODO Auto-generated constructor stub
	}

	public int getxInField() {
		return xInField;
	}

	public void setxInField(int xInField) {
		this.xInField = xInField;
	}

	public int getyInField() {
		return yInField;
	}

	public void setyInField(int yInField) {
		this.yInField = yInField;
	}

	public int getCost(Router u) {
		// zjisti jeho index v seznamu
		int index = neighbors.indexOf(u);
		if (index == -1) {
			return GlobalParameters.INFINITY;
		} else {
			// vrati cenu pro dany uzel
			return costs.get(index);
		}
	}

	public void setCost(Router u, int cost) {
		// zjisti jeho index v seznamu
		int index = neighbors.indexOf(u);
		
		if (index == -1) {
			System.out.println("index routra NOK");
			return;
		} else {
			// nastav cenu na dany index
			System.out.println("Nastavujem cost");
			costs.set(index, cost);
		}

	}

	public String getData() {
		return data;
	}

	public int getNumberOfNeighbors() {
		return neighbors.size();
	}

	public Router getNeighbor(int index) {
		return neighbors.get(index);
	}

	public Vector<Router> getNeighbors() {
		return neighbors;
	}

	public void addNeighbor(Router neighbor, int cost) {
		neighbors.add(neighbor);
		costs.add(cost);
	}

	public void setData(String r) {
		this.data = r;
	}

	@Override
	public String toString() {
		return "Router," + data + ",";
	}
}
