fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.util.stream.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. // Populate
  15.  
  16. Team alphaTeam = new Team(
  17. UUID.fromString( "b4c94867-8ac7-4caf-bf49-b79df92cff82" ) ,
  18. "Alpha",
  19. List.of(
  20. new Member(
  21. 1 ,
  22. "Alice",
  23. Member.Status.ACTIVE
  24. ),
  25. new Member(
  26. 2 ,
  27. "Bob",
  28. Member.Status.ACTIVE
  29. )
  30. )
  31. );
  32.  
  33. Team betaTeam = new Team(
  34. UUID.fromString( "9d12160a-94cc-45c6-a465-12cdf3d1a503" ) ,
  35. "Beta",
  36. List.of(
  37. new Member(
  38. 3,
  39. "Carol",
  40. Member.Status.INACTIVE
  41. ),
  42. new Member(
  43. 4,
  44. "Davis",
  45. Member.Status.ACTIVE
  46. )
  47. )
  48. );
  49.  
  50. Team gammaTeam = new Team(
  51. UUID.fromString( "f440ac2d-9175-47d8-a5e2-3102e0d162bc" ) ,
  52. "Gamma",
  53. List.of(
  54. new Member(
  55. 5 ,
  56. "Ernestine",
  57. Member.Status.ACTIVE
  58. ),
  59. new Member(
  60. 6 ,
  61. "Frank",
  62. Member.Status.ACTIVE
  63. )
  64. )
  65. );
  66.  
  67. List < Team > teams = List.of( alphaTeam , betaTeam , gammaTeam );
  68.  
  69. // Report
  70. List<Team> teamsWhoseMembershipIsEntirelyActive =
  71. teams
  72. .stream()
  73. .filter(
  74. team -> team.memberList().stream().allMatch( member -> member.status().equals( Member.Status.ACTIVE ) )
  75. )
  76. .collect( Collectors.toList() );
  77. ;
  78.  
  79. System.out.println( "teamsWhoseMembershipIsEntirelyActive = " + teamsWhoseMembershipIsEntirelyActive );
  80. }
  81. }
  82.  
  83. final class Member {
  84. private final int id;
  85. private final String name;
  86. private final Status status;
  87.  
  88. public Member ( int id , String name , Status status ) {
  89. this.id = id;
  90. this.name = name;
  91. this.status = status;
  92. }
  93.  
  94. public int id () { return id; }
  95.  
  96. public String name () { return name; }
  97.  
  98. public Status status () { return status; }
  99.  
  100. @Override
  101. public boolean equals ( Object obj ) {
  102. if ( obj == this ) return true;
  103. if ( obj == null || obj.getClass() != this.getClass() ) return false;
  104. var that = ( Member ) obj;
  105. return this.id == that.id && Objects.equals( this.name , that.name ) && Objects.equals( this.status , that.status );
  106. }
  107.  
  108. @Override
  109. public int hashCode () {
  110. return Objects.hash( id , name , status );
  111. }
  112.  
  113. @Override
  114. public String toString () {
  115. return "Member[" + "id=" + id + ", " + "name=" + name + ", " + "status=" + status + ']';
  116. }
  117.  
  118. public enum Status {
  119. ACTIVE,
  120. INACTIVE,
  121. }
  122. }
  123.  
  124.  
  125. final class Team {
  126. private final UUID id;
  127. private final String name;
  128. private final List < Member > memberList;
  129.  
  130. public Team ( UUID id , String name , List < Member > memberList ) {
  131. this.id = id;
  132. this.name = name;
  133. this.memberList = memberList;
  134. }
  135.  
  136. public UUID id () { return id; }
  137.  
  138. public String name () { return name; }
  139.  
  140. public List < Member > memberList () { return memberList; }
  141.  
  142. @Override
  143. public boolean equals ( Object obj ) {
  144. if ( obj == this ) return true;
  145. if ( obj == null || obj.getClass() != this.getClass() ) return false;
  146. var that = ( Team ) obj;
  147. return Objects.equals( this.id , that.id ) && Objects.equals( this.name , that.name ) && Objects.equals( this.memberList , that.memberList );
  148. }
  149.  
  150. @Override
  151. public int hashCode () {
  152. return Objects.hash( id , name , memberList );
  153. }
  154.  
  155. @Override
  156. public String toString () {
  157. return "Team[" + "id=" + id + ", " + "name=" + name + ", " + "memberList=" + memberList + ']';
  158. }
  159. }
  160.  
Success #stdin #stdout 0.22s 56288KB
stdin
Standard input is empty
stdout
teamsWhoseMembershipIsEntirelyActive = [Team[id=b4c94867-8ac7-4caf-bf49-b79df92cff82, name=Alpha, memberList=[Member[id=1, name=Alice, status=ACTIVE], Member[id=2, name=Bob, status=ACTIVE]]], Team[id=f440ac2d-9175-47d8-a5e2-3102e0d162bc, name=Gamma, memberList=[Member[id=5, name=Ernestine, status=ACTIVE], Member[id=6, name=Frank, status=ACTIVE]]]]