Skip to content

Commit

Permalink
Fixes #230 - submittor data handling
Browse files Browse the repository at this point in the history
* Change the way in which the submittor data is handled
* Fix all of the related tests
  • Loading branch information
dickschoeller committed Mar 19, 2017
1 parent d3f5ea4 commit adeac82
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,24 @@ public Submittor() {
}

/**
* @param parent parent object of this submittor
* @param string long version of type string
* @param parent parent object of this source
* @param xref cross reference to this source
*/
public Submittor(final GedObject parent, final String string) {
super(parent, string);
public Submittor(final GedObject parent, final ObjectId xref) {
super(parent, xrefString(xref));
}

/**
* @param parent parent object of this submittor
* @param tag long version of type string
* @param tail additional text to append to the string
*/
public Submittor(final GedObject parent, final String tag,
final String tail) {
super(parent, processTail(tag, tail));
}

/**
* Handle the concatenation. Separate with a space if both are not empty.
* Get the ID string from and ObjectId. Returns null on null input.
*
* @param tag long version of the type string
* @param tail additional text to append to the string.
* @return the tag and tail concatenated.
* @param xref an object ID
* @return its string
*/
private static String processTail(final String tag, final String tail) {
if (isEmpty(tag)) {
if (isEmpty(tail)) {
return "";
} else {
return tail;
}
} else {
if (isEmpty(tail)) {
return tag;
} else {
return tag + " " + tail;
}
private static String xrefString(final ObjectId xref) {
if (xref == null) {
return null;
}
}

/**
* @param string
* string to test for emptiness. Null is supported
* @return true if the string is either null or empty
*/
// TODO could move this into a utility class or into GedObject as a
// protected method
private static boolean isEmpty(final String string) {
return string == null || string.isEmpty();
return xref.getIdString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ public SubmittorLink() {
super();
}

/**
* @param parent parent object of this link
* @param tag long version of type string
*/
public SubmittorLink(final GedObject parent, final String tag) {
super(parent, tag);
}

/**
* @param parent parent object of this submittor link
* @param tag long version of type string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public Submittor createSubmittor(final String idString, final String name) {
if (idString == null || name == null) {
return new Submittor(root, null);
}
final Submittor submittor = new Submittor(root, idString);
final Submittor submittor = new Submittor(root, new ObjectId(idString));
submittor.insert(new Name(submittor, name));
root.insert(submittor);
return submittor;
Expand All @@ -314,7 +314,7 @@ public Submittor createSubmittor(final String idString) {
if (idString == null) {
return new Submittor(root, null);
}
final Submittor submittor = new Submittor(root, idString);
final Submittor submittor = new Submittor(root, new ObjectId(idString));
root.insert(submittor);
return submittor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ public void testOneArgumentConstructor() {
assertMatch(sourceLink, null, "", "", "");
}

/** */
@Test
public void testTwoArgumentConstructor() {
final SubmittorLink sourceLink = new SubmittorLink(parent, string);
assertMatch(sourceLink, parent, expectedString, expectedFromString, "");
}

/** */
@Test
public void testThreeArgumentConstructor() {
Expand Down
Loading

0 comments on commit adeac82

Please sign in to comment.