2 Commits

Author SHA1 Message Date
Fabian Holzwarth
7442880452 feat: limit placeholder generation to uppercase chars 2025-05-18 13:24:29 +02:00
Fabian Holzwarth
c4dc3b4245 feat: replace random based placeholder generation with deterministic approach 2025-05-18 12:41:56 +02:00

View File

@@ -25,15 +25,9 @@ public final class PlaceholderType extends UnifyType{
*/ */
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>(); public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
/**
* Prefix of auto-generated placeholder names.
*/
protected static String nextName = "gen_";
/** private static final char[] PLACEHOLDER_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
* Random number generator used to generate fresh placeholder name. private static int placeholderCount = 0;
*/
protected static Random rnd = new Random(43558747548978L);
/** /**
* True if this object was auto-generated, false if this object was user-generated. * True if this object was auto-generated, false if this object was user-generated.
@@ -100,16 +94,24 @@ public final class PlaceholderType extends UnifyType{
} }
/** /**
* Creates a fresh placeholder type with a name that does so far not exist. * Creates a fresh placeholder type with a name that does so far not exist from the chars A-Z.
* A user could later instantiate a type using the same name that is equivalent to this type. * A user could later instantiate a type using the same name that is equivalent to this type.
* @return A fresh placeholder type. * @return A fresh placeholder type.
*/ */
public synchronized static PlaceholderType freshPlaceholder() { public synchronized static PlaceholderType freshPlaceholder() {
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' String name;
// Add random chars while the name is in use. do {
while(EXISTING_PLACEHOLDERS.contains(name)) { int pc = PlaceholderType.placeholderCount++;
name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
StringBuilder sb = new StringBuilder();
while (pc >= 0) {
sb.insert(0, PLACEHOLDER_CHARS[pc % 26]);
pc = pc / 26 - 1;
}
name = sb.toString();
} }
while (EXISTING_PLACEHOLDERS.contains(name));
return new PlaceholderType(name, true); return new PlaceholderType(name, true);
} }