55import domain .converter .Row ;
66import domain .ladder .Ladder ;
77import domain .ladder .LinkedType ;
8- import domain .user .ParticipantUsers ;
9- import domain .user .User ;
8+ import domain .ladderCalculator .LadderIO ;
109
1110import java .util .Collections ;
1211import java .util .List ;
1312import java .util .stream .IntStream ;
1413
1514import static view .OutputLine .*;
1615
17- public class OutputView {
18- private ParticipantUsers participantUsers ;
16+ public class OutputLadder {
17+ private LadderIO ladderIO ;
1918 private Ladder ladder ;
2019
21- private OutputView ( ParticipantUsers participantUsers , Ladder ladder ) {
20+ private OutputLadder ( LadderIO ladderIO , Ladder ladder ) {
2221 this .ladder = ladder ;
23- this .participantUsers = participantUsers ;
22+ this .ladderIO = ladderIO ;
2423 }
2524
26- public static OutputView of (ParticipantUsers participantUsers , Ladder ladder ) {
27- return new OutputView ( participantUsers , ladder );
25+ public static OutputLadder of (LadderIO ladderIO , Ladder ladder ) {
26+ return new OutputLadder ( ladderIO , ladder );
2827 }
2928
3029 public void drawOutput () {
@@ -35,6 +34,39 @@ public void drawOutput() {
3534 }
3635 }
3736
37+ public void drawUserNames () {
38+ StringBuilder sb = new StringBuilder ();
39+ for (String user : ladderIO .getUsers ()) {
40+ sb .append (user );
41+ sb .append (calculateBlank (user ));
42+ sb .append (BLANK );
43+ }
44+ System .out .println (sb );
45+ }
46+
47+ public void drawResults () {
48+ StringBuilder sb = new StringBuilder ();
49+ for (String result : ladderIO .getResults ()) {
50+ sb .append (result );
51+ sb .append (calculateBlank (result ));
52+ sb .append (BLANK );
53+ }
54+ System .out .println (sb );
55+ }
56+
57+ public void showLadderResult (String userName ) {
58+ String result = userName .equals ("all" ) ? showAllResult () : ladderIO .findResult (ladder , userName );
59+ System .out .println (result );
60+ }
61+
62+ private String showAllResult () {
63+ StringBuilder sb = new StringBuilder ();
64+ for (String user : ladderIO .getUsers ()) {
65+ sb .append (user + ":" + ladderIO .findResult (ladder , user )+"\n " );
66+ }
67+ return sb .toString ();
68+ }
69+
3870 private void drawRow (Row row ) {
3971 List <Point > points = row .getPoints ();
4072 Collections .sort (points );
@@ -45,30 +77,20 @@ private void drawRow(Row row) {
4577 }
4678
4779 private String drawPoint (Point point ) {
48- int repeat = participantUsers .getUserCharMaxNum ();
80+ int repeat = ladderIO .getUserCharMaxNum ();
4981 return point .isBlankPoint () ? DOWN + widthBlank (repeat ) : Link (point );
5082 }
5183
52- public void drawUserNames () {
53- StringBuilder sb = new StringBuilder ();
54- for (User user : participantUsers .getUsers ()) {
55- sb .append (user .getName ());
56- sb .append (nameBlank (user ));
57- sb .append (BLANK );
58- }
59- System .out .println (sb );
60- }
61-
62- private String nameBlank (User user ) {
63- int width = participantUsers .getUserCharMaxNum () - user .getName ().length ();
84+ private String calculateBlank (String result ) {
85+ int width = ladderIO .getUserCharMaxNum () - result .length ();
6486 StringBuilder sb = new StringBuilder ();
6587 IntStream .range (0 , width )
6688 .forEach (each -> sb .append (BLANK ));
6789 return sb .toString ();
6890 }
6991
7092 private String Link (Point point ) {
71- int repeat = participantUsers .getUserCharMaxNum ();
93+ int repeat = ladderIO .getUserCharMaxNum ();
7294 if (point .getBridge ().getLinkPillarDirection () == LinkedType .RIGHT )
7395 return RIGHT + widthLine (repeat );
7496 return LEFT + widthBlank (repeat );
0 commit comments