Skip to content

Commit

Permalink
Issue #83 More conversion of model to Javabeans.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Harrah (frizbog) committed Jul 4, 2016
1 parent 65f762b commit a53ba33
Show file tree
Hide file tree
Showing 10 changed files with 730 additions and 588 deletions.
153 changes: 146 additions & 7 deletions src/main/java/org/gedcom4j/model/StringTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.List;

import org.gedcom4j.Options;

/**
* <p>
* A structure to hold an element (as string data) from a GEDCOM file in such a way as to preserve and recognize the
Expand All @@ -45,22 +47,22 @@ public class StringTree {
/**
* All the elements that are child elements of this element
*/
public List<StringTree> children = new ArrayList<StringTree>(0);
private List<StringTree> children = getChildren(Options.isCollectionInitializationEnabled());

/**
* The ID number of this element
*/
public String id;
private String id;

/**
* The level of this element
*/
public int level;
private int level;

/**
* The line number of the GEDCOM from which this element was derived
*/
public int lineNum;
private int lineNum;

/**
* <p>
Expand All @@ -71,17 +73,17 @@ public class StringTree {
* that leads to infinite recursion. See Issue #60.
* </p>
*/
public StringTree parent = null;
private StringTree parent = null;

/**
* The tag for this element
*/
public String tag;
private String tag;

/**
* The value for this element (basically everything after the tag)
*/
public String value;
private String value;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -135,6 +137,83 @@ public boolean equals(Object obj) {
return true;
}

/**
* Get the children
*
* @return the children
*/
public List<StringTree> getChildren() {
return children;
}

/**
* Get the children
*
* @param initializeIfNeeded
* initialize the collection, if needed?
* @return the children
*/
public List<StringTree> getChildren(boolean initializeIfNeeded) {
if (initializeIfNeeded && children == null) {
children = new ArrayList<StringTree>(0);
}
return children;
}

/**
* Get the id
*
* @return the id
*/
public String getId() {
return id;
}

/**
* Get the level
*
* @return the level
*/
public int getLevel() {
return level;
}

/**
* Get the lineNum
*
* @return the lineNum
*/
public int getLineNum() {
return lineNum;
}

/**
* Get the parent
*
* @return the parent
*/
public StringTree getParent() {
return parent;
}

/**
* Get the tag
*
* @return the tag
*/
public String getTag() {
return tag;
}

/**
* Get the value
*
* @return the value
*/
public String getValue() {
return value;
}

/**
* {@inheritDoc}
*/
Expand All @@ -151,6 +230,66 @@ public int hashCode() {
return result;
}

/**
* Set the id
*
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* Set the level
*
* @param level
* the level to set
*/
public void setLevel(int level) {
this.level = level;
}

/**
* Set the lineNum
*
* @param lineNum
* the lineNum to set
*/
public void setLineNum(int lineNum) {
this.lineNum = lineNum;
}

/**
* Set the parent
*
* @param parent
* the parent to set
*/
public void setParent(StringTree parent) {
this.parent = parent;
}

/**
* Set the tag
*
* @param tag
* the tag to set
*/
public void setTag(String tag) {
this.tag = tag;
}

/**
* Set the value
*
* @param value
* the value to set
*/
public void setValue(String value) {
this.value = value;
}

/**
* {@inheritDoc}
*/
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/gedcom4j/model/StringWithCustomTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
package org.gedcom4j.model;

import java.util.List;

/**
* Represents a string value from a tag, and allows for user-defined child tags
*
Expand Down Expand Up @@ -57,9 +59,10 @@ public StringWithCustomTags(String string) {
* the stringtree with the value of the string, plus optional custom tags
*/
public StringWithCustomTags(StringTree s) {
value = s.value;
if (s.children != null && !s.children.isEmpty()) {
getCustomTags(true).addAll(s.children);
value = s.getValue();
List<StringTree> children = s.getChildren();
if (children != null && !children.isEmpty()) {
getCustomTags(true).addAll(children);
}
}

Expand Down Expand Up @@ -123,7 +126,7 @@ public String toString() {
StringBuilder sb = new StringBuilder(value == null ? "null" : value);
for (StringTree ct : getCustomTags()) {
sb.append("\n");
sb.append(ct.level + (ct.id == null ? "" : " " + ct.id) + " " + ct.tag + " " + ct.value);
sb.append(ct.getLevel() + (ct.getId() == null ? "" : " " + ct.getId()) + " " + ct.getTag() + " " + ct.getValue());
}

return sb.toString();
Expand Down
Loading

0 comments on commit a53ba33

Please sign in to comment.