Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. package com.mail.lenka949;
  2.  
  3. import java.util.TreeSet;
  4.  
  5. public class Group {
  6.  
  7. private TreeSet<Student> students = new TreeSet<Student>(new StudentComporator());
  8. private int num = 0;
  9.  
  10. public Group() {
  11. super();
  12. }
  13.  
  14. public void addStudent(Student student) {
  15. students.add(student);
  16. }
  17.  
  18. public void removeStudent(Student student) {
  19. if (students.contains(student)) {
  20. students.remove(student);
  21. } else {
  22. System.out.println("The student is not found in this group");
  23. return;
  24. }
  25. }
  26.  
  27. public Student getStudentByName(String lastName) {
  28. Student st = students.stream().filter(lastName::equals).findFirst().orElse(null);
  29. return st;
  30. }
  31.  
  32. public String genListByChar(char c) {
  33. StringBuffer sb = new StringBuffer();
  34. sb.append("Group:").append(c).append(System.lineSeparator());
  35. students.stream().filter(n -> n.getLastName().charAt(0) == c)
  36. .forEachOrdered(n -> sb.append(getNextNum()).append(n).append(System.lineSeparator()));
  37. this.num = 0;
  38. return sb.toString();
  39. }
  40.  
  41. public Group genGroupByChar(char c) {
  42. Group newGroup = new Group();
  43. students.stream().filter(n -> n.getLastName().charAt(0) == c)
  44. .forEachOrdered(n -> newGroup.addStudent(n));
  45. return newGroup;
  46. }
  47.  
  48. private String getNextNum(){
  49. this.num = num + 1;
  50. return num + ") ";
  51. }
  52.  
  53. @Override
  54. public String toString() {
  55. StringBuffer sb = new StringBuffer();
  56. sb.append("Group:").append(System.lineSeparator());
  57. students.stream().forEachOrdered(n -> sb.append(getNextNum()).append(n).append(System.lineSeparator()));
  58. this.num = 0;
  59. return sb.toString();
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement