-
Notifications
You must be signed in to change notification settings - Fork 722
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
Home work6 #1184
Open
Oleg520
wants to merge
13
commits into
Liberate520:master
Choose a base branch
from
Oleg520:HomeWork6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Home work6 #1184
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c47c665
hw1
Oleg520 e86e7fe
create branch hw2
Oleg520 7bb60d3
hw2 finished
Oleg520 9bba228
merge hw2 to master
Oleg520 abc5b44
hw3 finished
Oleg520 23885b9
half-working version 4-th hw
Oleg520 6419658
working version 4-th hw
Oleg520 d6c2f81
hw 4 final version
Oleg520 0e73851
crerate branch hw5
Oleg520 780cb05
half-working console app
Oleg520 4544988
hw5 final
Oleg520 b3f7406
внесены правки по замечаниям преподавателя
Oleg520 e9d23c6
homework 6
Oleg520 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -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 added
BIN
+1.11 KB
out/production/hw_java_oop/model/human/comparators/HumanComparatorByAge.class
Binary file not shown.
Binary file added
BIN
+1.2 KB
out/production/hw_java_oop/model/human/comparators/HumanComparatorByBirthDate.class
Binary file not shown.
Binary file added
BIN
+1.16 KB
out/production/hw_java_oop/model/human/comparators/HumanComparatorByName.class
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.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import view.ConsoleUI; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
ConsoleUI consoleUI = new ConsoleUI(); | ||
consoleUI.start(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package model.family_tree; | ||
|
||
import model.human.*; | ||
import model.human.comparators.HumanComparatorByAge; | ||
import model.human.comparators.HumanComparatorByBirthDate; | ||
import model.human.comparators.HumanComparatorByName; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class FamilyTree<E extends FamilyTreeItem<E>> implements Serializable, Iterable<E>{ | ||
private List<E> familyTree; | ||
|
||
public FamilyTree() { | ||
this.familyTree = new ArrayList<>(); | ||
} | ||
|
||
public List<E> getHumans(){ | ||
return familyTree; | ||
} | ||
public void add(E human) { | ||
this.familyTree.add(human); | ||
} | ||
public boolean setWedding(E human1, E human2) { | ||
if (human1.getSpouse() == null && human2.getSpouse() == null) { | ||
human1.setSpouse(human2); | ||
human2.setSpouse(human1); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
public boolean setDivorce(E human1, E human2) { | ||
if (human1.getSpouse() != null && human2.getSpouse() != null) { | ||
human1.setSpouse(null); | ||
human2.setSpouse(null); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
public E findByName(String name) { | ||
for (E human : familyTree) { | ||
if (human.getName().equals(name)) { | ||
return human; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public E findById(int id){ | ||
for(E human : familyTree){ | ||
if (human.getId() == id){ | ||
return human; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public boolean remove(E human) { | ||
if (human != null) { | ||
familyTree.remove(human); | ||
return true; | ||
} | ||
return false; | ||
} | ||
@Override | ||
public String toString() { | ||
return getInfo(); | ||
} | ||
private String getInfo() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("В вашем древе ").append(familyTree.size()).append(" объектов\n"); | ||
for (int i = 0; i < familyTree.size(); i++) { | ||
sb.append(i + 1 + ". " + familyTree.get(i) + "\n"); | ||
} | ||
return sb.toString(); | ||
} | ||
public void sortByName(){ | ||
Collections.sort(familyTree, new HumanComparatorByName<>()); | ||
} | ||
public void sortByAge(){ | ||
Collections.sort(familyTree, new HumanComparatorByAge<>()); | ||
} | ||
public void sortByBirthDate(){ | ||
Collections.sort(familyTree, new HumanComparatorByBirthDate<>()); | ||
} | ||
@Override | ||
public Iterator<E> iterator() { | ||
return new HumanIterator<>(this); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package model.family_tree; | ||
|
||
import java.io.Serializable; | ||
import java.time.LocalDate; | ||
|
||
public interface FamilyTreeItem<E> extends Serializable { | ||
int getAge(); | ||
String getName(); | ||
int getId(); | ||
LocalDate getBirthDate(); | ||
E getSpouse(); | ||
void setSpouse(E human); | ||
boolean addChild(E child); | ||
boolean addParent(E parent); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package model.family_tree; | ||
|
||
import model.human.Human; | ||
import model.human.Gender; | ||
import model.human.HumanBuilder; | ||
import model.writer.FileHandler; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class Service { | ||
private FamilyTree familyTree; | ||
private HumanBuilder humanBuilder; | ||
FileHandler fileHandler; | ||
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<>(); | ||
humanBuilder = new HumanBuilder(); | ||
fileHandler = new FileHandler(); | ||
} | ||
|
||
public void addHuman(String name, Gender gender, LocalDate birthDate) { | ||
Human human = humanBuilder.setName(name).setGender(gender).setBirthDate(birthDate).build(); | ||
familyTree.add(human); | ||
} | ||
|
||
public boolean setWedding(String name1, String name2) { | ||
return familyTree.setWedding(familyTree.findByName(name1), familyTree.findByName(name2)); | ||
} | ||
|
||
public boolean setWedding(int id1, int id2) { | ||
return familyTree.setWedding(familyTree.findById(id1), familyTree.findById(id2)); | ||
} | ||
|
||
public boolean setDivorce(String name1, String name2) { | ||
return familyTree.setDivorce(familyTree.findByName(name1), familyTree.findByName(name2)); | ||
} | ||
|
||
public boolean setDivorce(int id1, int id2) { | ||
return familyTree.setDivorce(familyTree.findById(id1), familyTree.findById(id2)); | ||
} | ||
|
||
public boolean addChild(String human, String child) { | ||
return familyTree.findByName(human).addChild(familyTree.findByName(child)); | ||
} | ||
|
||
public boolean addChild(int idHuman, int idChild) { | ||
return familyTree.findById(idHuman).addChild(familyTree.findById(idChild)); | ||
} | ||
|
||
public boolean addParent(String child, String parent) { | ||
return familyTree.findByName(child).addParent(familyTree.findByName(parent)); | ||
} | ||
|
||
public boolean addParent(int child, int parent) { | ||
return familyTree.findById(child).addParent(familyTree.findById(parent)); | ||
} | ||
|
||
public FamilyTree getFamilyTree() { | ||
return familyTree; | ||
} | ||
|
||
public void sortByName() { | ||
familyTree.sortByName(); | ||
} | ||
|
||
public void sortByAge() { | ||
familyTree.sortByAge(); | ||
} | ||
|
||
public void sortByBirthDate() { | ||
familyTree.sortByBirthDate(); | ||
} | ||
|
||
public boolean saveToFile(String filename) { | ||
fileHandler.setPath(filename); | ||
return fileHandler.save(familyTree); | ||
} | ||
|
||
public boolean loadFromFile(String filePath) { | ||
fileHandler.setPath(filePath); | ||
familyTree = (FamilyTree) fileHandler.read(); | ||
if (familyTree.equals(null)) | ||
return false; | ||
else | ||
return true; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package model.human; | ||
|
||
public enum Gender { | ||
Male, Female; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
надо указать тип дерева