Witam, jestem początkującym programistą Java. Obecnie zastanawiam się jak by uporządkować ten kod, czy podzielić je na klasy abstrakcyjne, czy interfejsy, czy dodać więcej metod. Jakie są Wasze sposoby na uporządkowanie takiego kodu ?
private static String runMight(TypeCaptcha typeCaptcha, String apiKey, String filePath, String urlWebsite, String keyWebsite, Integer attempts, Integer timeoutAttempt, Integer might, String userAgent, ProxyTypeOption proxyTypeOption, String proxyAddress, Integer proxyPort, String proxyLogin, String proxyPassword) throws AntiCaptchaException {
String result = null;
try {
SimpleObjectProperty<Throwable> error = new SimpleObjectProperty<>();
SimpleStringProperty solution = new SimpleStringProperty(null);
Integer countSyncAttempt = 0;
while (countSyncAttempt < attempts) {
countSyncAttempt++;
ExecutorService executorService = AsyncHelper.async(() -> {
List<Callable<Object>> callables = new ArrayList<>();
for (int i = 0; i < might; i++) {
final Integer count = i;
callables.add(() -> {
String s = null;
switch (typeCaptcha) {
case IMAGE_TO_TEXT:
s = AnticaptchaHelper.imageToText(apiKey, filePath);
break;
case RECAPTCHA_V2:
s = AnticaptchaHelper.noCaptchaProxyless(apiKey, urlWebsite, keyWebsite);
break;
case RECAPTCHA_V2_PROXY:
s = AnticaptchaHelper.noCaptcha(apiKey, urlWebsite, keyWebsite, userAgent, proxyTypeOption, proxyAddress, proxyLogin, proxyPassword, proxyPort);
break;
default:
s = AnticaptchaHelper.imageToText(apiKey, filePath);
}
if (Objects.isNull(solution.get())) {
synchronized (solution) {
solution.set(s);
}
}
return null;
});
}
try {
AsyncHelper.asyncMultiWait(callables, callables.size(), "Anticaptcha", true, Thread.NORM_PRIORITY);
} catch (AsyncHelperException e) {
error.set(e);
}
}, "Anticaptcha Main", false, Thread.NORM_PRIORITY);
Integer timeoutAttemptCountMilliseconds = 0;
Integer poolingEvery = 100;
while (true) {
if (Objects.nonNull(solution.get()))
break;
TimeUnit.MILLISECONDS.sleep(poolingEvery);
timeoutAttemptCountMilliseconds += poolingEvery;
if (timeoutAttemptCountMilliseconds >= timeoutAttempt * 1000) {
break;
}
}
if (Objects.nonNull(solution.get())) {
executorService.awaitTermination(1, TimeUnit.NANOSECONDS);
break;
}
}
if (Objects.nonNull(error.get())) {
throw new AntiCaptchaException(error.get());
}
result = solution.get();
} catch (Exception e) {
throw new AntiCaptchaException(e);
}
return result;