-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cobol structure generator tool
- Loading branch information
1 parent
4631bae
commit 2820e4e
Showing
3 changed files
with
124 additions
and
25 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...ools/src/main/java/gutta/apievolution/tools/generator/CobolBenchmarkStructsGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package gutta.apievolution.tools.generator; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Writer; | ||
|
||
public class CobolBenchmarkStructsGenerator { | ||
|
||
public static void main(String[] arguments) throws IOException { | ||
String mode = arguments[0]; | ||
int numberOfElements = Integer.parseInt(arguments[1]); | ||
|
||
try (Writer outputWriter = new OutputStreamWriter(System.out)) { | ||
GeneratorMode generatorMode = createGeneratorMode(mode, outputWriter); | ||
generatorMode.generateCode(numberOfElements); | ||
} | ||
} | ||
|
||
private static GeneratorMode createGeneratorMode(String mode, Writer outputWriter) { | ||
String normalizedMode = mode.toLowerCase(); | ||
|
||
switch (normalizedMode) { | ||
case "structure": | ||
return new StructureGeneratorMode(outputWriter); | ||
|
||
case "initializer": | ||
return new InitializationGeneratorMode(outputWriter); | ||
|
||
default: | ||
throw new IllegalArgumentException("Unsupported mode '" + mode + "'."); | ||
} | ||
} | ||
|
||
private static class StructureGeneratorMode extends GeneratorMode { | ||
|
||
public StructureGeneratorMode(Writer outputWriter) { | ||
super(outputWriter); | ||
} | ||
|
||
@Override | ||
public void generateCode(int numberOfElements) { | ||
this.writeLine(" * Test structure with " + numberOfElements + " elements"); | ||
this.writeLine(" 05 '*-'TEST-STRUCT-" + numberOfElements + "."); | ||
|
||
for (int elementIndex = 1; elementIndex <= numberOfElements; elementIndex++) { | ||
this.writeLine(" 10 '*-'INT-FIELD-" + elementIndex + "-FLAGS PIC 9 BINARY."); | ||
this.writeLine(" 88 VALUE-ABSENT VALUE 0."); | ||
this.writeLine(" 88 VALUE-PRESENT VALUE 1."); | ||
this.writeLine(" 88 VALUE-UNREPRESENTABLE VALUE 2."); | ||
this.writeLine(" 10 '*-'INT-FIELD-" + elementIndex + " PIC S9(9) BINARY."); | ||
this.writeLine(""); | ||
} | ||
|
||
for (int elementIndex = 1; elementIndex <= numberOfElements; elementIndex++) { | ||
this.writeLine(" 10 '*-'STRING-FIELD-" + elementIndex + "-FLAGS PIC 9 BINARY."); | ||
this.writeLine(" 88 VALUE-ABSENT VALUE 0."); | ||
this.writeLine(" 88 VALUE-PRESENT VALUE 1."); | ||
this.writeLine(" 88 VALUE-UNREPRESENTABLE VALUE 2."); | ||
this.writeLine(" 10 '*-'STRING-FIELD-" + elementIndex + " PIC X(10)."); | ||
this.writeLine(""); | ||
} | ||
} | ||
} | ||
|
||
private static class InitializationGeneratorMode extends GeneratorMode { | ||
|
||
public InitializationGeneratorMode(Writer outputWriter) { | ||
super(outputWriter); | ||
} | ||
|
||
@Override | ||
public void generateCode(int numberOfElements) { | ||
for (int elementIndex = 1; elementIndex <= numberOfElements; elementIndex++) { | ||
String currentFieldName = "C" + numberOfElements + "-INT-FIELD-" + elementIndex; | ||
|
||
this.writeLine(" SET VALUE-PRESENT IN " + currentFieldName + "-FLAGS"); | ||
this.writeLine(" TO TRUE"); | ||
this.writeLine(" MOVE " + elementIndex); | ||
this.writeLine(" TO " + currentFieldName); | ||
} | ||
|
||
this.writeLine(""); | ||
|
||
for (int elementIndex = 1; elementIndex <= numberOfElements; elementIndex++) { | ||
String currentFieldName = "C" + numberOfElements + "-STRING-FIELD-" + elementIndex; | ||
|
||
this.writeLine(" SET VALUE-PRESENT IN " + currentFieldName + "-FLAGS"); | ||
this.writeLine(" TO TRUE"); | ||
this.writeLine(" MOVE '" + elementIndex + "'"); | ||
this.writeLine(" TO " + currentFieldName); | ||
} | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
gutta-apievolution-tools/src/main/java/gutta/apievolution/tools/generator/GeneratorMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gutta.apievolution.tools.generator; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
abstract class GeneratorMode { | ||
|
||
protected final Writer outputWriter; | ||
|
||
protected GeneratorMode(Writer outputWriter) { | ||
this.outputWriter = outputWriter; | ||
} | ||
|
||
protected void write(String output) { | ||
try { | ||
this.outputWriter.write(output); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error writing output line.", e); | ||
} | ||
} | ||
|
||
protected void writeLine(String line) { | ||
this.write(line + "\n"); | ||
} | ||
|
||
public abstract void generateCode(int numberOfElements); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters