Skip to content

Commit 367657e

Browse files
authored
Merge pull request #77 from rohithsh/develop
Fix filter action bugs
2 parents 80e90d7 + 78e0cb0 commit 367657e

File tree

3 files changed

+59
-17
lines changed

3 files changed

+59
-17
lines changed

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/data/JSONFileLoader.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static ArrayList<MethodWrapper> getMethods(ArrayList<Pair<String, String>
140140
for (MethodWrapper method : methods.values()) {
141141

142142

143-
if (method.getUpdateOperation().equals(Constants.METHOD_DELETED) || method.isTrainingMethod())
143+
if (method.getUpdateOperation().equals(Constants.METHOD_DELETED))
144144
continue;
145145

146146
filteredList.add(method);
@@ -187,20 +187,31 @@ private static ArrayList<MethodWrapper> filterList(ArrayList<Pair<String, String
187187

188188
for (String methodSignature : methods.keySet()) {
189189

190-
if ((filters.contains(Constants.FILE_FILTER) && !methodSignature.contains(currentFile))
191-
|| (!filters.contains(Constants.DELETED_FILTER) && methods.get(methodSignature).getUpdateOperation().equals(Constants.METHOD_DELETED))
192-
|| (methods.get(methodSignature).isTrainingMethod() && !filters.contains(Constants.TRAIN_FILTER)))
193-
continue;
194-
195-
for (Category category : methods.get(methodSignature).getCategories()) {
196-
197-
if ((filters.contains(Constants.DELETED_FILTER) && methods.get(methodSignature).getUpdateOperation().equals(Constants.METHOD_DELETED))
198-
|| filters.contains(new Pair<>(Constants.FILTER_TYPE, Formatter.toTitleCase(category.toString())))
199-
|| filters.contains(new Pair<>(Constants.FILTER_CWE, Formatter.toTitleCase(category.toString())))
200-
|| (methods.get(methodSignature).isTrainingMethod() && filters.contains(Constants.TRAIN_FILTER))) {
201-
202-
filteredList.add(methods.get(methodSignature));
203-
break;
190+
if(filters.size()==1 && filters.contains(Constants.TRAIN_FILTER) && methods.get(methodSignature).isTrainingMethod()){
191+
filteredList.add(methods.get(methodSignature));
192+
}else if((filters.contains(Constants.FILE_FILTER) && !methodSignature.contains(currentFile))
193+
|| (!filters.contains(Constants.DELETED_FILTER) && methods.get(methodSignature).getUpdateOperation().equals(Constants.METHOD_DELETED))){
194+
} else if (filters.size()>1 && filters.contains(Constants.TRAIN_FILTER)) {
195+
for (Category category : methods.get(methodSignature).getCategories()) {
196+
Pair<String, String> typePair = new Pair<>(Constants.FILTER_TYPE, Formatter.toTitleCase(category.toString()));
197+
Pair<String, String> cwePair = new Pair<>(Constants.FILTER_CWE, Formatter.toTitleCase(category.toString()));
198+
boolean isDeleted = filters.contains(Constants.DELETED_FILTER) && methods.get(methodSignature).getUpdateOperation().equals(Constants.METHOD_DELETED);
199+
boolean isTypeFilter = filters.contains(typePair) || filters.contains(cwePair);
200+
if ((isDeleted || isTypeFilter) && methods.get(methodSignature).isTrainingMethod()){
201+
filteredList.add(methods.get(methodSignature));
202+
break;
203+
}
204+
}
205+
} else{
206+
for (Category category : methods.get(methodSignature).getCategories()) {
207+
Pair<String, String> typePair = new Pair<>(Constants.FILTER_TYPE, Formatter.toTitleCase(category.toString()));
208+
Pair<String, String> cwePair = new Pair<>(Constants.FILTER_CWE, Formatter.toTitleCase(category.toString()));
209+
boolean isDeleted = filters.contains(Constants.DELETED_FILTER) && methods.get(methodSignature).getUpdateOperation().equals(Constants.METHOD_DELETED);
210+
boolean isTypeFilter = filters.contains(typePair) || filters.contains(cwePair);
211+
if (isDeleted || isTypeFilter ){
212+
filteredList.add(methods.get(methodSignature));
213+
break;
214+
}
204215
}
205216
}
206217
}

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/ui/MethodListTree.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,12 @@ private void loadMethods() {
587587

588588
classNode.add(addCategoriesToNode(method));
589589

590-
if (method.getMethod().isKnown())
590+
if (method.getMethod().isKnown()) {
591+
method.setTrainingMethod(true);
591592
standardSrms.add(classNode);
592-
else
593+
}else{
593594
currentProject.add(classNode);
595+
}
594596
}
595597
}
596598

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/util/Pair.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.fraunhofer.iem.swan.assist.util;
22

3+
import java.util.Objects;
4+
35
public class Pair<T,U> {
46
private final T key;
57
private final U value;
@@ -16,4 +18,31 @@ public T getKey() {
1618
public U getValue() {
1719
return this.value;
1820
}
21+
22+
@Override
23+
public boolean equals(Object obj) {
24+
if (this == obj) {
25+
return true;
26+
}
27+
28+
if (obj == null || getClass() != obj.getClass()) {
29+
return false;
30+
}
31+
32+
Pair<?, ?> pair = (Pair<?, ?>) obj;
33+
34+
if (!Objects.equals(key, pair.key)) {
35+
return false;
36+
}
37+
38+
return Objects.equals(value, pair.value);
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
int result = key != null ? key.hashCode() : 0;
44+
result = 31 * result + (value != null ? value.hashCode() : 0);
45+
return result;
46+
}
47+
1948
}

0 commit comments

Comments
 (0)