From f1e082091c9bc7255c99146bb0f7320793913ced Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Wed, 14 Feb 2024 16:05:27 -0500 Subject: [PATCH] warn when adding duplicate entries --- src/org/openlcb/can/AliasMap.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/org/openlcb/can/AliasMap.java b/src/org/openlcb/can/AliasMap.java index ba983b29..679a4b4f 100644 --- a/src/org/openlcb/can/AliasMap.java +++ b/src/org/openlcb/can/AliasMap.java @@ -3,6 +3,7 @@ import org.openlcb.NodeID; import java.util.ArrayList; +import java.util.logging.Logger; /** * Maintains a 2-way map between nodes and CAN node ID aliases. @@ -19,7 +20,8 @@ public AliasMap() { java.util.HashMap iMap = new java.util.HashMap(); java.util.HashMap nMap = new java.util.HashMap(); java.util.List watchers = new ArrayList<>(); - + private final static Logger logger = Logger.getLogger(AliasMap.class.getName()); + /// This interface allows an external component to watch for newly discovered aliases. public interface Watcher { /// Called when a new alias was discovered. @@ -47,6 +49,17 @@ public void processFrame(OpenLcbCanFrame f) { public void insert(int alias, NodeID nid) { synchronized (this) { + if (nMap.containsKey(alias) && nid.toLong() != nMap.get(alias).toLong()) { + logger.warning("map contains alias " + +String.format("0x%03X", alias & 0xFFF) + +" for node "+nMap.get(alias)+" change to "+nid); + } + if (iMap.containsKey(nid) && alias != iMap.get(nid)) { + logger.warning("map contains nodeID "+nid+" for alias " + +String.format("0x%03X", iMap.get(nid) & 0xFFF) + +" change to " + +String.format("0x%03X", alias & 0xFFF)); + } nMap.put(alias, nid); iMap.put(nid, alias); }