Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 232d388e

Přidáno uživatelem Ondřej Váně před asi 4 roky(ů)

Change list in anti pattern repository to map and fix selections

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/AntiPatternManagerImpl.java
7 7
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
8 8
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService;
9 9
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
10
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
10 11
import org.springframework.beans.factory.annotation.Autowired;
11 12
import org.springframework.stereotype.Service;
12 13

  
......
25 26
    @Override
26 27
    public List<QueryResult> analyze(String[] selectedProjects, String[] selectedAntiPatterns) {
27 28

  
28
        return this.analyze(antiPatternService.getAllAntiPatterns(), projectService.getAllProjects());
29
        return this.analyze(projectService.getAllProjectsForGivenIds(Utils.arrayOfStringsToArrayOfLongs(selectedProjects)),
30
                antiPatternService.getAllAntiPatternsForGivenIds(Utils.arrayOfStringsToArrayOfLongs(selectedAntiPatterns)));
29 31
    }
30 32

  
31
    private List<QueryResult> analyze(List<AntiPatternDetector> antiPatternDetectors, List<Project> projects) {
33
    private List<QueryResult> analyze(List<Project> projects, List<AntiPatternDetector> antiPatternDetectors) {
32 34
        DatabaseConnection databaseConnection = new DatabaseConnection();
33 35

  
34 36
        List<QueryResult> queryResults = new ArrayList<>();
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java
7 7
import org.springframework.stereotype.Component;
8 8

  
9 9
import java.lang.reflect.InvocationTargetException;
10
import java.util.LinkedList;
11
import java.util.List;
12
import java.util.Set;
10
import java.util.*;
13 11

  
14 12
@Component
15 13
public class AntiPatternRepository {
16 14

  
17 15
    private final Logger LOGGER = LoggerFactory.getLogger(AntiPatternRepository.class);
18 16

  
19
    private List<AntiPatternDetector> antiPatternDetectors = init();
17
    private Map<Long ,AntiPatternDetector> antiPatternDetectors = init();
20 18

  
21
    private List<AntiPatternDetector> init() {
22
        List<AntiPatternDetector> antiPatterns = new LinkedList<>();
19
    private Map<Long ,AntiPatternDetector> init() {
20
        Map<Long ,AntiPatternDetector> antiPatterns = new HashMap<>();
23 21
        try {
24 22
            Reflections reflections = new Reflections("cz.zcu.fav.kiv.antipatterndetectionapp");
25 23
            Set<Class<? extends AntiPatternDetector>> subTypes = reflections.getSubTypesOf(AntiPatternDetector.class);
26 24
            for (Class<? extends AntiPatternDetector> subType : subTypes) {
27
                antiPatterns.add(subType.getDeclaredConstructor().newInstance());
25
                AntiPatternDetector antiPatternDetector = subType.getDeclaredConstructor().newInstance();
26
                antiPatterns.putIfAbsent(antiPatternDetector.getAntiPatternId(), antiPatternDetector);
28 27
            }
29 28
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
30 29
            e.printStackTrace();
......
34 33
    }
35 34

  
36 35
    public List<AntiPatternDetector> getAllAntiPatterns() {
37
        return antiPatternDetectors;
36
        return new ArrayList<>(this.antiPatternDetectors.values());
38 37
    }
39 38

  
40 39
    public AntiPatternDetector getAntiPatternById(Long id) {
41
        for (AntiPatternDetector antiPatternDetector : antiPatternDetectors) {
42
            if (antiPatternDetector.getAntiPatternId().equals(id)) {
43
                return antiPatternDetector;
44
            }
45
            return antiPatternDetector;
46
        }
47
        return null;
40
        return this.antiPatternDetectors.getOrDefault(id, null);
48 41
    }
49 42
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternService.java
15 15

  
16 16
    AntiPattern antiPatternToModel(AntiPatternDetector antiPatternDetector);
17 17

  
18
    List<AntiPatternDetector> getAllAntiPatternsForGivenIds(Long[] ids);
19

  
18 20

  
19 21
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java
6 6
import org.springframework.beans.factory.annotation.Autowired;
7 7
import org.springframework.stereotype.Service;
8 8

  
9
import java.util.ArrayList;
9 10
import java.util.LinkedList;
10 11
import java.util.List;
11 12

  
......
39 40
    public AntiPattern antiPatternToModel(AntiPatternDetector antiPatternDetector) {
40 41
        return antiPatternDetector.getAntiPatternModel();
41 42
    }
43

  
44
    @Override
45
    public List<AntiPatternDetector> getAllAntiPatternsForGivenIds(Long[] ids) {
46
        List<AntiPatternDetector> antiPatternDetectors = new ArrayList<>();
47

  
48
        for (Long id : ids) {
49
            antiPatternDetectors.add(antiPatternRepository.getAntiPatternById(id));
50
        }
51
        return antiPatternDetectors;
52
    }
42 53
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ProjectService.java
9 9
    List<Project> getAllProjects();
10 10

  
11 11
    Project getProjectById(Long id);
12

  
13
    List<Project> getAllProjectsForGivenIds(Long[] ids);
12 14
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ProjectServiceImpl.java
6 6
import org.springframework.stereotype.Service;
7 7

  
8 8
import javax.transaction.Transactional;
9
import java.util.ArrayList;
9 10
import java.util.List;
10 11
import java.util.Optional;
11 12

  
......
30 31
            return result.get();
31 32
        }
32 33
    }
34

  
35
    @Override
36
    public List<Project> getAllProjectsForGivenIds(Long[] ids) {
37
        List<Project> projects = new ArrayList<>();
38

  
39
        for (Long id : ids) {
40
            projects.add(getProjectById(id));
41
        }
42
        return projects;
43
    }
33 44
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/utils/Utils.java
38 38
        return queries;
39 39
    }
40 40

  
41
    public static Long[] arrayOfStringsToArrayOfLongs(String[] strings) {
42
        Long[] longs = new Long[strings.length];
43
        for (int i = 0; i < strings.length; i++) {
44
            longs[i] = Long.parseLong(strings[i]);
45
        }
46
        return longs;
47
    }
48

  
41 49
    public static long daysBetween(Date firstDate, Date secondDate) {
42 50
        //24-May-2017, change this to your desired Start Date
43 51
        LocalDate dateBefore = firstDate.toLocalDate();

Také k dispozici: Unified diff