package nl.mpi.kinnate.gedcomimport;

import java.util.ArrayList;

/**
 * Document : ImportLineStructure
 * Created on : Jul 30, 2012, 9:23:36 AM
 * Author : Peter Withers
 */
public abstract class ImportLineStructure {

    int gedcomLevel = 0;
    String currentID = null;
    String entityType = null;
    boolean isFileHeader = false;
    boolean incompleteLine = false;
    private int currentFieldIndex = 0;

    protected class FieldEntry {

        protected String lineContents = null;
        protected String currentName = null;

        protected FieldEntry(String currentName, String lineContents) throws ImportException {
            if (currentName == null) {
                throw new ImportException("Cannot have null names to a field.");
            }
            this.currentName = currentName.trim();
            if (lineContents != null) {
                this.lineContents = lineContents.trim();
            }
        }
    }
    ArrayList<FieldEntry> fieldEntryList = new ArrayList<FieldEntry>();

    public ImportLineStructure(String lineString, ArrayList<String> gedcomLevelStrings) {
    }

    protected void addFieldEntry(String currentName, String lineContents) throws ImportException {
        fieldEntryList.add(new FieldEntry(currentName, lineContents));
    }

    protected FieldEntry getCurrent() {
        return fieldEntryList.get(currentFieldIndex);
    }

    protected void moveToNext() {
        currentFieldIndex++;
    }

    protected boolean hasCurrent() {
        return currentFieldIndex < fieldEntryList.size();
    }

    public String getCurrentID() throws ImportException {
        if (currentID == null) {
//            new Exception().printStackTrace();
            throw new ImportException("CurrentID has not been set");
        }
        return currentID;
    }

    public String getCurrentName() throws ImportException {
        if (getCurrent().currentName == null) {
//            new Exception().printStackTrace();
            throw new ImportException("CurrentName has not been set");
        }
        return getCurrent().currentName;
    }

    public int getGedcomLevel() {
        return gedcomLevel;
    }

    public boolean hasLineContents() {
        return hasCurrent() && getCurrent().lineContents != null;
    }

    public String getLineContents() throws ImportException {
        if (!hasCurrent() || getCurrent().lineContents == null) {
//            new Exception().printStackTrace();
            throw new ImportException("LineContents has not been set");
        }
        return getCurrent().lineContents;
    }

    public String getEntityType() {
        return entityType;
    }

    public boolean isFileHeader() {
        return isFileHeader;
    }

    public boolean isContinueLine() {
        return false;
    }

    public boolean isContinueLineBreak() {
        return false;
    }

    public boolean isEndOfFileMarker() {
        return false;
    }

    public boolean isIncompleteLine() {
        return incompleteLine;
    }

    abstract boolean isRelation();
}

@@ -58,16 +58,111 @@
 rayList;
+%0Aimport nl.mpi.kinnate.kindata.DataTypes;%0Aimport nl.mpi.kinnate.kindata.DataTypes.RelationType;
 %0A%0A/**%0A *
@@ -503,16 +503,442 @@
 x = 0;%0A%0A
+    protected class RelationEntry %7B%0A%0A        protected String egoIdString;%0A        protected String alterIdString;%0A        protected DataTypes.RelationType relationType;%0A%0A        public RelationEntry(String egoIdString, String alterIdString, RelationType relationType) %7B%0A            this.egoIdString = egoIdString;%0A            this.alterIdString = alterIdString;%0A            this.relationType = relationType;%0A        %7D%0A    %7D%0A%0A
     prot
@@ -1533,16 +1533,97 @@
 ntry%3E();
+%0A    ArrayList%3CRelationEntry%3E relationEntryList = new ArrayList%3CRelationEntry%3E();
 %0A%0A    pu
@@ -1882,32 +1882,261 @@
 tents));%0A    %7D%0A%0A
+    protected void addRelationEntry(String egoIdString, String alterIdString, RelationType relationType) throws ImportException %7B%0A        relationEntryList.add(new RelationEntry(egoIdString, alterIdString, relationType));%0A    %7D%0A%0A
     protected Fi
@@ -2150,24 +2150,29 @@
 y getCurrent
+Field
 () %7B%0A       
@@ -2254,16 +2254,21 @@
 veToNext
+Field
 () %7B%0A   
@@ -2332,16 +2332,21 @@
 sCurrent
+Field
 () %7B%0A   
@@ -2733,32 +2733,37 @@
   if (getCurrent
+Field
 ().currentName =
@@ -2927,16 +2927,21 @@
 tCurrent
+Field
 ().curre
@@ -3088,16 +3088,21 @@
 sCurrent
+Field
 () && ge
@@ -3101,32 +3101,37 @@
 () && getCurrent
+Field
 ().lineContents 
@@ -3230,16 +3230,21 @@
 sCurrent
+Field
 () %7C%7C ge
@@ -3243,32 +3243,37 @@
 () %7C%7C getCurrent
+Field
 ().lineContents 
@@ -3439,16 +3439,21 @@
 tCurrent
+Field
 ().lineC

Add an importer for TIP format by making the gedcom importer more generic. refs #2193