Skip to content

Commit 156ea99

Browse files
authored
Merge pull request #12 from kingthorin/prevent-dupes
improve: Prevent programmattic duplicates
2 parents d0b897a + e74ae62 commit 156ea99

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
### Changed
99
- Add red/green icon to Enable/Disable toggle button.
1010
- Maintenance changes.
11+
- Now targeting ZAP 2.10.
12+
- Ensure added color mappings are unique (Issue 11). Only applies when mappings are added programmatically, a user can still define the same mapping multiple times via the GUI (hopefully they'll recognize the inefficiency of doing so).
1113

1214
## [1.3.0] - 2020-09-29
1315

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ description = "Colors history table items based on tags"
5757
zapAddOn {
5858
addOnName.set("Neonmarker")
5959
addOnStatus.set(AddOnStatus.ALPHA)
60-
zapVersion.set("2.8.0")
60+
zapVersion.set("2.10.0")
6161

6262
releaseLink.set("https://github.com/kingthorin/neonmarker/compare/v@PREVIOUS_VERSION@...v@CURRENT_VERSION@")
6363
unreleasedLink.set("https://github.com/kingthorin/neonmarker/compare/v@CURRENT_VERSION@...HEAD")

src/main/java/org/zaproxy/zap/extension/neonmarker/ExtensionNeonmarker.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import java.util.Arrays;
2727
import java.util.Collections;
2828
import java.util.List;
29+
import java.util.Objects;
2930
import org.apache.commons.lang3.Range;
30-
import org.apache.log4j.Logger;
31+
import org.apache.logging.log4j.LogManager;
32+
import org.apache.logging.log4j.Logger;
3133
import org.jdesktop.swingx.decorator.AbstractHighlighter;
3234
import org.jdesktop.swingx.decorator.ComponentAdapter;
3335
import org.jdesktop.swingx.decorator.HighlightPredicate;
@@ -45,7 +47,7 @@
4547
import org.zaproxy.zap.view.table.HistoryReferencesTableModel;
4648

4749
public class ExtensionNeonmarker extends ExtensionAdaptor {
48-
private static final Logger LOGGER = Logger.getLogger(ExtensionNeonmarker.class);
50+
private static final Logger LOGGER = LogManager.getLogger(ExtensionNeonmarker.class);
4951
private static final Range<Integer> INT_RANGE =
5052
Range.between(Integer.MIN_VALUE, Integer.MAX_VALUE);
5153
public static final String RESOURCE = "/org/zaproxy/zap/extension/neonmarker/resources";
@@ -179,17 +181,17 @@ protected void toggleHighlighter(boolean on) {
179181
public boolean addColorMapping(String tag, int color) {
180182
if (isValidTag(tag) && isValidColor(color)) {
181183
Color newColor = new Color(color);
182-
getColorMap().add(new ColorMapping(tag, newColor));
184+
ColorMapping newMapping = new ColorMapping(tag, newColor);
185+
if (!getColorMap().contains(newMapping)) {
186+
getColorMap().add(newMapping);
187+
}
183188
if (!palette.contains(newColor)) {
184189
addToPalette(newColor);
185190
}
186191
getNeonmarkerPanel().refreshDisplay();
187192
return true;
188193
}
189-
if (LOGGER.isDebugEnabled()) {
190-
LOGGER.debug(
191-
"Either the tag: \"" + tag + "\" or the color: \"" + color + " was invalid.");
192-
}
194+
LOGGER.debug("Either the tag: \"{}\" or the color: \"{}\" was invalid.", tag, color);
193195
return false;
194196
}
195197

@@ -297,6 +299,26 @@ public Color getColor() {
297299
public void setColor(Color color) {
298300
this.color = color;
299301
}
302+
303+
@Override
304+
public int hashCode() {
305+
return Objects.hash(color, tag);
306+
}
307+
308+
@Override
309+
public boolean equals(Object obj) {
310+
if (this == obj) {
311+
return true;
312+
}
313+
if (obj == null) {
314+
return false;
315+
}
316+
if (getClass() != obj.getClass()) {
317+
return false;
318+
}
319+
ColorMapping other = (ColorMapping) obj;
320+
return Objects.equals(color, other.color) && Objects.equals(tag, other.tag);
321+
}
300322
}
301323

302324
@Override

0 commit comments

Comments
 (0)