Skip to content

Commit

Permalink
Merge pull request #435 from dickschoeller/368-369-376-codebeat
Browse files Browse the repository at this point in the history
Fix codebeat issues
  • Loading branch information
dickschoeller authored Jun 18, 2017
2 parents 033f734 + bf95ce3 commit f71fd93
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public final void loadGedObject(final GedDocumentLoader loader,
* {@inheritDoc}
*/
@Override
public final String getTail() {
return this.tail;
public final void setTail(final String tail) {
this.tail = tail;
}

/**
* {@inheritDoc}
*/
@Override
public final void setTail(final String tail) {
this.tail = tail;
public final String getTail() {
return this.tail;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.schoellerfamily.gedbrowser.renderer;

import org.schoellerfamily.gedbrowser.datamodel.Person;
import org.schoellerfamily.gedbrowser.datamodel.visitor.GetDateVisitor;

/**
* @author Dick Schoeller
*/
public interface PersonLifeSpanRenderer {
/**
* @return whether the current person is confidential.
*/
boolean isConfidential();

/**
* @return whether the current person is confidential.
*/
boolean isHiddenLiving();

/**
* @return the GedObject
*/
Person getGedObject();

/**
* @return lifespan string.
*/
default String getLifeSpanString() {
if (isConfidential() || isHiddenLiving()) {
return "";
}

return String.format("(%s-%s)", date("Birth"), date("Death"));
}

/**
* @param type the event type to find a date for
* @return the date string
*/
default String date(final String type) {
final GetDateVisitor birthVisitor = new GetDateVisitor(type);
getGedObject().accept(birthVisitor);
return birthVisitor.getDate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.schoellerfamily.gedbrowser.renderer;

import org.schoellerfamily.gedbrowser.datamodel.GedObject;
import org.schoellerfamily.gedbrowser.datamodel.Name;
import org.schoellerfamily.gedbrowser.datamodel.Person;

/**
* @author Dick Schoeller
*/
public interface PersonNameRenderer {
/**
* @return whether the current person is confidential.
*/
boolean isConfidential();

/**
* @return whether the current person is confidential.
*/
boolean isHiddenLiving();

/**
* @param attribute The sub-object to render.
* @return The renderer.
*/
GedRenderer<? extends GedObject> createGedRenderer(GedObject attribute);

/**
* @return the GedObject
*/
Person getGedObject();

/**
* @return the name string in title format.
*/
default String getTitleName() {
final Name name = getGedObject().getName();
if (isConfidential()) {
return "Confidential";
} else if (isHiddenLiving()) {
return "Living";
} else {
final GedRenderer<?> nameRenderer = createGedRenderer(name);
return nameRenderer.getNameHtml();
}
}

/**
* @return Get the whole name without markup.
*/
default String getWholeName() {
if (isConfidential()) {
return "Confidential";
} else if (isHiddenLiving()) {
return "Living";
}
final Name name = getGedObject().getName();

final String prefix =
RenderingContextRenderer.escapeString(name.getPrefix());
final String surname =
RenderingContextRenderer.escapeString(name.getSurname());
final String suffix =
RenderingContextRenderer.escapeString(" ", name.getSuffix());

return String.format("%s %s%s", prefix, surname, suffix);
}

/**
* @return surname if not confidential
*/
default String getSurname() {
if (isConfidential() || isHiddenLiving()) {
return "?";
} else {
return getGedObject().getSurname();
}
}

/**
* @return surname first letter if not confidential
*/
default String getSurnameLetter() {
if (isConfidential() || isHiddenLiving()) {
return "?";
} else {
return getGedObject().getSurnameLetter();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import org.schoellerfamily.gedbrowser.analytics.LivingEstimator;
import org.schoellerfamily.gedbrowser.datamodel.Family;
import org.schoellerfamily.gedbrowser.datamodel.GedObject;
import org.schoellerfamily.gedbrowser.datamodel.Name;
import org.schoellerfamily.gedbrowser.datamodel.Person;
import org.schoellerfamily.gedbrowser.datamodel.navigator.PersonNavigator;
import org.schoellerfamily.gedbrowser.datamodel.visitor.GetDateVisitor;
import org.schoellerfamily.gedbrowser.datamodel.visitor.PersonVisitor;

/**
Expand All @@ -20,12 +18,8 @@
*/
public final class PersonRenderer extends GedRenderer<Person>
implements IndexHrefRenderer<Person>, HeaderHrefRenderer<Person>,
SubmittorsHrefRenderer<Person>, SourcesHrefRenderer<Person> {
/**
* Number of generations, including the root when rendering the tree.
*/
private static final int TREE_GENERATIONS = 5;

SubmittorsHrefRenderer<Person>, SourcesHrefRenderer<Person>,
PersonNameRenderer, PersonLifeSpanRenderer {
/**
* Connection to helper to estimate whether this person is living.
*/
Expand Down Expand Up @@ -64,67 +58,13 @@ public ParentsRenderer getParents() {
return parentsRenderer;
}

/**
* @return the name string in title format.
*/
public String getTitleName() {
final Name name = getGedObject().getName();
if (isConfidential()) {
return "Confidential";
} else if (isHiddenLiving()) {
return "Living";
} else {
final GedRenderer<?> nameRenderer = createGedRenderer(name);
return nameRenderer.getNameHtml();
}
}

/**
* @return lifespan string.
*/
public String getLifeSpanString() {
if (isConfidential() || isHiddenLiving()) {
return "";
}

return String.format("(%s-%s)", date("Birth"), date("Death"));
}

/**
* @param type the event type to find a date for
* @return the date string
*/
private String date(final String type) {
final GetDateVisitor birthVisitor = new GetDateVisitor(type);
getGedObject().accept(birthVisitor);
return birthVisitor.getDate();
}

/**
* @return the ID string of the person.
*/
public String getIdString() {
return getGedObject().getString();
}

/**
* @return Get the whole name without markup.
*/
public String getWholeName() {
if (isConfidential()) {
return "Confidential";
} else if (isHiddenLiving()) {
return "Living";
}
final Name name = getGedObject().getName();

final String prefix = escapeString(name.getPrefix());
final String surname = escapeString(name.getSurname());
final String suffix = escapeString(" ", name.getSuffix());

return String.format("%s %s%s", prefix, surname, suffix);
}

/**
* @return the list of renderers for the families of the person.
*/
Expand Down Expand Up @@ -168,20 +108,10 @@ public List<GedRenderer<?>> getAttributes() {
}

/**
* @return the 2D array of cells.
*/
public CellRow[] getTreeRows() {
final TreeTableRenderer ttr = new TreeTableRenderer(this,
confidentialGenCount(TREE_GENERATIONS));
return ttr.getTreeRows();
}

/**
* @param generations the number of generations to diplay.
* @param generations the number of generations to display.
* @return the 2D array of cells.
*/
public CellRow[] getTreeRows(final int generations) {
// TODO this is the one that is actually used.
final TreeTableRenderer ttr = new TreeTableRenderer(this,
confidentialGenCount(generations));
return ttr.getTreeRows();
Expand Down Expand Up @@ -230,26 +160,4 @@ public String getIndexHref() {
return "surnames?db=" + getGedObject().getDbName() + "&letter="
+ surnameLetter + "#" + surname;
}

/**
* @return surname if not confidential
*/
public String getSurname() {
if (isConfidential() || isHiddenLiving()) {
return "?";
} else {
return getGedObject().getSurname();
}
}

/**
* @return surname first letter if not confidential
*/
public String getSurnameLetter() {
if (isConfidential() || isHiddenLiving()) {
return "?";
} else {
return getGedObject().getSurnameLetter();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.schoellerfamily.gedbrowser.renderer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
Expand All @@ -25,7 +26,10 @@ public class SourcesRenderer extends GedRenderer<Root>
* @author Dick Schoeller
*/
private static class SourceRendererComparator
implements Comparator<SourceRenderer> {
implements Comparator<SourceRenderer>, Serializable {
/** */
private static final long serialVersionUID = 1L;

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public void testRenderGeorgeTree() throws IOException {
final Person george = (Person) root.find("I9");
final PersonRenderer personRenderer = new PersonRenderer(george,
new GedRendererFactory(), anonymousContext);
final CellRow[] cellRows = personRenderer.getTreeRows();
final CellRow[] cellRows = personRenderer.getTreeRows(5);
int i = 0;
for (final CellRow cellRow : cellRows) {
final CellRenderer[] cellRenderers = cellRow.getCells();
Expand All @@ -456,7 +456,7 @@ public void testRenderArnoldTree() throws IOException {
final Person arnold = (Person) root.find("I7");
final PersonRenderer personRenderer = new PersonRenderer(arnold,
new GedRendererFactory(), anonymousContext);
final CellRow[] cellRows = personRenderer.getTreeRows();
final CellRow[] cellRows = personRenderer.getTreeRows(5);
int i = 0;
for (final CellRow cellRow : cellRows) {
final CellRenderer[] cellRenderers = cellRow.getCells();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public void testRenderGeorgeTree() throws IOException {
final Person george = (Person) root.find("I9");
final PersonRenderer personRenderer = new PersonRenderer(george,
new GedRendererFactory(), userContext);
final CellRow[] cellRows = personRenderer.getTreeRows();
final CellRow[] cellRows = personRenderer.getTreeRows(5);
int i = 0;
for (final CellRow cellRow : cellRows) {
final CellRenderer[] cellRenderers = cellRow.getCells();
Expand Down
Loading

0 comments on commit f71fd93

Please sign in to comment.