private List<Character> rangeFor(String startChar, String endChar) { int start = startChar.getBytes(StandardCharsets.US_ASCII)[0]; int end = endChar.getBytes(StandardCharsets.US_ASCII)[0]; assertPrintable(start); assertPrintable(end); assertOrder(start, end); List<Character> chars = new ArrayList<>(); ByteBuffer bb = ByteBuffer.allocate(1); for (int i = start; i <= end; i++) { bb.clear(); bb.put(0, (byte) i); CharBuffer decoded = StandardCharsets.US_ASCII.decode(bb); chars.add(decoded.get(0)); } return chars; }
public Combinations(String spec) { this.charsets = parseSpec(spec); this.modulo = computeRadixFactors(this.charsets); }
private char[][] parseSpec(String spec) { String[] ranges = spec.split("[,;]"); char[][] cs = new char[ranges.length][]; for (int i = 0; i < ranges.length; i++) { char[] range = rangeFor(ranges[i]); cs[i] = range; } return cs; }
@Example({"Combinations('A-Z;A-Z')","a two digit alphanumeric code. Wraps at 26^2"}) @Example({"Combinations('0-9A-F')","a single hexadecimal digit"}) @Example({"Combinations('0123456789ABCDEF')","a single hexadecimal digit"}) @Example({"Combinations('0-9A-F;0-9A-F;0-9A-F;0-9A-F;')","two bytes of hexadecimal"}) @Example({"Combinations('A-9')","upper case alphanumeric"}) public Combinations(String spec) { this.charsets = parseSpec(spec); this.modulo = computeRadixFactors(this.charsets); }
private List<Character> rangeFor(String startChar, String endChar) { int start = startChar.getBytes(StandardCharsets.US_ASCII)[0]; int end = endChar.getBytes(StandardCharsets.US_ASCII)[0]; assertPrintable(start); assertPrintable(end); assertOrder(start, end); List<Character> chars = new ArrayList<>(); ByteBuffer bb = ByteBuffer.allocate(1); for (int i = start; i <= end; i++) { bb.clear(); bb.put(0, (byte) i); CharBuffer decoded = StandardCharsets.US_ASCII.decode(bb); chars.add(decoded.get(0)); } return chars; }
private char[][] parseSpec(String spec) { String[] ranges = spec.split("[,;]"); char[][] cs = new char[ranges.length][]; for (int i = 0; i < ranges.length; i++) { char[] range = rangeFor(ranges[i]); cs[i] = range; } return cs; }
@Example({"Combinations('A-Z;A-Z')","a two digit alphanumeric code. Wraps at 26^2"}) @Example({"Combinations('0-9A-F')","a single hexadecimal digit"}) @Example({"Combinations('0123456789ABCDEF')","a single hexadecimal digit"}) @Example({"Combinations('0-9A-F;0-9A-F;0-9A-F;0-9A-F;')","two bytes of hexadecimal"}) @Example({"Combinations('A-9')","upper case alphanumeric"}) public Combinations(String spec) { this.charsets = parseSpec(spec); this.modulo = computeRadixFactors(this.charsets); }
private List<Character> rangeFor(String startChar, String endChar) { int start = startChar.getBytes(Charsets.US_ASCII)[0]; int end = endChar.getBytes(Charsets.US_ASCII)[0]; assertPrintable(start); assertPrintable(end); assertOrder(start, end); List<Character> chars = new ArrayList<>(); ByteBuffer bb = ByteBuffer.allocate(1); for (int i = start; i <= end; i++) { bb.clear(); bb.put(0, (byte) i); CharBuffer decoded = Charsets.US_ASCII.decode(bb); chars.add(decoded.get(0)); } return chars; }
private char[][] parseSpec(String spec) { String[] ranges = spec.split("[,;]"); char[][] cs = new char[ranges.length][]; for (int i = 0; i < ranges.length; i++) { char[] range = rangeFor(ranges[i]); cs[i] = range; } return cs; }
private char[] rangeFor(String range) { List<Character> chars = new ArrayList<>(); int pos = 0; while (pos < range.length()) { if (range.length() > pos + 2 && range.substring(pos + 1, pos + 2).equals("-")) { List<Character> rangeChars = rangeFor(range.substring(pos, pos + 1), range.substring(pos + 2, pos + 3)); chars.addAll(rangeChars); pos += 3; } else { chars.add(range.substring(pos, pos + 1).charAt(0)); pos += 1; } } char[] charAry = new char[chars.size()]; for (int i = 0; i < chars.size(); i++) { charAry[i] = chars.get(i); } return charAry; }
private char[] rangeFor(String range) { List<Character> chars = new ArrayList<>(); int pos = 0; while (pos < range.length()) { if (range.length() > pos + 2 && range.substring(pos + 1, pos + 2).equals("-")) { List<Character> rangeChars = rangeFor(range.substring(pos, pos + 1), range.substring(pos + 2, pos + 3)); chars.addAll(rangeChars); pos += 3; } else { chars.add(range.substring(pos, pos + 1).charAt(0)); pos += 1; } } char[] charAry = new char[chars.size()]; for (int i = 0; i < chars.size(); i++) { charAry[i] = chars.get(i); } return charAry; }
private char[] rangeFor(String range) { List<Character> chars = new ArrayList<>(); int pos = 0; while (pos < range.length()) { if (range.length() > pos + 2 && range.substring(pos + 1, pos + 2).equals("-")) { List<Character> rangeChars = rangeFor(range.substring(pos, pos + 1), range.substring(pos + 2, pos + 3)); chars.addAll(rangeChars); pos += 3; } else { chars.add(range.substring(pos, pos + 1).charAt(0)); pos += 1; } } char[] charAry = new char[chars.size()]; for (int i = 0; i < chars.size(); i++) { charAry[i] = chars.get(i); } return charAry; }