Fixed Ids were limited to 10. Now it appens a random single digit number

This commit is contained in:
Speiger 2022-05-21 19:36:25 +02:00
parent d4e3da23fa
commit 4a72afdb1c
4 changed files with 28 additions and 9 deletions

View File

@ -5,7 +5,7 @@ repositories {
} }
archivesBaseName = 'Simple Code Generator' archivesBaseName = 'Simple Code Generator'
version = '1.1.0' version = '1.1.1'
apply plugin: 'maven' apply plugin: 'maven'
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {

View File

@ -4,10 +4,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import speiger.src.builder.conditions.ICondition; import speiger.src.builder.conditions.ICondition;
import speiger.src.builder.misc.IdGenerator;
public class ConditionedSegment public class ConditionedSegment
{ {
@ -38,15 +38,15 @@ public class ConditionedSegment
return builder.length() - length; return builder.length() - length;
} }
public static int parse(String fileName, String currentLine, List<String> lines, int currentIndex, int startIndex, AtomicInteger ignoreCounter, List<ConditionedSegment> segments, List<PostSegment> postSegments) throws IllegalStateException public static int parse(String fileName, String currentLine, List<String> lines, int currentIndex, int startIndex, IdGenerator ignoreCounter, List<ConditionedSegment> segments, List<PostSegment> postSegments) throws IllegalStateException
{ {
int ignoreSegmentId = ignoreCounter.get(); String ignoreSegmentId = ignoreCounter.getId();
ConditionedSegment segment = new ConditionedSegment(startIndex); ConditionedSegment segment = new ConditionedSegment(startIndex);
ICondition condition = currentLine == null ? null : ICondition.parse(currentLine); ICondition condition = currentLine == null ? null : ICondition.parse(currentLine);
List<ConditionedSegment> childSegments = new ArrayList<>(); List<ConditionedSegment> childSegments = new ArrayList<>();
StringJoiner segmentText = new StringJoiner("\n", (currentIndex <= 0 || includeStartNewLine(lines.get(currentIndex-1).trim())) ? "\n" : "", ""); StringJoiner segmentText = new StringJoiner("\n", (currentIndex <= 0 || includeStartNewLine(lines.get(currentIndex-1).trim())) ? "\n" : "", "");
if(currentLine == null) { if(currentLine == null) {
lines.set(currentIndex, "#ignoreLine"+ignoreSegmentId); lines.set(currentIndex, ignoreSegmentId);
} }
for(int i = currentIndex+1;i<lines.size();i++) for(int i = currentIndex+1;i<lines.size();i++)
@ -92,7 +92,7 @@ public class ConditionedSegment
else if(trimmed.startsWith("#ignore")) else if(trimmed.startsWith("#ignore"))
{ {
if(currentLine == null) throw new IllegalStateException("#ignore lines can't be applied Recursively"); if(currentLine == null) throw new IllegalStateException("#ignore lines can't be applied Recursively");
ignoreCounter.incrementAndGet(); ignoreCounter.appendId();
int prev = i; int prev = i;
i += parse(fileName, null, lines, i, segmentText.length(), ignoreCounter, childSegments, postSegments); i += parse(fileName, null, lines, i, segmentText.length(), ignoreCounter, childSegments, postSegments);
segmentText.add(lines.get(prev)); segmentText.add(lines.get(prev));

View File

@ -7,10 +7,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicInteger;
import speiger.src.builder.mappers.IMapper; import speiger.src.builder.mappers.IMapper;
import speiger.src.builder.misc.FileUtils; import speiger.src.builder.misc.FileUtils;
import speiger.src.builder.misc.IdGenerator;
public class Template public class Template
{ {
@ -66,7 +66,7 @@ public class Template
public static Template parse(Path file) throws IOException public static Template parse(Path file) throws IOException
{ {
String fileName = FileUtils.getFileName(file.getFileName()); String fileName = FileUtils.getFileName(file.getFileName());
AtomicInteger segmentIds = new AtomicInteger(); IdGenerator segmentIds = new IdGenerator();
List<ConditionedSegment> segments = new ArrayList<>(); List<ConditionedSegment> segments = new ArrayList<>();
List<PostSegment> postSegments = new ArrayList<>(); List<PostSegment> postSegments = new ArrayList<>();
StringJoiner joiner = new StringJoiner("\n"); StringJoiner joiner = new StringJoiner("\n");
@ -84,7 +84,7 @@ public class Template
} }
else if(trimmed.startsWith("#ignore")) else if(trimmed.startsWith("#ignore"))
{ {
segmentIds.getAndIncrement(); segmentIds.appendId();
int prev = i; int prev = i;
i += ConditionedSegment.parse(fileName, null, lines, i, joiner.length(), segmentIds, segments, postSegments); i += ConditionedSegment.parse(fileName, null, lines, i, joiner.length(), segmentIds, segments, postSegments);
joiner.add(lines.get(prev)); joiner.add(lines.get(prev));

View File

@ -0,0 +1,19 @@
package speiger.src.builder.misc;
import java.util.Random;
public class IdGenerator
{
StringBuilder builder = new StringBuilder();
Random rand = new Random(24912012592L);
public void appendId()
{
builder.insert(0, rand.nextInt(10));
}
public String getId()
{
return "#ignoreLine"+builder.toString();
}
}