#How to stop this being cursed
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
What exactly is your question?
If you use a LinkedHashSet, that is for a reason. It has an order.
If you dont need an order you can also simply use a HashSet
for a password generator you could simply do
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+"
and just get a random character
Make it all in a normal class, then make singleton static
i have no idea why you would want to do this
you can just "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+"
and if you need a random character use Random or ThreadLocalRandom to get a random number then just string.charAt(randomNumber)
maybe a configurable password generator like this
to support utf8 range and not just ascii.
passwords usually don't need more than ascii?
especially if a program generates them
I did this as a prototype but I need to make it extensible 
For others: I used a Singleton pattern
package com.cdev;
import java.util.*;
public final class CharacterSetManager {
private static final CharacterSetManager INSTANCE = new CharacterSetManager();
private final Map<Sets, Set<Character>> characterSets;
public enum Sets {
LOWERCASE,
UPPERCASE,
DIGITS,
SPECIAL
}
private CharacterSetManager() {
Map<Sets, Set<Character>> modifiableMap = new EnumMap<>(Sets.class);
Set<Character> lowercase = new LinkedHashSet<>();
Set<Character> uppercase = new LinkedHashSet<>();
Set<Character> digits = new LinkedHashSet<>();
Set<Character> specialCharacters = new LinkedHashSet<>(List.of('!', '#', '-', '$', '&'));
// populate sets
for (char c = 'a'; c <= 'z'; c++) {
lowercase.add(c);
uppercase.add(Character.toUpperCase(c));
}
for(char c = '0'; c <= '9'; c++) {
digits.add(c);
}
modifiableMap.put(Sets.LOWERCASE, Collections.unmodifiableSet(lowercase));
modifiableMap.put(Sets.UPPERCASE, Collections.unmodifiableSet(uppercase));
modifiableMap.put(Sets.DIGITS, Collections.unmodifiableSet(digits));
modifiableMap.put(Sets.SPECIAL, Collections.unmodifiableSet(specialCharacters));
this.characterSets = Collections.unmodifiableMap(modifiableMap);
}
public static CharacterSetManager getInstance() {
return INSTANCE;
}
public Set<Character> getSet(Sets set) {
return this.characterSets.get(set);
}
public Map<Sets, Set<Character>> getSetMap() {
return this.characterSets;
}
}```
Detected code, here are some useful tools:
package com.cdev;
import java.util. * ;
public final class CharacterSetManager {
private static final CharacterSetManager INSTANCE = new CharacterSetManager();
private final Map<Sets, Set<Character>> characterSets;
public enum Sets {
LOWERCASE, UPPERCASE, DIGITS, SPECIAL}
private CharacterSetManager() {
Map<Sets, Set<Character>> modifiableMap = new EnumMap<>(Sets.class );
Set<Character> lowercase = new LinkedHashSet<>();
Set<Character> uppercase = new LinkedHashSet<>();
Set<Character> digits = new LinkedHashSet<>();
Set<Character> specialCharacters = new LinkedHashSet<>(List.of('!', '#', ' - ', '$', ' & '));
// populate sets
for (char c = 'a'; c <= 'z'; c++) {
lowercase.add(c);
uppercase.add(Character.toUpperCase(c));
}
for (char c = '0'; c <= '9'; c++) {
digits.add(c);
}
modifiableMap.put(Sets.LOWERCASE, Collections.unmodifiableSet(lowercase));
modifiableMap.put(Sets.UPPERCASE, Collections.unmodifiableSet(uppercase));
modifiableMap.put(Sets.DIGITS, Collections.unmodifiableSet(digits));
modifiableMap.put(Sets.SPECIAL, Collections.unmodifiableSet(specialCharacters));
this .characterSets = Collections.unmodifiableMap(modifiableMap);
}
public static CharacterSetManager getInstance() {
return INSTANCE;
}
public Set<Character> getSet(Sets set) {
return this .characterSets.get(set);
}
public Map<Sets, Set<Character>> getSetMap() {
return this .characterSets;
}
}
Maybe make it thread proof?
I don't see how this is not thread proof. Hes not changing anything after class initialization and afterwards there are only reads
I rage quit and deleted the whole program to start it over 
Any reason why? It doesn't look that bad
It was later on when I was trying to build my own configuration for generator, I wanted to have the ability to add different sets. This design is too fragile for adding because of the Enums and because its a Singleton