44import java .util .Collection ;
55import java .util .HashSet ;
66import java .util .List ;
7- import java .util .Map ;
87import java .util .Queue ;
8+ import java .util .StringJoiner ;
9+ import java .util .Arrays ;
10+ import java .util .stream .Collector ;
911import java .util .stream .Collectors ;
12+ import java .util .stream .IntStream ;
1013
1114/**
1215<b>
1316Purpose: Requirement to be a node for evaluation purposes.<br>
14- Programmer: Gabriel Toban Harris, Alexander Herman Oxorn
17+ Programmer: Gabriel Toban Harris, Alexander Oxorn
1518</b>
1619*/
1720
@@ -59,7 +62,7 @@ interface RollbackCallback {
5962
6063 /**
6164 * Constructor to force unified id among all subclasses.
62- *
65+ *
6366 * @param NAME {@link #NAME}
6467 */
6568 public Evaluable (final String NAME )
@@ -70,9 +73,9 @@ public Evaluable(final String NAME)
7073
7174 /**
7275 * Output whole tree in dot file format.
73- *
76+ *
7477 * @param START of breath first search
75- *
78+ *
7679 * @return representation of whole structure in dot file format
7780 */
7881 public static String print_whole_subtree (final Evaluable START )
@@ -102,11 +105,11 @@ public static String print_whole_subtree(final Evaluable START)
102105
103106 /**
104107 * Allows for hand to be in an arbitrary order. Default entry point where the success callback returns true and the failure callback returns false
105- *
108+ *
106109 * @param <E> anything that is {@link Reservable} will do
107110 *
108111 * @param hand to be checked {@link Collection}
109- *
112+ *
110113 * @return If the hand meets a condition
111114 */
112115 public <E extends Reservable > boolean evaluate (final Collection <E > hand )
@@ -139,6 +142,51 @@ protected Collection<? extends Evaluable> continue_breath_search()
139142 throw new UnsupportedOperationException ("Child failed to override me." );
140143 }
141144
145+
146+ /**
147+ * @return a {@link List} of two {@link StringJoiner}s with ", " delimiter and [ ] prefix and suffix
148+ */
149+ private static List <StringJoiner > StringJoinerListGenerator () {
150+ return Arrays .asList (
151+ new StringJoiner (", " , "[" , "]" ),
152+ new StringJoiner (", " , "[" , "]" )
153+ );
154+ }
155+
156+ /**
157+ * Takes a {@link Reservable} and adds it to the first {@link StringJoiner} if its reserved and the second
158+ * otherwise
159+ *
160+ * @param partialSum the current state of the two StringJoiners
161+ * @param nextElement the next Reservable to add to the StringJoiner
162+ */
163+ private static void StringJoinerListPartialAdder (List <StringJoiner > partialSum , Reservable nextElement ) {
164+ partialSum .get (nextElement .isReserved () ? 0 : 1 ).add (nextElement .toString ());
165+ }
166+
167+ /**
168+ * Takes two {@link List}s of {@link StringJoiner}s and merges them together index wise
169+ *
170+ * @param partialSum1 List of StringJoiner to be merged to
171+ * @param partialSum2 List of StringJoiner to be merged with
172+ * @return partialSum1 after having their elements be merged with partialSum2's
173+ */
174+ private static List <StringJoiner > StringJoinerListJoiner (List <StringJoiner > partialSum1 , List <StringJoiner > partialSum2 ) {
175+ partialSum1 .get (0 ).merge (partialSum2 .get (0 ));
176+ partialSum1 .get (1 ).merge (partialSum2 .get (1 ));
177+ return partialSum1 ;
178+ }
179+
180+ /**
181+ * Takes a {@link List} of {@link StringJoiner}s returns a {@link List} of their final {@link String}
182+ *
183+ * @param finalSum StringJoiner after all of the elements have been added
184+ * @return The {@link String} representing the joined elements
185+ */
186+ private static List <String > StringJoinerToStringList (List <StringJoiner > finalSum ) {
187+ return finalSum .stream ().map (StringJoiner ::toString ).collect (Collectors .toList ());
188+ }
189+
142190 /**
143191 * If debugMode is set, print current debug details about the currently executing node
144192 *
@@ -147,10 +195,15 @@ protected Collection<? extends Evaluable> continue_breath_search()
147195 <E extends Reservable > void printDebugStep (final Collection <E > hand )
148196 {
149197 if (debugMode ) {
150- System .out .printf ("%s " , this );
151- Map <Boolean , List <E >> hand_partition = hand .stream ().collect (Collectors .partitioningBy (Reservable ::isReserved ));
152- System .out .printf ("Used Cards: [%s] " , hand_partition .get (true ).stream ().map (Object ::toString ).collect (Collectors .joining ("," )));
153- System .out .printf ("Unused Cards: [%s]\n " , hand_partition .get (false ).stream ().map (Object ::toString ).collect (Collectors .joining ("," )));
198+ System .out .print (this + " " );
199+ List <String > usedAndUnusedCards = hand .stream ().collect (Collector .of (
200+ Evaluable ::StringJoinerListGenerator ,
201+ Evaluable ::StringJoinerListPartialAdder ,
202+ Evaluable ::StringJoinerListJoiner ,
203+ Evaluable ::StringJoinerToStringList
204+ ));
205+ System .out .printf ("Used Cards: %s " , usedAndUnusedCards .get (0 ));
206+ System .out .printf ("Unused Cards: %s\n " , usedAndUnusedCards .get (1 ));
154207 }
155208 }
156209}
0 commit comments