Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#80. Refactoring. #100

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/com/github/curiousoddman/rgxgen/RgxGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class RgxGen {
*
* @param pattern regex pattern for values generation
*/
public static RgxGen parse(CharSequence pattern) {
public static RgxGen parse(String pattern) {
return parse(null, pattern);
}

Expand All @@ -55,13 +55,13 @@ public static RgxGen parse(CharSequence pattern) {
* @param pattern regex pattern for values generation
* @see com.github.curiousoddman.rgxgen.config.RgxGenOption
*/
public static RgxGen parse(RgxGenProperties rgxGenProperties, CharSequence pattern) {
public static RgxGen parse(RgxGenProperties rgxGenProperties, String pattern) {
return new RgxGen(rgxGenProperties, pattern);
}

private RgxGen(RgxGenProperties properties, CharSequence pattern) {
private RgxGen(RgxGenProperties properties, String pattern) {
this.properties = properties;
DefaultTreeBuilder defaultTreeBuilder = new DefaultTreeBuilder(pattern.toString(), this.properties);
DefaultTreeBuilder defaultTreeBuilder = new DefaultTreeBuilder(pattern, this.properties);
node = defaultTreeBuilder.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

public class ArrayIterator implements StringIterator {

private final int aMaxIndex;
private final Character[] aStrings;
private final int aMaxIndex;
private final char[] aStrings;

private int aIndex = -1;

public ArrayIterator(Character[] strings) {
public ArrayIterator(char[] strings) {
aStrings = strings;
aMaxIndex = aStrings.length - 1; // Because of prefix increment in nextImpl()
}
Expand All @@ -41,7 +41,7 @@ public String next() {
if (aIndex >= aStrings.length) {
throw new NoSuchElementException("Not enough elements in arrays");
} else {
return aStrings[aIndex].toString();
return String.valueOf(aStrings[aIndex]);
}
}

Expand All @@ -52,6 +52,6 @@ public void reset() {

@Override
public String current() {
return aStrings[aIndex].toString();
return String.valueOf(aStrings[aIndex]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.util.function.Supplier;

public class ArrayIteratorSupplier implements Supplier<StringIterator> {
private final Character[] aSymbolSet;
private final char[] aSymbolSet;

public ArrayIteratorSupplier(Character[] symbolSet) {
public ArrayIteratorSupplier(char[] symbolSet) {
aSymbolSet = symbolSet;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,48 @@

import com.github.curiousoddman.rgxgen.parsing.dflt.ConstantsProvider;
import com.github.curiousoddman.rgxgen.util.Util;
import com.github.curiousoddman.rgxgen.util.chars.CharList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class RgxGenCharsDefinition {

private final List<SymbolRange> rangeList;
private final List<Character> characters;
private final CharList characters;

public static RgxGenCharsDefinition of(List<SymbolRange> externalRanges) {
return of(externalRanges, CharList.empty());
}

public static RgxGenCharsDefinition of(UnicodeCategory category) {
return new RgxGenCharsDefinition(category.getSymbolRanges(), Arrays.asList(category.getSymbols()));
return new RgxGenCharsDefinition(category.getSymbolRanges(), CharList.charList(category.getSymbols()));
}

public static RgxGenCharsDefinition of(SymbolRange... ranges) {
return new RgxGenCharsDefinition(Arrays.asList(ranges), Collections.emptyList());
return new RgxGenCharsDefinition(Arrays.asList(ranges), CharList.empty());
}

public static RgxGenCharsDefinition of(Character... characters) {
return new RgxGenCharsDefinition(Collections.emptyList(), Arrays.asList(characters));
public static RgxGenCharsDefinition of(char... characters) {
return new RgxGenCharsDefinition(Collections.emptyList(), CharList.charList(characters));
}

public static RgxGenCharsDefinition of(CharSequence characterString) {
List<Character> characterList = characterString.chars().mapToObj(c -> (char) c).collect(Collectors.toList());
public static RgxGenCharsDefinition of(String characterString) {
CharList characterList = CharList.charList(characterString);
List<SymbolRange> compactedRanges = new ArrayList<>();
List<Character> compactedSymbols = new ArrayList<>();
CharList compactedSymbols = CharList.empty();
Util.compactOverlappingRangesAndSymbols(Collections.emptyList(), characterList, compactedRanges, compactedSymbols);
return new RgxGenCharsDefinition(compactedRanges, compactedSymbols);
}

public static RgxGenCharsDefinition of(List<SymbolRange> symbolRanges, Character[] symbols) {
return of(symbolRanges, Arrays.asList(symbols));
public static RgxGenCharsDefinition of(CharList charList) {
return of(Collections.emptyList(), charList);
}

public static RgxGenCharsDefinition of(List<SymbolRange> symbolRanges, List<Character> symbols) {
public static RgxGenCharsDefinition of(List<SymbolRange> symbolRanges, CharList symbols) {
return new RgxGenCharsDefinition(symbolRanges, symbols);
}

Expand All @@ -73,19 +78,19 @@ public RgxGenCharsDefinition withRanges(List<SymbolRange> ranges) {
return this;
}

public RgxGenCharsDefinition withCharacters(Character... characters) {
this.characters.addAll(Arrays.asList(characters));
public RgxGenCharsDefinition withCharacters(char... characters) {
this.characters.addAll(characters);
return this;
}

public RgxGenCharsDefinition withCharacters(List<Character> characters) {
public RgxGenCharsDefinition withCharacters(CharList characters) {
this.characters.addAll(characters);
return this;
}

private RgxGenCharsDefinition(List<SymbolRange> rangeList, List<Character> characters) {
private RgxGenCharsDefinition(List<SymbolRange> rangeList, CharList characters) {
this.rangeList = new ArrayList<>(rangeList);
this.characters = new ArrayList<>(characters);
this.characters = characters.copy();
}

public boolean isAsciiOnly() {
Expand All @@ -100,7 +105,7 @@ public List<SymbolRange> getRangeList() {
return rangeList;
}

public List<Character> getCharacters() {
public CharList getCharacters() {
return characters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
limitations under the License.
/* **************************************************************************/

import java.util.stream.IntStream;
import java.util.stream.Stream;
import com.github.curiousoddman.rgxgen.util.chars.CharList;

/**
* Range of symbols
Expand Down Expand Up @@ -65,8 +64,8 @@ public int size() {
return to - from + 1;
}

public Stream<Character> chars() {
return IntStream.rangeClosed(from, to).mapToObj(i -> (char) i);
public CharList chars() {
return CharList.rangeClosed(from, to);
}

public boolean contains(int c) {
Expand Down
Loading
Loading