class AssociativeSortClassGenerator extends Object
AssociativeSort and
AssociativeSortTest containing the JUnit tests for the
AssociativeSort class. It should only be run if these classes should
be changed.| Modifier and Type | Field and Description |
|---|---|
private static String |
ARRAY_EQUALS_DELTA_ASSOCIATED_ARRAY_KEY
Defining the String which will be replaced with the delta which is needed
to compare double or float values of the associated array in the JUnit
tests (or an empty String if the type of the associated array is not
double or float).
|
private static String |
ARRAY_EQUALS_DELTA_SORTED_ARRAY_KEY
Defining the String which will be replaced with the delta which is needed
to compare double or float values of the sorted array in the JUnit tests
(or an empty String if the type of the sorted array is not double or
float).
|
private static String |
ASSOCIATED_TYPE_EXAMPLE_KEY
Defining the String which will be replaced with the example array for the
associated array.
|
private static String |
ASSOCIATED_TYPE_KEY
Defining the String which will be replaced with the type of the
associated array.
|
private static String[] |
associatedTypes
Defining the types the associated array can have.
|
private static String |
CLASS_FEAT
String defining the feet of the
AssociativeSort class. |
private static String |
CLASS_HEAD
Head of the
AssociativeSort class. |
private static HashMap<String,String> |
exampleArrays
Defining the sorted example arrays used for the JUnit tests.
|
private static String |
GENERIC_DECLARATION_KEY
Defining the String which will be replaced with the generic type
declaration (or with an empty String if the generic type declaration is
not needed).
|
private static String |
INSERTION_SORT_METHOD1
String defining the insertion sort.
|
private static String |
INSERTION_SORT_METHOD2
String defining the insertion sort.
|
private static String |
PARTITION_METHOD
String defining the partitioning method
|
private static String |
PATH_TO_ASSOCIATIVE_SORT_CLASS_FILE
The path to the .java file of the
AssociativeSort class. |
private static String |
PATH_TO_ASSOCIATIVE_SORT_TEST_CLASS_FILE
The path to the .java file of the JUnit test class AssociativeSortTest.
|
private static String[] |
primitiveSortTypes
Defining the types the sorted array can have.
|
private static String |
QUICK_SORT_METHOD1
String defining the quick sort method
|
private static String |
QUICK_SORT_METHOD2
String defining the quick sort method
|
private static String |
SORTED_TYPE_EXAMPLE_KEY
Defining the String which will be replaced with the example array for the
sorted array.
|
private static String |
SORTED_TYPE_KEY
Defining the String which will be replaced with the type of the sorted
array.
|
private static String |
SWAP_METHOD
String defining the swap method
|
private static String |
TEST_CLASS_FEAT
String defining the feet of the
AssociativeSortTest class. |
private static String |
TEST_CLASS_HEAD
Head of the
AssociativeSortTest class. |
private static String |
TEST_METHOD
String defining the JUnit test method.
|
private static String |
TEST_METHOD_NAME_KEY
Defining the String which will be replaced with the name of the test
method.
|
private FileWriter |
writer
FileWriter used for creating the files.
|
| Constructor and Description |
|---|
AssociativeSortClassGenerator() |
| Modifier and Type | Method and Description |
|---|---|
private String |
getArrayDelta(String type)
Returns a String defining a delta for the equal assertion of the JUnit
tests if the given type is double or float.
|
static void |
main(String[] args)
Starts the generation.
|
private void |
prepareFile(File file) |
private void |
writeAssociativeSortClasses(String[] primitiveSortTypes,
String[] associatedTypes,
HashMap<String,String> exampleArrays)
This method writes the two classes.
|
private void |
writeMethod(String method,
String sortedType,
String associatedType,
String genericDeclaration)
Method which writes the given method replacing the
SORTED_TYPE_KEY, the ASSOCIATED_TYPE_KEY, and the
GENERIC_DECLARATION_KEY using the given values. |
private void |
writeMethods(String[] primitiveSortTypes,
String[] associatedTypes)
This method writes the methods of the
AssociativeSort class for
the combinations of the given types. |
private void |
writeMethods(String sortedType,
String associatedType)
Writes the methods for a given type pair.
|
private void |
writeMethods(String sortedType,
String associatedType,
String genericDeclaration)
Writes the methods for a given type pair using the given generic
declaration.
|
private void |
writeTestMethod(String sortedType,
String sortedTypeExample,
String associatedType,
String associatedTypeExample)
writes the test method for a single combination of a sorted array type
and an associated array type.
|
private void |
writeTestMethods(String[] primitiveSortTypes,
String[] associatedTypes,
HashMap<String,String> exampleArrays)
This method writes the test methods for the combinations of the given
example arrays and the types of the sorted and the associated array.
|
private static final String PATH_TO_ASSOCIATIVE_SORT_CLASS_FILE
AssociativeSort class.private static final String PATH_TO_ASSOCIATIVE_SORT_TEST_CLASS_FILE
private static final String SORTED_TYPE_KEY
private static final String ASSOCIATED_TYPE_KEY
private static final String GENERIC_DECLARATION_KEY
private static final String TEST_METHOD_NAME_KEY
private static final String ARRAY_EQUALS_DELTA_SORTED_ARRAY_KEY
private static final String ARRAY_EQUALS_DELTA_ASSOCIATED_ARRAY_KEY
private static final String SORTED_TYPE_EXAMPLE_KEY
private static final String ASSOCIATED_TYPE_EXAMPLE_KEY
private static final String[] primitiveSortTypes
private static final String[] associatedTypes
private static final HashMap<String,String> exampleArrays
private FileWriter writer
private static final String CLASS_HEAD
AssociativeSort class.private static final String SWAP_METHOD
private static final String QUICK_SORT_METHOD1
private static final String QUICK_SORT_METHOD2
private static final String PARTITION_METHOD
private static final String INSERTION_SORT_METHOD1
private static final String INSERTION_SORT_METHOD2
private static final String CLASS_FEAT
AssociativeSort class.private static final String TEST_CLASS_HEAD
AssociativeSortTest class.private static final String TEST_METHOD
private static final String TEST_CLASS_FEAT
AssociativeSortTest class.public static void main(String[] args)
args - private void writeAssociativeSortClasses(String[] primitiveSortTypes, String[] associatedTypes, HashMap<String,String> exampleArrays) throws IOException
primitiveSortTypes - array containing the types for the sorted arrayassociatedTypes - array containing the types for the associated arrayexampleArrays - Map containing the types and their example arraysIOException - thrown by the used writerprivate void prepareFile(File file)
private void writeMethods(String[] primitiveSortTypes, String[] associatedTypes) throws IOException
AssociativeSort class for
the combinations of the given types. Additionally for every sorted type
methods for a generic associated type are generated.primitiveSortTypes - types the sorted arrays can haveassociatedTypes - types the associated arrays can haveIOExceptionprivate void writeMethods(String sortedType, String associatedType) throws IOException
sortedType - type the sorted array can haveassociatedType - types the associated array can haveIOExceptionprivate void writeMethods(String sortedType, String associatedType, String genericDeclaration) throws IOException
sortedType - type the sorted array can haveassociatedType - types the associated array can havegenericDeclaration - String declaring a generic or an empty StringIOExceptionprivate void writeMethod(String method, String sortedType, String associatedType, String genericDeclaration) throws IOException
SORTED_TYPE_KEY, the ASSOCIATED_TYPE_KEY, and the
GENERIC_DECLARATION_KEY using the given values.method - method which should be writtensortedType - type of the sorted array which should be inserted into the
methodassociatedType - type of the associated array which should be inserted into the
methodgenericDeclaration - generic type declaration which should be inserted into the
methodIOExceptionprivate void writeTestMethods(String[] primitiveSortTypes, String[] associatedTypes, HashMap<String,String> exampleArrays) throws IOException
primitiveSortTypes - types of the sorted arraysassociatedTypes - types of the associated arraysexampleArrays - examples for the different array typesIOExceptionprivate void writeTestMethod(String sortedType, String sortedTypeExample, String associatedType, String associatedTypeExample) throws IOException
sortedType - type of the sorted arraysortedTypeExample - already sorted example of the sorted array typeassociatedType - type of the associated arrayassociatedTypeExample - example of the associated array typeIOExceptionCopyright © 2015–2020. All rights reserved.