Created
October 6, 2011 06:32
-
-
Save sdqali/1266674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bar.foo; | |
import java.io.BufferedReader; | |
import java.io.DataInputStream; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class ObjectMap { | |
private ArrayList<String> lines; | |
private HashMap<String, String> objects; | |
public ObjectMap(String file) { | |
readLinesFrom(file); | |
parseObjects(); | |
} | |
public String idFor(String key) { | |
return objects.get(key); | |
} | |
private void parseObjects() { | |
objects = new HashMap<String, String>(); | |
for (String line : lines) { | |
String key = line.split(":")[0].trim(); | |
String value = line.split(":")[1].trim(); | |
objects.put(key, value); | |
} | |
} | |
private void readLinesFrom(String file) { | |
FileInputStream fstream; | |
lines = new ArrayList<String>(); | |
try { | |
fstream = new FileInputStream(file); | |
DataInputStream in = new DataInputStream(fstream); | |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | |
String line; | |
while ((line = br.readLine()) != null) { | |
lines.add(line); | |
} | |
in.close(); | |
} catch (IOException e) { | |
System.out.println("Error reading object map file " + file); | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment