-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: all descendents - generate children method
- Loading branch information
Jiri Ambroz
authored and
Jiri Ambroz
committed
Dec 10, 2022
1 parent
8e63b3a
commit 6d4c7d7
Showing
12 changed files
with
153 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
import org.ambrogenea.familyview.enums.Sex; | ||
|
||
/** | ||
* | ||
* @author Jiri Ambroz <[email protected]> | ||
*/ | ||
public class AncestorCouple { | ||
|
@@ -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) { | ||
|
@@ -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) { | ||
|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
@@ -24,10 +57,6 @@ public void setMaxCouplesCount(int maxCouplesCount) { | |
this.maxCouplesCount = maxCouplesCount; | ||
} | ||
|
||
public void increaseMaxCouplesCount() { | ||
this.maxCouplesCount++; | ||
} | ||
|
||
public int getMaxSinglesCount() { | ||
return maxSinglesCount; | ||
} | ||
|
@@ -36,10 +65,6 @@ public void setMaxSinglesCount(int maxSinglesCount) { | |
this.maxSinglesCount = maxSinglesCount; | ||
} | ||
|
||
public void increaseMaxSinglesCount() { | ||
this.maxSinglesCount++; | ||
} | ||
|
||
public int getMaxGenerationsCount() { | ||
return maxGenerationsCount; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
src/main/java/org/ambrogenea/familyview/service/LineageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.