Skip to content

Commit

Permalink
Exclude tags starting with !
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Dec 26, 2024
1 parent 1ed4d99 commit f631613
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/main/java/com/askimed/nf/test/core/TagQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,36 @@ public boolean matches(ITaggable taggable) {
return true;
}

if (tags.contains(taggable.getName().toLowerCase())) {
// Separate positive and negative tags
List<String> positiveTags = new Vector<String>();
List<String> negativeTags = new Vector<String>();

for (String tag : tags) {
if (tag.startsWith("!")) {
negativeTags.add(tag.substring(1).toLowerCase()); // Remove '!' prefix for negative tags
} else {
positiveTags.add(tag.toLowerCase());
}
}

// Check for negative matches
if (negativeTags.contains(taggable.getName().toLowerCase())) {
return false;
}

for (String tag : taggable.getTags()) {
if (negativeTags.contains(tag.toLowerCase())) {
return false;
}
}

// Check for positive matches
if (positiveTags.contains(taggable.getName().toLowerCase())) {
return true;
}

for (String tag : taggable.getTags()) {
if (tags.contains(tag.toLowerCase())) {
if (positiveTags.contains(tag.toLowerCase())) {
return true;
}
}
Expand All @@ -48,12 +72,11 @@ public boolean matches(ITaggable taggable) {
return matches(taggable.getParent());
}

return false;
return !negativeTags.isEmpty();
}

@Override
public String toString() {
return tags.toString();
}

}

0 comments on commit f631613

Please sign in to comment.