import java.util.*;

public class Anagram {

    private final AnagramSubject anagramSubject;

    public Anagram(String word) {
        anagramSubject = new AnagramSubject(word);
    }

    public List<String> match(List<String> candidates) {
        List<String> anagrams = new ArrayList<String>();

        for (String candidate : candidates) {
            if (anagramSubject.anagramOf(candidate)) {
                anagrams.add(candidate);
            }
        }

        return anagrams;
    }

    static final class AnagramSubject {

        private final String word;
        private final char[] fingerprint;

        public AnagramSubject(String other) {
            this.word = other;
            this.fingerprint = canonicalize(other);
        }

        public boolean anagramOf(String other) {
            return !duplicate(other) && Arrays.equals(fingerprint,canonicalize(other));
        }

        private boolean duplicate(String other) {
            return word.equalsIgnoreCase(other);
        }

        private char[] canonicalize(String other) {
            char[] chars = other.toLowerCase().toCharArray();
            Arrays.sort(chars);
            return chars;
        }
    }
}


@@ -14,23 +14,16 @@
 til.*;%0A%0A
-public 
 class An
@@ -30,16 +30,16 @@
 agram %7B%0A
+
 %0A    pri
@@ -81,31 +81,24 @@
 bject;%0A%0A    
-public 
 Anagram(Stri
@@ -166,27 +166,20 @@
 %0A    %7D%0A%0A
+
     
-public 
 List%3CStr
@@ -600,23 +600,16 @@
         
-public 
 AnagramS
@@ -737,15 +737,8 @@
     
-public 
 bool

improve reference solution