Package hu.u_szeged.nbo.geometria.element

Source Code of hu.u_szeged.nbo.geometria.element.GeomPlace

/*
* 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.type.GeomIntVektor;

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 GeomPlace implements /*Comparator,*/ Comparable {
  static GeomPlace[] places;
 
//  private int ID;  //mindig 1-tol kezdodik
  private int id;
  private String name;

  private static GeomIntVektor placeIndexes;
 
//  private static int count = 0;
 
  public GeomPlace(int id, String name){
//    ID = ++count;
    this.id = id;
    this.name = name;
  }
 
//  public int getID() {
//    return ID;
//  }

  public int getId() {
    return id;
  }

  public String getName(){
    return name;
  }
 
  public String toString(){
    return /*getID() + "-" +*/ getName();
  }

  public static TreeMap beolvas(String fileName) throws GeomWrongFileTypeException, IOException, GeomWrongIndexException {
    TreeMap map = new TreeMap();
    placeIndexes = new GeomIntVektor();
    int sor = 1;
    try{
      BufferedReader buf = new BufferedReader(new FileReader(fileName));
      int id;
      String nev;
      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());
        nev = st.nextToken();
        if(map.put(new Integer(id), new GeomPlace(id, nev))!=null){
          throw new GeomWrongIndexException(GeomWrongIndexException.INDEX_DUPLICATE_EXCEPTION, fileName, sor, id);
        }
        placeIndexes.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("Helyek:");
    for(int i=0; i<places.length; i++){
      System.out.println(places[i].toString());
    }
    System.out.println();
  }

/*  public int compare(Object arg0, Object arg1) {
    return ((GeomPlace)arg0).getId() - ((GeomPlace)arg1).getId();
  }
*/
 
  public int compareTo(Object arg0) {
    return this.getId() - ((GeomPlace)arg0).getId();
  }

  /**
   * @return
   */
  public static GeomIntVektor getPlaceIndexes() {
    return placeIndexes;
  }
}
TOP

Related Classes of hu.u_szeged.nbo.geometria.element.GeomPlace

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.