當前位置: 首頁>>代碼示例>>Java>>正文


Java PApplet.loadStrings方法代碼示例

本文整理匯總了Java中processing.core.PApplet.loadStrings方法的典型用法代碼示例。如果您正苦於以下問題:Java PApplet.loadStrings方法的具體用法?Java PApplet.loadStrings怎麽用?Java PApplet.loadStrings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在processing.core.PApplet的用法示例。


在下文中一共展示了PApplet.loadStrings方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadLifeExpectancyFromCSV

import processing.core.PApplet; //導入方法依賴的package包/類
public static HashMap<String, Float> loadLifeExpectancyFromCSV(PApplet p, String fileName) {
	// HashMap key: country ID and  data: lifeExp at birth
	HashMap<String, Float> lifeExpMap = new HashMap<String, Float>();

	// get lines of csv file
	String[] rows = p.loadStrings(fileName);
	
	// Reads country name and population density value from CSV row
	for (String row : rows) {
		// split row by commas not in quotations
		String[] columns = row.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
		
		// check if there is any life expectancy data from any year, get most recent
		/*
		 * EXTENSION: Add code to also get the year the data is from.
		 * You may want to use a list of Floats as the  values for the HashMap
		 * and store the year as the second value. (There are many other ways to do this)
		 */
		//
		for(int i = columns.length - 1; i > 3; i--) {
			
			// check if value exists for year
			if(!columns[i].equals("..")) {
				lifeExpMap.put(columns[3], Float.parseFloat(columns[i]));
				
				// break once most recent data is found
				break;
			}
		}
		
	}

	return lifeExpMap;
}
 
開發者ID:simontangbit,項目名稱:CourseCode,代碼行數:35,代碼來源:ParseFeed.java

示例2: parseAirports

import processing.core.PApplet; //導入方法依賴的package包/類
public static List<PointFeature> parseAirports(PApplet p, String fileName) {
	List<PointFeature> features = new ArrayList<PointFeature>();

	String[] rows = p.loadStrings(fileName);
	for (String row : rows) {
		
		// hot-fix for altitude when lat lon out of place
		int i = 0;
		
		// split row by commas not in quotations
		String[] columns = row.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
		
		// get location and create feature
		//System.out.println(columns[6]);
		float lat = Float.parseFloat(columns[6]);
		float lon = Float.parseFloat(columns[7]);
		
		Location loc = new Location(lat, lon);
		PointFeature point = new PointFeature(loc);
		
		// set ID to OpenFlights unique identifier
		point.setId(columns[0]);
		
		// get other fields from csv
		point.addProperty("name", columns[1]);
		point.putProperty("city", columns[2]);
		point.putProperty("country", columns[3]);
		
		// pretty sure IATA/FAA is used in routes.dat
		// get airport IATA/FAA code
		if(!columns[4].equals("")) {
			point.putProperty("code", columns[4]);
		}
		// get airport ICAO code if no IATA
		else if(!columns[5].equals("")) {
			point.putProperty("code", columns[5]);
		}
		
		point.putProperty("altitude", columns[8 + i]);
		
		features.add(point);
	}

	return features;
	
}
 
開發者ID:simontangbit,項目名稱:CourseCode,代碼行數:47,代碼來源:ParseFeed.java

示例3: parseRoutes

import processing.core.PApplet; //導入方法依賴的package包/類
public static List<ShapeFeature> parseRoutes(PApplet p, String fileName) {
	List<ShapeFeature> routes = new ArrayList<ShapeFeature>();
	
	String[] rows = p.loadStrings(fileName);
	
	for(String row : rows) {
		String[] columns = row.split(",");
		
		ShapeFeature route = new ShapeFeature(Feature.FeatureType.LINES);
		
		// set id to be OpenFlights identifier for source airport
		
		// check that both airports on route have OpenFlights Identifier
		if(!columns[3].equals("\\N") && !columns[5].equals("\\N")){
			// set "source" property to be OpenFlights identifier for source airport
			route.putProperty("source", columns[3]);
			// "destination property" -- OpenFlights identifier
			route.putProperty("destination", columns[5]);
			
			routes.add(route);
		}
	}
		
	
	return routes;
	
	
	
}
 
開發者ID:simontangbit,項目名稱:CourseCode,代碼行數:30,代碼來源:ParseFeed.java


注:本文中的processing.core.PApplet.loadStrings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。