1 | package edu.ucsb.cs156.rec.services; | |
2 | ||
3 | import edu.ucsb.cs156.rec.entities.RequestType; | |
4 | import edu.ucsb.cs156.rec.repositories.RequestTypeRepository; | |
5 | import lombok.extern.slf4j.Slf4j; | |
6 | ||
7 | import java.util.ArrayList; | |
8 | import java.util.List; | |
9 | import java.util.Optional; | |
10 | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | |
12 | import org.springframework.stereotype.Service; | |
13 | ||
14 | /** | |
15 | * This is a service that provides information about the current user. | |
16 | * | |
17 | * This is the version of the service used in production. | |
18 | */ | |
19 | ||
20 | @Slf4j | |
21 | @Service("RequestType") | |
22 | public class RequestTypeService { | |
23 | | |
24 | @Autowired | |
25 | private RequestTypeRepository requestTypeRepository; | |
26 | ||
27 | private boolean requestTypeExists(String type) { | |
28 | boolean alreadyContains = false; | |
29 | Iterable<RequestType> typeList = requestTypeRepository.findAll(); | |
30 | ||
31 | for (RequestType requestType : typeList) { | |
32 |
1
1. requestTypeExists : negated conditional → KILLED |
if (requestType.getRequestType().equals(type)) { |
33 | alreadyContains = true; | |
34 | break; | |
35 | } | |
36 | } | |
37 |
2
1. requestTypeExists : replaced boolean return with true for edu/ucsb/cs156/rec/services/RequestTypeService::requestTypeExists → KILLED 2. requestTypeExists : replaced boolean return with false for edu/ucsb/cs156/rec/services/RequestTypeService::requestTypeExists → KILLED |
return alreadyContains; |
38 | } | |
39 | ||
40 | public Optional<RequestType> trySave(RequestType requestType) { | |
41 | boolean alreadyContains = requestTypeExists(requestType.getRequestType()); | |
42 | ||
43 |
1
1. trySave : negated conditional → KILLED |
if (alreadyContains) { |
44 | return Optional.empty(); | |
45 | } | |
46 | ||
47 |
1
1. trySave : replaced return value with Optional.empty for edu/ucsb/cs156/rec/services/RequestTypeService::trySave → KILLED |
return Optional.of(requestTypeRepository.save(requestType)); |
48 | } | |
49 | ||
50 | public List<RequestType> trySaveTypes(List<RequestType> toSave) { | |
51 | List<RequestType> savedTypes = new ArrayList<RequestType>(); | |
52 | ||
53 |
1
1. trySaveTypes : removed call to java/util/List::forEach → KILLED |
toSave.forEach((requestType) -> { |
54 | Optional<RequestType> saved = trySave(requestType); | |
55 |
1
1. lambda$trySaveTypes$0 : negated conditional → KILLED |
if (saved.isPresent()) { |
56 | savedTypes.add(saved.get()); | |
57 | } | |
58 | }); | |
59 | ||
60 |
1
1. trySaveTypes : replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/services/RequestTypeService::trySaveTypes → KILLED |
return savedTypes; |
61 | } | |
62 | } | |
Mutations | ||
32 |
1.1 |
|
37 |
1.1 2.2 |
|
43 |
1.1 |
|
47 |
1.1 |
|
53 |
1.1 |
|
55 |
1.1 |
|
60 |
1.1 |