Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions GBLesson1.iml
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>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
59 changes: 59 additions & 0 deletions src/ru/gb/family_tree/Main.java
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;
// }
}
79 changes: 79 additions & 0 deletions src/ru/gb/family_tree/model/Service.java
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

угловые скобочки и тип Human

private String filePath = "src/ru/gb/family_tree/model/save/tree.txt";
Copy link
Owner

Choose a reason for hiding this comment

The 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));
}
Copy link
Owner

Choose a reason for hiding this comment

The 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
Copy link
Owner

Choose a reason for hiding this comment

The 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);
}
Copy link
Owner

Choose a reason for hiding this comment

The 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;
}
}

}
24 changes: 24 additions & 0 deletions src/ru/gb/family_tree/model/family_tree/FamiliTreeIterator.java
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++);
}
}
Loading