Код: Выделить всё
public List getAllCompanies(String authHeader) {
long start = System.currentTimeMillis();
List companies = new ArrayList();
long next = 0;
do {
CollectionResponse result = hubspotClient.getCompanies(authHeader, maxBatchSize, next, false, new ArrayList());
next = Optional.ofNullable(result.paging())
.map(Paging::next)
.map(Next::after)
.orElse(0L);
Envelope envelope = result.toEnvelope();
companies.addAll(envelope.items());
LOG.info("Loaded %d companies (next: %d, overall: %d)".formatted(
result.results().size(),
next,
companies.size()));
} while (next != 0);
LOG.info("Loaded %d companies in %ds".formatted(companies.size(), (System.currentTimeMillis() - start) / 1000));
return companies;
}
public List getAllContacts(String authHeader) {
long start = System.currentTimeMillis();
List contacts = new ArrayList();
long next = 0;
do {
CollectionResponse result = hubspotClient.getContacts(authHeader, maxBatchSize, next, false, new ArrayList());
next = Optional.ofNullable(result.paging())
.map(Paging::next)
.map(Next::after)
.orElse(0L);
Envelope envelope = result.toEnvelope();
contacts.addAll(envelope.items());
LOG.info("Loaded %d contacts (next: %d, overall: %d)".formatted(
result.results().size(),
next,
contacts.size()));
} while (next != 0);
LOG.info("Loaded %d contacts in %ds".formatted(contacts.size(), (System.currentTimeMillis() - start) / 1000));
return contacts;
}
Я попробовал применить универсальные функции, но возникший в результате беспорядок был уродливее, чем сам дублированный код. Как правильно провести рефакторинг этого кода?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -endpoints