@@ -173,7 +173,7 @@ public PriorityQueue<Keystroke> keyStrokes(int maxExpansions) {
173173 PriorityQueue <Keystroke > result = new PriorityQueue <>();
174174 for (Keystroke tail : this .child .keyStrokes (maxExpansions )) {
175175 for (Keystroke stroke : this .keyStrokes ) {
176- result .add (new Keystroke ( stroke . getKey () + tail . getKey (), stroke . getWeight () + tail . getWeight () ));
176+ result .add (Keystroke . concatenate ( stroke , tail ));
177177 if (result .size () > maxExpansions ) {
178178 result .poll (); // Remove highest weight key stroke.
179179 }
@@ -193,9 +193,9 @@ public String keyStroke() {
193193
194194 private static class Keystroke implements Comparable <Keystroke > {
195195 private final String key ;
196- private final Integer weight ;
196+ private final int weight ;
197197
198- public Keystroke (String key , Integer weight ) {
198+ public Keystroke (String key , int weight ) {
199199 this .key = key ;
200200 this .weight = weight ;
201201 }
@@ -204,14 +204,18 @@ public String getKey() {
204204 return this .key ;
205205 }
206206
207- public Integer getWeight () {
207+ public int getWeight () {
208208 return weight ;
209209 }
210210
211211 // Descending order.
212212 @ Override
213213 public int compareTo (Keystroke other ) {
214- return -this .weight .compareTo (other .weight );
214+ return other .weight - this .weight ;
215+ }
216+
217+ public static Keystroke concatenate (Keystroke k1 , Keystroke k2 ) {
218+ return new Keystroke (k1 .getKey () + k2 .getKey (), k1 .getWeight () + k2 .getWeight ());
215219 }
216220 }
217221}
0 commit comments