mirror of
https://github.com/dromara/tianai-captcha.git
synced 2026-06-15 23:15:33 +08:00
U 优化代码
This commit is contained in:
@@ -21,8 +21,8 @@ import java.util.function.BiFunction;
|
|||||||
*/
|
*/
|
||||||
public class MultiImageCaptchaGenerator extends AbstractImageCaptchaGenerator {
|
public class MultiImageCaptchaGenerator extends AbstractImageCaptchaGenerator {
|
||||||
|
|
||||||
private Map<String, ImageCaptchaGenerator> imageCaptchaGeneratorMap = new HashMap<>(4);
|
protected Map<String, ImageCaptchaGenerator> imageCaptchaGeneratorMap = new HashMap<>(4);
|
||||||
private Map<String, BiFunction<String, MultiImageCaptchaGenerator, ImageCaptchaGenerator>> imageCaptchaGeneratorProviderMap = new HashMap<>(4);
|
protected Map<String, BiFunction<String, MultiImageCaptchaGenerator, ImageCaptchaGenerator>> imageCaptchaGeneratorProviderMap = new HashMap<>(4);
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
@@ -79,6 +79,11 @@ public class MultiImageCaptchaGenerator extends AbstractImageCaptchaGenerator {
|
|||||||
param.setType(defaultCaptcha);
|
param.setType(defaultCaptcha);
|
||||||
type = defaultCaptcha;
|
type = defaultCaptcha;
|
||||||
}
|
}
|
||||||
|
ImageCaptchaGenerator imageCaptchaGenerator = requireGetCaptchaGenerator(type);
|
||||||
|
return imageCaptchaGenerator.generateCaptchaImage(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageCaptchaGenerator requireGetCaptchaGenerator(String type) {
|
||||||
ImageCaptchaGenerator imageCaptchaGenerator = imageCaptchaGeneratorMap.get(type);
|
ImageCaptchaGenerator imageCaptchaGenerator = imageCaptchaGeneratorMap.get(type);
|
||||||
if (imageCaptchaGenerator == null) {
|
if (imageCaptchaGenerator == null) {
|
||||||
BiFunction<String, MultiImageCaptchaGenerator, ImageCaptchaGenerator> provider = imageCaptchaGeneratorProviderMap.get(type);
|
BiFunction<String, MultiImageCaptchaGenerator, ImageCaptchaGenerator> provider = imageCaptchaGeneratorProviderMap.get(type);
|
||||||
@@ -87,7 +92,6 @@ public class MultiImageCaptchaGenerator extends AbstractImageCaptchaGenerator {
|
|||||||
}
|
}
|
||||||
imageCaptchaGenerator = imageCaptchaGeneratorMap.computeIfAbsent(type, k -> provider.apply(k, this));
|
imageCaptchaGenerator = imageCaptchaGeneratorMap.computeIfAbsent(type, k -> provider.apply(k, this));
|
||||||
}
|
}
|
||||||
|
return imageCaptchaGenerator;
|
||||||
return imageCaptchaGenerator.generateCaptchaImage(param);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user