Package models

Source Code of models.Locations

package models;

import java.io.BufferedReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedList;

import models.coordinates.LocationCoordinates;
import controllers.Messages;

/**
* Class for handling the Stars as a collection
*
* @see StarStorage
* @author francois
*
*/
public class Locations {
  public static String separator = ",";
  public static Charset charset = Charset.forName("UTF-8");
 
  private static LinkedList<LocationCoordinates> locations = new LinkedList<>();

  /**
   * Importation du fichier dans la mémoire
   * @param filename
   */
  public static void initLocations(final Path filename) {
    // try with limit, assure la fermeture de l'input stream à la fin du try
    try (BufferedReader br = Files.newBufferedReader(filename, charset)) {
      String line;
      String[] subline;

      while ((line = br.readLine()) != null)
        if (line.charAt(0) != '#') {
          subline = line.split(separator);
          if (subline.length >=3 )
            locations.add(new LocationCoordinates(Double.parseDouble(subline[0]), Double.parseDouble(subline[1]), subline[2]));
        }
    } catch (Exception e) {
      Messages.addError("Error: " + e.getMessage());
      e.printStackTrace();
    }
  }

  /**
   *
   * @return the currently loaded set of Location
   */
  public static Iterable<LocationCoordinates> getLocations() {
    return locations;
  }
}
TOP

Related Classes of models.Locations

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.