private static final String |
ARRAY_EQUALS_DELTA_ASSOCIATED_ARRAY_KEY |
"$ASSOCIATED_DELTA$" |
private static final String |
ARRAY_EQUALS_DELTA_SORTED_ARRAY_KEY |
"$SORTED_DELTA$" |
private static final String |
ASSOCIATED_TYPE_EXAMPLE_KEY |
"$ASSOCIATED_EXAMPLE$" |
private static final String |
ASSOCIATED_TYPE_KEY |
"$ASSOCIATED_TYPE$" |
private static final String |
CLASS_FEAT |
"}" |
private static final String |
CLASS_HEAD |
"package org.dice_research.topicmodeling.commons.sort;\n\n/**\n * This class is a container for some static functions to sort associative.\n * \n * <b>Note</b> that this class has been generated automatically using the {@link AssociativeSortClassGenerator} class.\n * Do never change the source code in this class because changes could be overwritten by the genrating class. Change the\n * source code of the {@link AssociativeSortClassGenerator} class instead.\n * \n * @author Martin Nettling\n * @author Michael Röder <roeder@informatik.uni-leipzig.de>\n */\npublic class AssociativeSort {\n\n /**\n * Constant defining at which array size quicksort or insertion sort is used.\n\n * This parameter was chosen by making performance tests for arrays of the sizes 50 - 500000 and different\n * parameters in the range 2 - 200.\n */\n public static int MIN_SIZE_FOR_QUICKSORT = 36;\n\n" |
private static final String |
GENERIC_DECLARATION_KEY |
"$GENERIC_TYPE$" |
private static final String |
INSERTION_SORT_METHOD1 |
" /**\n * Insertion sort. The bounds specify which part of the array is to be sorted.<br />\n * <br />\n * Algorithm of O( n\u00b2 ). <br />\n * This version of insertion sort also allows for bounds to be put in to specify what part of the array will be sorted. <br />\n * The part of the array that lies between <b>left</b> and <b>right</b> is the only part that will be sorted.\n * \n * @param A\n * an array of Comparable items.\n * @param Assoc\n * The associative Array\n * @param left\n * the left-most index of the subarray.\n * @param right\n * the right-most index of the subarray.\n * @return A reference to the array that was sorted.\n */\n public static $GENERIC_TYPE$ $SORTED_TYPE$[] insertionSort($SORTED_TYPE$[] A, $ASSOCIATED_TYPE$[] Assoc) {\n return insertionSort(A, Assoc, 0, A.length - 1);\n }\n\n" |
private static final String |
INSERTION_SORT_METHOD2 |
" /**\n * Insertion sort. The bounds specify which part of the array is to be sorted.<br />\n * <br />\n * Algorithm of O( n\u00b2 ). <br />\n * This version of insertion sort also allows for bounds to be put in to specify what part of the array will be sorted. <br />\n * The part of the array that lies between <b>left</b> and <b>right</b> is the only part that will be sorted.\n * \n * @param A\n * an array of Comparable items.\n * @param Assoc\n * The associative Array\n * @param left\n * the left-most index of the subarray.\n * @param right\n * the right-most index of the subarray.\n * @return A reference to the array that was sorted.\n */\n public static $GENERIC_TYPE$ $SORTED_TYPE$[] insertionSort($SORTED_TYPE$[] A, $ASSOCIATED_TYPE$[] Assoc, int left, int right) {\n for (int p = left + 1; p <= right; p++) {\n $SORTED_TYPE$ tmp = A[p];\n $ASSOCIATED_TYPE$ temp = Assoc[p];\n int j;\n for (j = p; j > left && tmp < A[j - 1]; j--) {\n A[j] = A[j - 1];\n Assoc[j] = Assoc[j - 1];\n }\n A[j] = tmp;\n Assoc[j] = temp;\n }\n return A;\n }\n\n" |
private static final String |
PARTITION_METHOD |
" /**\n * Partitions part of an array. <br />\n * The part of the array between <b>left</b> and <b>right</b> will be partitioned around the value held at\n * A[right-1].\n * \n * @param A\n * The array to be partitioned.\n * @param Assoc\n * The associative Array to partitioned\n * @param left\n * The left bound of the array.\n * @param right\n * The right bound of the array.\n * @return The index of the pivot after the partition has occured.\n */\n private static $GENERIC_TYPE$ int partition($SORTED_TYPE$ A[], $ASSOCIATED_TYPE$[] Assoc, int left, int right) {\n int i = left;\n int j = right;\n $SORTED_TYPE$ pivot = A[(left + right) / 2];\n while (i <= j) {\n while (A[i] < pivot)\n i++;\n while (A[j] > pivot)\n j--;\n\n if (i <= j) {\n swap(A, Assoc, i, j);\n i++;\n j--;\n }\n }\n\n return i;\n }\n\n" |
private static final String |
PATH_TO_ASSOCIATIVE_SORT_CLASS_FILE |
"src/main/java/org/dice_research/topicmodeling/commons/sort/AssociativeSort.java" |
private static final String |
PATH_TO_ASSOCIATIVE_SORT_TEST_CLASS_FILE |
"src/test/java/org/dice_research/topicmodeling/commons/sort/AssociativeSortTest.java" |
private static final String |
QUICK_SORT_METHOD1 |
" /**\n * Quicksort for two arrays. The first array will be sorted. All swaps that\n * are done to this array during the sorting will be done to the second,\n * associative array, too. <br />\n * Algorithm of O( n*log(n) ) asymptotic upper bound.\n * \n * @param A\n * The array to be sorted.\n * @param Assoc\n * The Array to sort associative to the given Array A\n * @return A reference to the array that was sorted.\n */\n public static $GENERIC_TYPE$ $SORTED_TYPE$[] quickSort($SORTED_TYPE$[] A, $ASSOCIATED_TYPE$[] Assoc) {\n quickSort(A, Assoc, 0, A.length - 1);\n return A;\n }\n\n" |
private static final String |
QUICK_SORT_METHOD2 |
" /**\n * Quicksort. The bounds specify which part of the array is to be sorted.<br />\n * <br />\n * Algorithm of O( n*log(n) ) asymptotic upper bound. <br />\n * This version of quicksort also allows for bounds to be put in to specify what part of the array will be sorted. <br />\n * The part of the array that lies between <b>left</b> and <b>right</b> is the only part that will be sorted.\n * \n * @param A\n * The array to be sorted.\n * @param Assoc\n * The Array to sort associative to the given Array A\n * @param left\n * The left boundary of what will be sorted.\n * @param right\n * The right boundary of what will be sorted.\n * @return A reference to the array that was sorted.\n */\n public static $GENERIC_TYPE$ $SORTED_TYPE$[] quickSort($SORTED_TYPE$[] A, $ASSOCIATED_TYPE$[] Assoc, int left, int right) {\n if (left + MIN_SIZE_FOR_QUICKSORT <= right) {\n int partitionIndex = partition(A, Assoc, left, right);\n quickSort(A, Assoc, left, partitionIndex - 1);\n quickSort(A, Assoc, partitionIndex, right);\n } else {\n // Do an insertion sort on the subarray\n insertionSort(A, Assoc, left, right);\n }\n return A;\n }\n\n" |
private static final String |
SORTED_TYPE_EXAMPLE_KEY |
"$SORTED_EXAMPLE$" |
private static final String |
SORTED_TYPE_KEY |
"$SORTED_TYPE$" |
private static final String |
SWAP_METHOD |
" /**\n * Swaps the element at index i with element at index j\n * \n * @param A\n * The array to be sorted.\n * @param Assoc\n * The Array to sort associative to the given Array A\n * @param i\n * index of first element\n * @param j\n * index of second element\n */\n public static $GENERIC_TYPE$ void swap($SORTED_TYPE$[] A, $ASSOCIATED_TYPE$[] Assoc, int i, int j) {\n $SORTED_TYPE$ temp = A[i];\n A[i] = A[j];\n A[j] = temp;\n\n $ASSOCIATED_TYPE$ tmp = Assoc[i];\n Assoc[i] = Assoc[j];\n Assoc[j] = tmp;\n }\n\n" |
private static final String |
TEST_CLASS_FEAT |
"}" |
private static final String |
TEST_CLASS_HEAD |
"package org.dice_research.topicmodeling.commons.sort;\n\nimport java.util.Random;\n\nimport org.junit.Assert;\nimport org.junit.Test;\n\n\n/**\n * This class contains JUnit tests for the {@link AssociativeSort} class.\n * \n * <b>Note</b> that this class has been generated automatically using the {@link AssociativeSortClassGenerator} class.\n * Do never change the source code in this class because changes could be overwritten by the genrating class. Change the\n * source code of the {@link AssociativeSortClassGenerator} class instead.\n * \n * @author Michael Röder <roeder@informatik.uni-leipzig.de>\n */\npublic class AssociativeSortTest {\n\n /**\n * Number of swaps which are done to get a random order of the array elements.\n */\n private static final int INITIALE_SWAPS = 5;\n\n /**\n * Used to get a random order of the array elements.\n */\n private Random rand = new Random();\n\n" |
private static final String |
TEST_METHOD |
" @Test\n public void test$TEST_NAME$Sort() {\n $SORTED_TYPE$[] keyArray = $SORTED_EXAMPLE$;\n $ASSOCIATED_TYPE$[] associatedArray = $ASSOCIATED_EXAMPLE$;\n // make some swaps\n for (int i = 0; i < INITIALE_SWAPS; ++i) {\n AssociativeSort.swap(keyArray, associatedArray, rand.nextInt(keyArray.length),\n rand.nextInt(keyArray.length));\n }\n AssociativeSort.quickSort(keyArray, associatedArray);\n Assert.assertArrayEquals(new $SORTED_TYPE$[]$SORTED_EXAMPLE$, keyArray$SORTED_DELTA$);\n Assert.assertArrayEquals(new $ASSOCIATED_TYPE$[]$ASSOCIATED_EXAMPLE$, associatedArray$ASSOCIATED_DELTA$);\n }\n\n" |
private static final String |
TEST_METHOD_NAME_KEY |
"$TEST_NAME$" |