FlatFilepublic class FlatFile extends Object
Fields Summary |
---|
Hashtable | families | Hashtable | people | String | lastLine | int | individualCount | int | familyCount | int | specialEnd | HumanInterface.FamilyFrame | target |
Constructors Summary |
---|
public FlatFile()
families = new Hashtable();
people = new Hashtable();
|
Methods Summary |
---|
void | createFamily(java.io.BufferedReader in, java.lang.String line)
int endOfRecord = 0;
String inline = new String();
String verb = new String();
int firstTime = 1;
int refNo = 0;
Individual husband = null;
Individual wife = null;
Marriage ceremony = null;
String place = new String();
Divorce decree = null;
String bmonth = new String();
String d = "";
Family ff;
Vector children = null;
while(endOfRecord != 1) {
try {
inline = in.readLine();
} catch(IOException ex) {}
StringTokenizer st = new StringTokenizer(inline);
st.nextElement();
verb = (String)st.nextElement();
if(verb.equals("_FRECT")) endOfRecord = 1;
else {
if(verb.equals("REFN")) {
verb = (String)st.nextElement();
verb = verb.substring(1,verb.length());
refNo = Integer.parseInt(verb);
}
if(verb.equals("HUSB")) {
verb = (String)st.nextElement();
verb = verb.substring(1,verb.lastIndexOf('@"));
verb = verb.substring(1,verb.length());
int tempRefNo = Integer.parseInt(verb);
husband = (Individual)people.get(new Integer(tempRefNo));
}
if(verb.equals("WIFE")) {
verb = (String)st.nextElement();
verb = verb.substring(1,verb.lastIndexOf('@"));
verb = verb.substring(1,verb.length());
int tempRefNo = Integer.parseInt(verb);
wife = (Individual)people.get(new Integer(tempRefNo));
}
if(verb.equals("CHIL")) {
if(children == null) children = new Vector();
verb = (String)st.nextElement();
verb = verb.substring(1,verb.lastIndexOf('@"));
verb = verb.substring(1,verb.length());
int tempRefNo = Integer.parseInt(verb);
children.addElement(people.get(new Integer(tempRefNo)));
}
if(verb.equals("MARR")) {
try {
inline = in.readLine();
}catch(IOException exex) {}
StringTokenizer stt = new StringTokenizer(inline);
if(stt.countTokens() < 5)
{
d = "?";
}
else {
stt.nextElement();
verb = (String)stt.nextElement();
if(verb.equals("DATE")) {
d = d + (String)stt.nextElement() + "/";
d = d + (String)stt.nextElement() + "/";
d = d + (String)stt.nextElement();
}
try {
inline = in.readLine();
}catch(IOException exxe) {}
StringTokenizer sttr = new StringTokenizer(inline);
sttr.nextElement();
verb = (String)sttr.nextElement();
if(verb.equals("PLAC")) {
while(sttr.hasMoreTokens()) {
place = place + sttr.nextElement() + " ";
}
}
}
}
}
}
if(husband != null && wife != null) {
ceremony = new Marriage(d,"places","notes");
ff = new Family(refNo,husband,wife,ceremony,null);
if(children != null) {
Enumeration list = children.elements();
while(list.hasMoreElements()) {
ff.addChild((Individual)list.nextElement());
}
}
// target.textArea.setText(ff.getDetails());
families.put(new Integer(refNo),ff);
}
| void | createIndividual(java.io.BufferedReader in, java.lang.String line)
String inline;
String verb;
int endOfRecord = 0;
int firstTim = 1;
int refNo = 0;
String FamilyName = new String();
String GivenNames = new String();
String place = new String();
String sex = new String();
Birth birth = null;
Death death = null;
String lastIndex;
String d = "";
int indexFirst = 1;
Individual record;
inline = line;
// if(people == null) people = new Hashtable();
while(endOfRecord == 0) {
StringTokenizer st = new StringTokenizer(inline);
lastIndex = (String)st.nextElement();
verb = (String)st.nextElement();
if(verb.equals("_BLOB"))
{
endOfRecord = 1;
}
else {
if(lastIndex.equals("0") && indexFirst == 0)
{
endOfRecord = 1;
specialEnd = 1;
lastLine = inline;
}
else {
indexFirst = 0;
if(verb.equals("REFN")) {
verb = (String)st.nextElement();
verb = verb.substring(1,verb.length());
refNo = Integer.parseInt(verb);
}
if(verb.equals("BIRT")) {
try {
inline = in.readLine();
}catch(IOException exex) {}
StringTokenizer stt = new StringTokenizer(inline);
if(stt.countTokens() < 5)
{
d = "?";
}
else
{
stt.nextElement();
verb = (String)stt.nextElement();
if(verb.equals("DATE")) {
d = d + (String)stt.nextElement() + "/";
d = d + (String)stt.nextElement() + "/";
d = d + (String)stt.nextElement();
}
}
try {
inline = in.readLine();
}catch(IOException exex) {}
StringTokenizer sttr = new StringTokenizer(inline);
sttr.nextElement();
verb = (String)sttr.nextElement();
if(verb.equals("PLAC")) place = (String)sttr.nextElement();
}
if(verb.equals("NAME")) {
verb = (String)st.nextElement();
while(!verb.startsWith("/") && st.hasMoreElements()) {
if(firstTim == 1) {
GivenNames = verb;
firstTim = 0;
}
else
GivenNames = GivenNames + " " + verb;
if(st.hasMoreElements())
verb = (String)st.nextElement();
}
if(verb.startsWith("/")) {
if(verb.equals("//")) verb = "Unknown";
else {
verb = verb.substring(1,verb.length()-1);
verb = new String(verb.toLowerCase());
String tmp = verb.valueOf(verb.charAt(0));
tmp = tmp.toUpperCase();
verb = new String(tmp + verb.substring(1,verb.length()));
}
}
FamilyName = verb;
}
if(verb.equals("SEX")) {
verb = (String)st.nextElement();
if(verb.equals("M")) sex = "M";
else sex = "F";
}
try {
inline = in.readLine();
}catch(IOException ex) {}
}
}
}
if(GivenNames.length() == 0) GivenNames = "Unknown";
birth = new Birth(d,place,"notes");
record = new Individual(refNo,FamilyName,GivenNames,sex, birth,null);
// individualDM.add(refNo,FamilyName,GivenNames,sex, birth,null);
people.put(new Integer(refNo),record);
// target.textArea.setText(record.getDetails());
| public java.util.Hashtable | getFamily()
return families;
| public java.util.Hashtable | getIndividual()
return people;
| public void | readData(java.lang.String filename)
String inText = " ";
int individualCount = 0;
int familyCount = 0;
int occurances = 0;
try {
BufferedReader in = new BufferedReader(new FileReader(filename));
while(!inText.equals("0 TRLR")) {
if(specialEnd != 1)
inText = in.readLine();
else inText = lastLine;
StringTokenizer st = new StringTokenizer(inText);
occurances = 0;
while(st.hasMoreTokens()) {
String line = (String)st.nextElement();
occurances++;
if(line.equals("INDI") && occurances == 3) {
specialEnd = 0;
individualCount++;
/* target.textArea.appendText("\nIndividal count: " + individualCount);
if(individualCount == 115) {
int i = 9;
}*/
createIndividual(in,inText);
}
if(line.equals("FAM") && occurances == 3) {
specialEnd = 0;
familyCount++;
// target.textArea.appendText("\nFamily count: " + familyCount);
createFamily(in,inText);
}
}
}
in.close();
}
catch(FileNotFoundException ex) {}
catch(IOException exe) {}
| public void | setTarget(HumanInterface.FamilyFrame frame)
target = frame;
|
|