@Test public void testGenerate() { CustomCodeGenerator generator = new CustomCodeGenerator(CustomCodeGenerator.Mode.NUMBER); String code = generator.generateCode("xxx"); Assert.assertEquals(6, code.length()); String code2 = generator.generateCode("xxx"); Assert.assertNotEquals(code, code2); }
@Override public String generateCode(String phone) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxLength; i++) { int index = random.nextInt(arr.size()); sb.append(arr.get(index)); if (sb.length() >= minLength) { if (random.nextBoolean()) { break; } } } return sb.toString(); }
CustomCodeGenerator implements CodeGenerator, InitializingBean { @Override public String generateCode(String phone) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxLength; i++) { int index = random.nextInt(arr.size()); sb.append(arr.get(index)); if (sb.length() >= minLength) { if (random.nextBoolean()) { break; } } } return sb.toString(); } }
CustomCodeGenerator implements CodeGenerator, InitializingBean { @Override public String generateCode(String phone) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxLength; i++) { int index = random.nextInt(arr.size()); sb.append(arr.get(index)); if (sb.length() >= minLength) { if (random.nextBoolean()) { break; } } } return sb.toString(); } CustomCodeGenerator(Mode... modes); }
CustomCodeGenerator implements CodeGenerator, InitializingBean { @Override public String generateCode(String phone) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxLength; i++) { int index = random.nextInt(arr.size()); sb.append(arr.get(index)); if (sb.length() >= minLength) { if (random.nextBoolean()) { break; } } } return sb.toString(); } CustomCodeGenerator(Mode... modes); @Override String generateCode(String phone); void setMode(Mode... modes); void addMode(Mode... modes); void addArr(char[] chars); void setMinLength(int minLength); void setMaxLength(int maxLength); @Override void afterPropertiesSet(); }
CustomCodeGenerator implements CodeGenerator, InitializingBean { @Override public String generateCode(String phone) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxLength; i++) { int index = random.nextInt(arr.size()); sb.append(arr.get(index)); if (sb.length() >= minLength) { if (random.nextBoolean()) { break; } } } return sb.toString(); } CustomCodeGenerator(Mode... modes); @Override String generateCode(String phone); void setMode(Mode... modes); void addMode(Mode... modes); void addArr(char[] chars); void setMinLength(int minLength); void setMaxLength(int maxLength); @Override void afterPropertiesSet();  }