Skip to content

Commit

Permalink
WIP: all descendents - generate children method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Ambroz authored and Jiri Ambroz committed Dec 10, 2022
1 parent 8e63b3a commit 6d4c7d7
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 273 deletions.
20 changes: 10 additions & 10 deletions src/main/java/org/ambrogenea/familyview/dto/AncestorCouple.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.ambrogenea.familyview.enums.Sex;

/**
*
* @author Jiri Ambroz <[email protected]>
*/
public class AncestorCouple {
Expand Down Expand Up @@ -112,6 +111,8 @@ public ArrayList<AncestorPerson> getChildren() {

public void setChildren(List<AncestorPerson> children) {
this.children = new ArrayList<>();
int maxSingles = 0;
int maxCouples = 0;
int actualSingles = 0;
int actualCouples = 0;
for (AncestorPerson child : children) {
Expand All @@ -121,8 +122,9 @@ public void setChildren(List<AncestorPerson> children) {
if (child.getSpouseCouples().isEmpty()) {
actualSingles++;
} else {
actualCouples += child.getSpouseCouple().getDescendentTreeInfo().getMaxCouplesCount();
actualSingles += child.getSpouseCouple().getDescendentTreeInfo().getMaxSinglesCount();
actualCouples++;
maxCouples += child.getSpouseCouple().getDescendentTreeInfo().getMaxCouplesCount();
maxSingles += child.getSpouseCouple().getDescendentTreeInfo().getMaxSinglesCount();
}

if (child.getSpouseCouple() == null) {
Expand All @@ -133,22 +135,20 @@ public void setChildren(List<AncestorPerson> children) {
getDescendentTreeInfo().addChildGenerations(generationsCount);
}

if (isNotSingle() && (actualSingles <= 2 && actualCouples <= 1)) {
getDescendentTreeInfo().setMaxSinglesCount(0);
getDescendentTreeInfo().setMaxCouplesCount(1);
} else {
getDescendentTreeInfo().setMaxSinglesCount(actualSingles);
getDescendentTreeInfo().setMaxCouplesCount(actualCouples);
}
getDescendentTreeInfo().setSinglesCount(actualSingles);
getDescendentTreeInfo().setCouplesCount(actualCouples);
getDescendentTreeInfo().validateMaxCounts(maxSingles, maxCouples);
}

public void addChildren(AncestorPerson child) {
this.children.add(child);
int generationsCount;
if (child.getSpouseCouples().isEmpty()) {
generationsCount = 1;
getDescendentTreeInfo().increaseSinglesCount();
} else {
generationsCount = 1 + child.getSpouseCouple().getDescendentTreeInfo().getMaxGenerationsCount();
getDescendentTreeInfo().increaseCouplesCount();
}
getDescendentTreeInfo().addChildGenerations(generationsCount);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
package org.ambrogenea.familyview.dto;

/**
*
* @author Jiri Ambroz <[email protected]>
*/
public class DescendentTreeInfo {

private int maxCouplesCount;
private int maxSinglesCount;
private int couplesCount;
private int singlesCount;
private int maxGenerationsCount;

public DescendentTreeInfo() {
maxCouplesCount = 0;
maxSinglesCount = 0;
couplesCount = 0;
singlesCount = 0;
maxGenerationsCount = 0;
}

public int getCouplesCount() {
return couplesCount;
}

public void setCouplesCount(int couplesCount) {
this.couplesCount = couplesCount;
if (couplesCount > maxCouplesCount) {
setMaxCouplesCount(couplesCount);
}
}

public int getSinglesCount() {
return singlesCount;
}

public void setSinglesCount(int singlesCount) {
this.singlesCount = singlesCount;
if (singlesCount > maxSinglesCount) {
setMaxSinglesCount(singlesCount);
}
}

public void increaseCouplesCount() {
setCouplesCount(getCouplesCount() + 1);
}

public void increaseSinglesCount() {
setSinglesCount(getSinglesCount() + 1);
}

public int getMaxCouplesCount() {
return maxCouplesCount;
}
Expand All @@ -24,10 +57,6 @@ public void setMaxCouplesCount(int maxCouplesCount) {
this.maxCouplesCount = maxCouplesCount;
}

public void increaseMaxCouplesCount() {
this.maxCouplesCount++;
}

public int getMaxSinglesCount() {
return maxSinglesCount;
}
Expand All @@ -36,10 +65,6 @@ public void setMaxSinglesCount(int maxSinglesCount) {
this.maxSinglesCount = maxSinglesCount;
}

public void increaseMaxSinglesCount() {
this.maxSinglesCount++;
}

public int getMaxGenerationsCount() {
return maxGenerationsCount;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ambrogenea/familyview/enums/Relation.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public enum Relation {

public int getInt() {
if (this.equals(DIRECT)) {
return 2;
return 3;
} else {
return 1;
return 2;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
import org.ambrogenea.familyview.dto.ParentsDto;
import org.ambrogenea.familyview.dto.tree.Position;
import org.ambrogenea.familyview.dto.tree.TreeModel;
import org.ambrogenea.familyview.enums.Relation;

public interface CommonAncestorService {

Position addRootSpouses(Position rootPersonPosition, AncestorPerson person);
void generateSpouseAndSiblings(Position rootPersonPosition, AncestorPerson rootPerson);
int generateChildren(Position fatherPosition, AncestorCouple spouseCouple);
int generateChildren(Position firstChildrenPosition, AncestorCouple spouseCouple, AncestorPerson rootSpouse);
void addSiblings(Position rootSiblingPosition, AncestorPerson rootSibling);
ParentsDto generateParents(Position heraldryPosition, AncestorPerson child);
ParentsDto generateHorizontalParents(Position heraldryPosition, AncestorPerson child);
ParentsDto generateVerticalParents(Position heraldryPosition, AncestorPerson child);

void addPerson(Position center, AncestorPerson person);
void addRootPerson(Position center, AncestorPerson person);
void addLine(Position start, Position end, Relation lineType);
void addHeraldry(Position childPosition, String simpleBirthPlace);

TreeModel getTreeModel();

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package org.ambrogenea.familyview.service;

import org.ambrogenea.familyview.dto.AncestorCouple;
import org.ambrogenea.familyview.dto.AncestorPerson;
import org.ambrogenea.familyview.dto.tree.Position;
import org.ambrogenea.familyview.dto.tree.TreeModel;

import java.util.List;

public interface LineageService extends CommonAncestorService {
Position addClosestFamily(Position rootPosition, AncestorPerson person);
TreeModel generateFathersFamily(Position heraldryPosition, AncestorPerson person);
TreeModel generateMotherFamily(Position heraldryPosition, AncestorPerson person);
TreeModel generateParentsFamily(Position heraldryPosition, AncestorPerson person);
TreeModel addAllParents(Position heraldryPosition, AncestorPerson child);

TreeModel generateAllDescendents(Position firstChildPosition, List<AncestorCouple> spouseCouples, int allDescendentsWidth);
Position addCoupleFamily(Position firstChildPosition, AncestorCouple couple, int descendentsWidth);
}
Loading

0 comments on commit 6d4c7d7

Please sign in to comment.