From 4a72afdb1c15e4681b07775faedbf3f664fc8bc7 Mon Sep 17 00:00:00 2001 From: Speiger Date: Sat, 21 May 2022 19:36:25 +0200 Subject: [PATCH] Fixed Ids were limited to 10. Now it appens a random single digit number --- build.gradle | 2 +- .../src/builder/base/ConditionedSegment.java | 10 +++++----- .../speiger/src/builder/base/Template.java | 6 +++--- .../speiger/src/builder/misc/IdGenerator.java | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/main/java/speiger/src/builder/misc/IdGenerator.java diff --git a/build.gradle b/build.gradle index 96a03bd..4db1638 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ repositories { } archivesBaseName = 'Simple Code Generator' -version = '1.1.0' +version = '1.1.1' apply plugin: 'maven' tasks.withType(JavaCompile) { diff --git a/src/main/java/speiger/src/builder/base/ConditionedSegment.java b/src/main/java/speiger/src/builder/base/ConditionedSegment.java index 6a6c5f3..e832c8f 100644 --- a/src/main/java/speiger/src/builder/base/ConditionedSegment.java +++ b/src/main/java/speiger/src/builder/base/ConditionedSegment.java @@ -4,10 +4,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.StringJoiner; -import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import speiger.src.builder.conditions.ICondition; +import speiger.src.builder.misc.IdGenerator; public class ConditionedSegment { @@ -38,15 +38,15 @@ public class ConditionedSegment return builder.length() - length; } - public static int parse(String fileName, String currentLine, List lines, int currentIndex, int startIndex, AtomicInteger ignoreCounter, List segments, List postSegments) throws IllegalStateException + public static int parse(String fileName, String currentLine, List lines, int currentIndex, int startIndex, IdGenerator ignoreCounter, List segments, List postSegments) throws IllegalStateException { - int ignoreSegmentId = ignoreCounter.get(); + String ignoreSegmentId = ignoreCounter.getId(); ConditionedSegment segment = new ConditionedSegment(startIndex); ICondition condition = currentLine == null ? null : ICondition.parse(currentLine); List childSegments = new ArrayList<>(); StringJoiner segmentText = new StringJoiner("\n", (currentIndex <= 0 || includeStartNewLine(lines.get(currentIndex-1).trim())) ? "\n" : "", ""); if(currentLine == null) { - lines.set(currentIndex, "#ignoreLine"+ignoreSegmentId); + lines.set(currentIndex, ignoreSegmentId); } for(int i = currentIndex+1;i segments = new ArrayList<>(); List postSegments = new ArrayList<>(); StringJoiner joiner = new StringJoiner("\n"); @@ -84,7 +84,7 @@ public class Template } else if(trimmed.startsWith("#ignore")) { - segmentIds.getAndIncrement(); + segmentIds.appendId(); int prev = i; i += ConditionedSegment.parse(fileName, null, lines, i, joiner.length(), segmentIds, segments, postSegments); joiner.add(lines.get(prev)); diff --git a/src/main/java/speiger/src/builder/misc/IdGenerator.java b/src/main/java/speiger/src/builder/misc/IdGenerator.java new file mode 100644 index 0000000..62bb44d --- /dev/null +++ b/src/main/java/speiger/src/builder/misc/IdGenerator.java @@ -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(); + } +}