/*
* Created on Dec 16, 2003
*/
package hu.u_szeged.nbo.geometria.element;
import hu.u_szeged.nbo.geometria.exception.GeomFileNotFoundException;
import hu.u_szeged.nbo.geometria.exception.GeomWrongFileTypeException;
import hu.u_szeged.nbo.geometria.exception.GeomWrongIndexException;
import hu.u_szeged.nbo.geometria.main.GeomLogger;
import hu.u_szeged.nbo.geometria.main.GeomResources;
import hu.u_szeged.nbo.geometria.type.GeomHalmaz;
import hu.u_szeged.nbo.geometria.type.GeomIntVektor;
import hu.u_szeged.nbo.geometria.type.GeomNumPair;
import hu.u_szeged.nbo.geometria.type.GeomPack;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TreeMap;
/**
* @author Sindely D�niel
*/
public class GeomTeam {
private static GeomTeam[] teams;
private static int lezartEroforrasokSzama = 0;
// private static int count = 0;
// private int ID;
private int id;
private int type;
private int idoablakEredetiKezdete = 0;
private int idoablakElozoKezdete = 0;
private GeomNumPair idoablak;
private GeomPlace basicPlace;
private GeomPlace previousPlace = null;
private GeomPlace actualPlace;
private boolean foglalt = false;
private boolean fiktiv = false;
private GeomHalmaz hozzarendeltMunkak = new GeomHalmaz();
private static GeomIntVektor teamIndexes;
private static GeomIntVektor teamTypeIndexes;
private GeomLogger logger = GeomLogger.getInstance();
public GeomTeam() {
fiktiv = true;
}
public GeomTeam(int id, int type, int idoablakKezdete, int idoablakVege, GeomPlace basicPlace) {
// ID = ++count;
this.id = id;
this.type = type;
this.idoablakEredetiKezdete = idoablakKezdete;
this.idoablak = new GeomNumPair(idoablakKezdete, idoablakVege);
this.basicPlace = basicPlace;
this.actualPlace = basicPlace;
}
public GeomPlace getBasicPlace() {
return basicPlace;
}
public GeomPlace getActualPlace() {
return actualPlace;
}
public void setActualPlace(GeomPlace actualPlace) {
this.actualPlace = actualPlace;
}
public boolean isFoglalt() {
return foglalt;
}
public void setFoglalt(boolean foglalt) {
this.foglalt = foglalt;
}
// public int getID() {
// return ID;
// }
public int getId() {
return id;
}
public int getType() {
return type;
}
public GeomNumPair getIdoablak(){
return idoablak;
}
public void setIdoablakKezdete(int idoablakKezdete) {
idoablak.setX(idoablakKezdete);
}
public int getIdoablakElozoKezdete() {
return idoablakElozoKezdete;
}
/* public String toString() {
return "e" + getId() + " type:" + getType() + " [" + idoablakKezdete + "-"+ idoablak.getY() + "] base:" + basicPlace;
}
*/
public String toString() {
if(!fiktiv){
return "e" + getId();
}else{
return "fiktiv eroforras";
}
}
public static TreeMap beolvas(String fileName) throws GeomWrongFileTypeException, IOException, GeomWrongIndexException {
TreeMap map = new TreeMap();
teamIndexes = new GeomIntVektor();
int sor = 1;
try {
BufferedReader buf = new BufferedReader(new FileReader(fileName));
int id, type, begin, end, base;
StringTokenizer st;
buf.readLine(); //a fejl�c miatt
while(buf.ready()){
sor++;
String s = buf.readLine();
st = new StringTokenizer(s);
id = Integer.parseInt(st.nextToken());
type = Integer.parseInt(st.nextToken());
if(!GeomResources.getInstance().getTeamTypeIndexes().isEleme(type)){
throw new GeomWrongIndexException(GeomWrongIndexException.NO_SPECIFIED_TYPE_INDEX_EXCEPTION, fileName, sor, type);
}
base = Integer.parseInt(st.nextToken());
begin = Integer.parseInt(st.nextToken());
end = Integer.parseInt(st.nextToken());
if(begin<0){
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.NEGATIVE_NUMBER_EXCEPTION, fileName, sor, "idoablak kezdete");
}
if(end<0){
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.NEGATIVE_NUMBER_EXCEPTION, fileName, sor, "idoablak vege");
}
if(begin >= end){
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.INVALID_INTERVAL_EXCEPTION, fileName, sor);
}
if(GeomResources.getInstance().getNagyT() < end){
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.TIME_GREATER_THAN_NAGYT_EXCEPTION, fileName, sor);
}
GeomPlace place;
try{
place = GeomResources.getInstance().getPlaceById(base);
} catch (GeomWrongIndexException e) {
throw new GeomWrongIndexException(GeomWrongIndexException.NO_SPECIFIED_PLACE_INDEX_EXCEPTION, fileName, sor, base);
}
if(map.put(new Integer(id), new GeomTeam(id, type, begin, end, place))!=null){
throw new GeomWrongIndexException(GeomWrongIndexException.INDEX_DUPLICATE_EXCEPTION, fileName, sor, id);
}
teamIndexes.addElement(id);
if(st.hasMoreTokens()){
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.MUCH_TOKEN_EXCEPTION, fileName, sor);
}
}
return map;
} catch (FileNotFoundException e){
throw new GeomFileNotFoundException(fileName);
} catch (NoSuchElementException e){
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.FEW_TOKEN_EXCEPTION, fileName, sor);
} catch (NumberFormatException e) {
throw new GeomWrongFileTypeException(GeomWrongFileTypeException.NUM_CONVERT_EXCEPTION, fileName, sor);
}
}
public static void listaz() {
System.out.println("Er�forr�sok:");
for(int i=0; i<teams.length; i++){
System.out.println(teams[i].toString());
}
System.out.println();
}
public boolean isFiktiv() {
return fiktiv;
}
public void lezar(){
lezartEroforrasokSzama++;
if(logger.isTeamFinishEnabled()){
System.out.println("/ "+lezartEroforrasokSzama+". lezart eroforras: "+this);
}
}
public void addHozzarendeltMunka(GeomWork work, int begin, int end){
hozzarendeltMunkak.gmBeszur(new GeomPack(work, this, begin, end));
}
public void setIdoablakElozoKezdete(int idoablakElozoKezdete) {
this.idoablakElozoKezdete = idoablakElozoKezdete;
}
public GeomPlace getPreviousPlace() {
return previousPlace;
}
public void setPreviousPlace(GeomPlace previousPlace) {
this.previousPlace = previousPlace;
}
public GeomHalmaz getHozzarendeltMunkak() {
return hozzarendeltMunkak;
}
/**
* @return
*/
public static GeomIntVektor getTeamIndexes() {
return teamIndexes;
}
/**
* @return
*/
public static GeomIntVektor getTeamTypeIndexes() {
return teamTypeIndexes;
}
/**
* @return Returns the idoablakEredetiKezdete.
*/
public int getIdoablakEredetiKezdete() {
return idoablakEredetiKezdete;
}
}