diff --git a/src/com/o3smeasures/plugin/chart/BarChart.java b/src/com/o3smeasures/plugin/chart/BarChart.java index 0339533..0eec851 100644 --- a/src/com/o3smeasures/plugin/chart/BarChart.java +++ b/src/com/o3smeasures/plugin/chart/BarChart.java @@ -144,15 +144,7 @@ private void createFactors(ItemMeasured itemsMeasured) throws FactorNotFoundExce String factorName = O3SMeasuresConfigurationEnum.searchByValue(item.getName()).getFactor(); if (!factorName.equals("None") && !factorName.equals("High Cohesion of Methods")){ - Factor factor = factorsMap.get(factorName); - - if (factor == null){ - factor = new Factor(); - factor.setName(factorName); - factor.setDescription(factorName); - factor.setNumberOfIndicators(0); - factorsMap.put(factorName, factor); - } + Factor factor = factorsMap.computeIfAbsent(factorName, f -> new Factor(factorName, factorName, 0)); factor.getIndicators().add(new Indicator(item, 0.0)); factor.setNumberOfIndicators(factor.getNumberOfIndicators()+1); } diff --git a/src/com/o3smeasures/plugin/chart/BoxAndWhiskerChart.java b/src/com/o3smeasures/plugin/chart/BoxAndWhiskerChart.java index 968c765..b28e4fd 100644 --- a/src/com/o3smeasures/plugin/chart/BoxAndWhiskerChart.java +++ b/src/com/o3smeasures/plugin/chart/BoxAndWhiskerChart.java @@ -111,14 +111,7 @@ private void createFactors(ItemMeasured itemsMeasured) throws FactorNotFoundExce String factorName = O3SMeasuresConfigurationEnum.searchByValue(item.getName()).getFactor(); if (!factorName.equals("None") && !factorName.equals("High Cohesion of Methods")){ - Factor factor = factorsMap.get(factorName); - - if (factor == null){ - factor = new Factor(); - factor.setName(factorName); - factor.setDescription(factorName); - factorsMap.put(factorName, factor); - } + Factor factor = factorsMap.computeIfAbsent(factorName, f -> new Factor(factorName, factorName, 0)); factor.getIndicators().add(new Indicator(item, 0.0)); } } diff --git a/src/com/o3smeasures/statistic/Factor.java b/src/com/o3smeasures/statistic/Factor.java index 363f717..e710823 100644 --- a/src/com/o3smeasures/statistic/Factor.java +++ b/src/com/o3smeasures/statistic/Factor.java @@ -17,7 +17,14 @@ public class Factor { private int numberOfIndicators; public Factor(){ - indicators = new ArrayList<>(); + this.indicators = new ArrayList<>(); + } + + public Factor(String name, String description, int numberOfIndicators) { + this.name = name; + this.description = description; + this.numberOfIndicators = numberOfIndicators; + this.indicators = new ArrayList<>(); } public String getName() { diff --git a/src/com/o3smeasures/structures/Measure.java b/src/com/o3smeasures/structures/Measure.java index ef7e9f0..266c8d0 100644 --- a/src/com/o3smeasures/structures/Measure.java +++ b/src/com/o3smeasures/structures/Measure.java @@ -34,7 +34,7 @@ public enum Granularity { public Measure(){ applicableGranularities = new ArrayList<>(4); - parser = ASTParser.newParser(AST.JLS8); + parser = ASTParser.newParser(AST.JLS9); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setResolveBindings(true); } diff --git a/src/com/o3smeasures/util/JavaParser.java b/src/com/o3smeasures/util/JavaParser.java index e1559f6..0822ce3 100644 --- a/src/com/o3smeasures/util/JavaParser.java +++ b/src/com/o3smeasures/util/JavaParser.java @@ -69,7 +69,7 @@ public static CompilationUnit parseAST(FileInputStream fileInputStream){ ASTSession.getInstance().reset(); if (cacheParser) { - astParser = ASTParser.newParser(AST.JLS8); + astParser = ASTParser.newParser(AST.JLS9); astParser.setKind(ASTParser.K_COMPILATION_UNIT); astParser.setResolveBindings(true); char[] source = getFileContent(fileInputStream);