#121 Refactoring a Document Status Service
Refactor the following service:
@Service
public class DocumentService {
@Autowired
StatusRepository statusRepository;
/
* Checks whether the document has been accepted. A document is considered accepted if its current
* status code is included in the list of positive status codes.
*/
public boolean isAcceptedDocument(Document document) {
List<String> statusCodes = Arrays.asList("500", "293", "216", "processed");
boolean result = false;
for (String status : statusCodes) {
if (document.getCurrentStatus().getCode() == status) {
result = true;
break;
}
}
return result;
}
/
* Checks whether document processing has finished. Processing is complete if the document contains
* a code that belongs to one of the final statuses.
*/
public boolean isFinishedDocument(Document document) {
List<String> documentStatusCodes = document.getCodes();
for (String docStatusCode : documentStatusCodes) {
Status status = statusRepository.findByCode(docStatusCode);
if (status.isFinal()) {
return true;
}
}
return false;
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor