@@ -0,0 +1,2802 @@
+/**%0D%0A *%0D%0A *The MIT License (MIT)%0D%0A *%0D%0A *Copyright (c) 2014 Abhijit Kumar%0D%0A *%0D%0A *Permission is hereby granted, free of charge, to any person obtaining a copy%0D%0A *of this software and associated documentation files (the %22Software%22), to deal%0D%0A *in the Software without restriction, including without limitation the rights%0D%0A *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0D%0A *copies of the Software, and to permit persons to whom the Software is%0D%0A *furnished to do so, subject to the following conditions:%0D%0A *%0D%0A *The above copyright notice and this permission notice shall be included in all%0D%0A *copies or substantial portions of the Software.%0D%0A *%0D%0A *THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0D%0A *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0D%0A *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0D%0A *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0D%0A *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0D%0A *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0D%0A *SOFTWARE.%0D%0A *%0D%0A **/%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0A%0D%0A/**%0D%0A * Compute all possible anagrams/permutations of given String (sequence of characters)%0D%0A * @author abhijitkumar2003%5Bat%5Dgmail%5Bdot%5Dcom%0D%0A *%0D%0A */%0D%0Apublic class Permutations %7B%0D%0A    private boolean%5B%5D used;%0D%0A    private StringBuilder out = new StringBuilder();%0D%0A    private String in;%0D%0A    %0D%0A    /**%0D%0A     * Calculate all permutations of given String.%0D%0A     * @param str%0D%0A     * @return List of permutations of str%0D%0A     */%0D%0A    public ArrayList%3CString%3E getPermutations(final String str) %7B%0D%0A    %09in = str;%0D%0A        used = new boolean%5B in.length() %5D;%0D%0A        ArrayList%3CString%3E permutations = new ArrayList%3CString%3E();%0D%0A        permute(permutations);%0D%0A        return permutations;%0D%0A    %7D%0D%0A    %0D%0A    /**%0D%0A     * Calculate all permutations. Logic is:%0D%0A     * (Fix 1 character at a time)%0D%0A     * Fix first element and shuffle remaining characters%0D%0A     * Fix second element and shuffle remaining characters%0D%0A     * (.. and so on)%0D%0A     * (Fix 2 characters at a time)%0D%0A     * Fix first 2 characters and shuffle others%0D%0A     * Fix next 2 characters and shuffle others%0D%0A     * (.. and so on)%0D%0A     * (Fix 3 characters and so on, shuffle others)%0D%0A     * @param permuted%0D%0A     */%0D%0A%09private void permute(ArrayList%3CString%3E permuted) %7B%0D%0A%09%09if (out.length() == in.length()) %7B%0D%0A%09%09%09permuted.add(out.toString());%0D%0A%09%09%09return;%0D%0A%09%09%7D%0D%0A%09%09for (int i = 0; i %3C in.length(); ++i) %7B%0D%0A%09%09%09if (used%5Bi%5D)%0D%0A%09%09%09%09continue; // skip fixed character%0D%0A%09%09%09out.append(in.charAt(i));%0D%0A%09%09%09used%5Bi%5D = true; // fix seen character%0D%0A%09%09%09permute(permuted);%0D%0A%09%09%09used%5Bi%5D = false;// make this available for shuffle%0D%0A%09%09%09out.setLength(out.length() - 1);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%7D

Anagram calculator. Permutations generator.