-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Создана база семейного древа. #16
base: master
Are you sure you want to change the base?
Changes from 12 commits
31bc8eb
8121c7f
b1e5714
f792834
06cbac0
1a64a82
d0f8473
a38305d
0744e18
0d7802e
9fcb9ee
6eeda45
d4812e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package ru.gb.family_tree; | ||
|
||
import ru.gb.family_tree.model.family_tree.FamilyTree; | ||
import ru.gb.family_tree.model.human.Gender; | ||
import ru.gb.family_tree.model.human.Human; | ||
import ru.gb.family_tree.model.save.FileHandler; | ||
import ru.gb.family_tree.model.save.Writable; | ||
import ru.gb.family_tree.view.ConsoleUI; | ||
import ru.gb.family_tree.view.View; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
View view = new ConsoleUI(); | ||
view.start(); | ||
|
||
} | ||
// String filePath = "src/ru/gb/family_tree/save/tree.txt"; | ||
// FamilyTree tree = testTree(); | ||
// //FamilyTree tree = load(filePath); | ||
// System.out.println(tree); | ||
// tree.sotrByName(); | ||
// System.out.println(tree); | ||
// tree.sortByBirthDate(); | ||
// System.out.println(tree); | ||
// //save(tree, filePath); | ||
// | ||
// } | ||
// | ||
// private static FamilyTree load(String filePath){ | ||
// Writable writable = new FileHandler(); | ||
// return (FamilyTree) writable.read(filePath); | ||
// } | ||
// | ||
// private static void save(FamilyTree familyTree, String filePath){ | ||
// Writable writable = new FileHandler(); | ||
// writable.save(familyTree, filePath); | ||
// } | ||
// | ||
// private static FamilyTree testTree() { | ||
// FamilyTree familyTree = new FamilyTree(); | ||
// | ||
// Human human1 = new Human("Oleg", Gender.Male, LocalDate.of(1985, 12, 12)); | ||
// Human human2 = new Human("Olga", Gender.Female, LocalDate.of(1984, 6, 18)); | ||
// Human human3 = new Human("Ruslan", Gender.Male, LocalDate.of(2006, 10, 10), human1, human2); | ||
// Human human4 = new Human("Lena", Gender.Female, LocalDate.of(2016, 5, 4), human1, human2); | ||
// | ||
// | ||
// familyTree.addHuman(human1); | ||
// familyTree.addHuman(human2); | ||
// familyTree.addHuman(human3); | ||
// familyTree.addHuman(human4); | ||
// | ||
// familyTree.setWedding(human1.getId(), human2.getId()); | ||
// | ||
// return familyTree; | ||
// } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ru.gb.family_tree.model; | ||
|
||
import ru.gb.family_tree.model.family_tree.FamilyTree; | ||
import ru.gb.family_tree.model.human.Gender; | ||
import ru.gb.family_tree.model.human.Human; | ||
import ru.gb.family_tree.model.save.FileHandler; | ||
import ru.gb.family_tree.model.save.Writable; | ||
import ru.gb.family_tree.presenter.Presenter; | ||
import ru.gb.family_tree.view.View; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public class Service { | ||
private FamilyTree familyTree; | ||
private String filePath = "src/ru/gb/family_tree/model/save/tree.txt"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не имеет отношения к работе Сервис. Перенести в класс, где используется |
||
|
||
public Service() { | ||
familyTree = new FamilyTree<>(); | ||
} | ||
|
||
public void addHuman(String name, String gender, LocalDate date) { | ||
familyTree.addHuman(new Human(name, getGenderFromString(gender), date)); | ||
} | ||
|
||
public void addChildren(int nameParent, int nameChild){ | ||
familyTree.getById(nameParent).addChild(familyTree.getById(nameChild)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А ребенку добавить связь с родителем? |
||
|
||
public String getHumanInfo(){ | ||
String answer = familyTree.getInfo(); | ||
return answer; | ||
} | ||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опять же название метода не сочетается с телом метода |
||
|
||
public void sotrByName() { | ||
familyTree.sortByName(); | ||
} | ||
|
||
public void sortByBirthDate() { | ||
familyTree.sortByBirthDate(); | ||
} | ||
|
||
public void saveFemaleTree() { | ||
save(familyTree, filePath); | ||
} | ||
|
||
public void loadFemaleTree() { | ||
familyTree = load(filePath); | ||
} | ||
|
||
private static FamilyTree load(String filePath){ | ||
Writable writable = new FileHandler(); | ||
return (FamilyTree) writable.read(filePath); | ||
} | ||
|
||
private static void save(FamilyTree familyTree, String filePath){ | ||
Writable writable = new FileHandler(); | ||
writable.save(familyTree, filePath); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Убрать статику. Сделать обычным методом. Writable сделать полем. Убрать нарушение 5 принципа. Зависимость должна быть от абстракции |
||
|
||
|
||
public void setWedding(int idMale, int idFemale) { | ||
familyTree.setWedding(idMale, idFemale); | ||
} | ||
|
||
public static Gender getGenderFromString(String input) { | ||
if (input == null) { | ||
return null; | ||
} | ||
|
||
try { | ||
return Gender.valueOf(input); | ||
} catch (IllegalArgumentException e) { | ||
// Если введенная строка не соответствует ни одной из констант | ||
return null; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ru.gb.family_tree.model.family_tree; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class FamiliTreeIterator<T extends TreeNode<T>> implements Iterator<T> { | ||
private List<T> list; | ||
private int index; | ||
|
||
public FamiliTreeIterator(List<T> list) { | ||
this.list = list; | ||
index = 0; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return index < list.size(); | ||
} | ||
|
||
@Override | ||
public T next() { | ||
return list.get(index++); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
угловые скобочки и тип Human