001: /**
002: * Concat.java
003: *
004: Copyright (c) 2007, Innovatics Inc.
005:
006: All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
009:
010: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
011: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
012:
013: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
017: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
018: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
019: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
020: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
021: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
022: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
023: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: */package util;
025:
026: import java.lang.*;
027: import java.io.*;
028: import java.util.*;
029:
030: public class Concat {
031:
032: private List<Country> countries = new ArrayList<Country>();
033:
034: public Concat(String[] args) throws IOException {
035: BufferedReader reader = new BufferedReader(new FileReader(
036: "data/2119rank.txt"));
037: String line = null;
038: while ((line = reader.readLine()) != null) {
039: String[] info = line.split("\t");
040: if (info.length != 4)
041: continue;
042: Country country = new Country();
043: country.name = info[1].trim();
044: country.population = info[2].trim();
045: countries.add(country);
046: }
047: reader.close();
048:
049: reader = new BufferedReader(new FileReader("data/2004rank.txt"));
050: while ((line = reader.readLine()) != null) {
051: String[] info = line.split("\t");
052: if (info.length != 4)
053: continue;
054:
055: for (int i = 0; i < countries.size(); i++) {
056: Country country = countries.get(i);
057: if (country.name.equals(info[1].trim())) {
058: country.gdp_per_capita = info[2].trim();
059: }
060: }
061: }
062: reader.close();
063:
064: reader = new BufferedReader(new FileReader("data/2038rank.txt"));
065: while ((line = reader.readLine()) != null) {
066: String[] info = line.split("\t");
067: if (info.length != 4)
068: continue;
069:
070: for (int i = 0; i < countries.size(); i++) {
071: Country country = countries.get(i);
072: if (country.name.equals(info[1].trim())) {
073: country.electricity_production = info[2].trim();
074: }
075: }
076: }
077: reader.close();
078:
079: reader = new BufferedReader(new FileReader("data/2042rank.txt"));
080: while ((line = reader.readLine()) != null) {
081: String[] info = line.split("\t");
082: if (info.length != 4)
083: continue;
084:
085: for (int i = 0; i < countries.size(); i++) {
086: Country country = countries.get(i);
087: if (country.name.equals(info[1].trim())) {
088: country.electricity_consumption = info[2].trim();
089: }
090: }
091: }
092: reader.close();
093:
094: reader = new BufferedReader(new FileReader("data/2150rank.txt"));
095: while ((line = reader.readLine()) != null) {
096: String[] info = line.split("\t");
097: if (info.length != 4)
098: continue;
099:
100: for (int i = 0; i < countries.size(); i++) {
101: Country country = countries.get(i);
102: if (country.name.equals(info[1].trim())) {
103: country.telephones = info[2].trim();
104: }
105: }
106: }
107: reader.close();
108:
109: reader = new BufferedReader(new FileReader("data/2151rank.txt"));
110: while ((line = reader.readLine()) != null) {
111: String[] info = line.split("\t");
112: if (info.length != 4)
113: continue;
114:
115: for (int i = 0; i < countries.size(); i++) {
116: Country country = countries.get(i);
117: if (country.name.equals(info[1].trim())) {
118: country.cellphones = info[2].trim();
119: }
120: }
121: }
122: reader.close();
123:
124: reader = new BufferedReader(new FileReader("data/2184rank.txt"));
125: while ((line = reader.readLine()) != null) {
126: String[] info = line.split("\t");
127: if (info.length != 4)
128: continue;
129:
130: for (int i = 0; i < countries.size(); i++) {
131: Country country = countries.get(i);
132: if (country.name.equals(info[1].trim())) {
133: country.internet_hosts = info[2].trim();
134: }
135: }
136: }
137: reader.close();
138:
139: reader = new BufferedReader(new FileReader("data/2153rank.txt"));
140: while ((line = reader.readLine()) != null) {
141: String[] info = line.split("\t");
142: if (info.length != 4)
143: continue;
144:
145: for (int i = 0; i < countries.size(); i++) {
146: Country country = countries.get(i);
147: if (country.name.equals(info[1].trim())) {
148: country.internet_users = info[2].trim();
149: }
150: }
151: }
152: reader.close();
153:
154: // Write the output files
155: BufferedWriter writer = null;
156: for (int i = 0; i < countries.size(); i++) {
157: Country country = countries.get(i);
158: String country_name = country.name.replace(" ", "_");
159: country_name = country_name.replace("'", "_");
160: country_name = country_name.replace(",", "_");
161: country_name = country_name.replace("(", "_");
162: country_name = country_name.replace(")", "_");
163: writer = new BufferedWriter(new FileWriter("www/country/"
164: + country_name + ".txt"));
165: writer.write(country.name);
166: writer.write("\n");
167: writer.write("---------------------------");
168: writer.write("\n");
169: writer.write("Population\t" + country.population);
170: writer.write("\n");
171: writer.write("Telephones\t" + country.telephones);
172: writer.write("\n");
173: writer.write("Cell phones\t" + country.cellphones);
174: writer.write("\n");
175: writer.write("Internet hosts\t" + country.internet_hosts);
176: writer.write("\n");
177: writer.write("Internet users\t" + country.internet_users);
178: writer.write("\n");
179: writer.close();
180:
181: /*
182: System.out.print(country.name);
183: System.out.print("|");
184: System.out.print(country.population);
185: System.out.print("|");
186: if (country.electricity_production != null) {
187: System.out.print(country.electricity_production);
188: }
189: System.out.print("|");
190: if (country.electricity_consumption != null) {
191: System.out.print(country.electricity_consumption);
192: }
193: System.out.print("|");
194: if (country.telephones != null) {
195: System.out.print(country.telephones);
196: }
197: System.out.print("|");
198: if (country.cellphones != null) {
199: System.out.print(country.cellphones);
200: }
201: System.out.print("|");
202: if (country.internet_hosts != null) {
203: System.out.print(country.internet_hosts);
204: }
205: System.out.print("|");
206: if (country.internet_users != null) {
207: System.out.print(country.internet_users);
208: }
209: System.out.println();
210: */
211: }
212: }
213:
214: public static void main(String[] args) {
215: try {
216: new Concat(args);
217: } catch (IOException ioe) {
218: System.err.println(ioe);
219: }
220: }
221:
222: } // End of Concat.java
223:
224: class Country {
225: protected String name = null; // 2119rank.txt
226: protected String population = null; // 2119rank.txt
227:
228: protected String gdp_per_capita = null; // 2004rank.txt
229: protected String electricity_production = null; // 2038rank.txt
230: protected String electricity_consumption = null; // 2042rank.txt
231: protected String telephones = null; // 2150rank.txt
232: protected String cellphones = null; // 2151rank.txt
233: protected String internet_hosts = null; // 2184rank.txt
234: protected String internet_users = null; // 2153rank.txt
235: }
|