public void EqualsTest(NetworkAddress addr1, NetworkAddress addr2, bool expected) { Assert.Equal(expected, addr1.Equals(addr2)); Assert.Equal(expected, addr1.Equals((object)addr2)); Assert.Equal(expected, addr2.Equals(addr1)); Assert.Equal(expected, addr2.Equals((object)addr1)); Assert.True(addr1.Equals(addr1)); Assert.True(addr1.Equals((object)addr1)); Assert.True(addr2.Equals(addr2)); Assert.True(addr2.Equals((object)addr2)); }
public void Equality_Success() { NetworkAddress a1 = new NetworkAddress(1); NetworkAddress a2 = new NetworkAddress(2); NetworkAddress a3 = new NetworkAddress(2); Assert.IsFalse(a1.Equals(a2)); Assert.IsTrue(a2.Equals(a3)); }
/// <summary> /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality /// and the method will only return true if the node data has been changed. /// /// @param node the {@link ZigBeeNode} that contains the newer node data. /// @return true if there were changes made as a result of the update /// </summary> public bool UpdateNode(ZigBeeNode node) { if (!node.IeeeAddress.Equals(IeeeAddress)) { return(false); } bool updated = false; if (!NetworkAddress.Equals(node.NetworkAddress)) { updated = true; NetworkAddress = node.NetworkAddress; } if (!NodeDescriptor.Equals(node.NodeDescriptor)) { updated = true; NodeDescriptor = node.NodeDescriptor; } if (!PowerDescriptor.Equals(node.PowerDescriptor)) { updated = true; PowerDescriptor = node.PowerDescriptor; } lock (AssociatedDevices) { if (!AssociatedDevices.Equals(node.AssociatedDevices)) { updated = true; AssociatedDevices.Clear(); AssociatedDevices.AddRange(node.AssociatedDevices); } } lock (BindingTable) { if (!BindingTable.Equals(node.BindingTable)) { updated = true; BindingTable.Clear(); BindingTable.AddRange(node.BindingTable); } } lock (Neighbors) { if (!Neighbors.Equals(node.Neighbors)) { updated = true; Neighbors.Clear(); Neighbors.AddRange(node.Neighbors); } } lock (Routes) { if (!Routes.Equals(node.Routes)) { updated = true; Routes.Clear(); Routes.AddRange(node.Routes); } } // TODO: How to deal with endpoints return(updated); }
public override bool Equals(Object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (this.GetType() != obj.GetType()) { return(false); } NeighborTable other = (NeighborTable)obj; //if (depth == null) //{ // if (other.depth != null) // { // return false; // } //} /*else */ if (!Depth.Equals(other.Depth)) { return(false); } if (DeviceType != other.DeviceType) { return(false); } if (ExtendedAddress == null) { if (other.ExtendedAddress != null) { return(false); } } else if (!ExtendedAddress.Equals(other.ExtendedAddress)) { return(false); } if (ExtendedPanId == null) { if (other.ExtendedPanId != null) { return(false); } } else if (!ExtendedPanId.Equals(other.ExtendedPanId)) { return(false); } //if (lqi == null) //{ // if (other.lqi != null) // { // return false; // } //} else if (!Lqi.Equals(other.Lqi)) { return(false); } //if (networkAddress == null) //{ // if (other.networkAddress != null) // { // return false; // } //} else if (!NetworkAddress.Equals(other.NetworkAddress)) { return(false); } if (PermitJoining != other.PermitJoining) { return(false); } if (Relationship != other.Relationship) { return(false); } if (RxOnWhenIdle != other.RxOnWhenIdle) { return(false); } return(true); }
/// <summary> /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality /// and the method will only return true if the node data has been changed. /// /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param> /// <returns>true if there were changes made as a result of the update</returns> /// </summary> public bool UpdateNode(ZigBeeNode node) { if (!node.IeeeAddress.Equals(IeeeAddress)) { return(false); } bool updated = false; if (!NetworkAddress.Equals(node.NetworkAddress)) { updated = true; NetworkAddress = node.NetworkAddress; } if (!NodeDescriptor.Equals(node.NodeDescriptor)) { updated = true; NodeDescriptor = node.NodeDescriptor; } if (!PowerDescriptor.Equals(node.PowerDescriptor)) { updated = true; PowerDescriptor = node.PowerDescriptor; } lock (AssociatedDevices) { if (!AssociatedDevices.Equals(node.AssociatedDevices)) { updated = true; AssociatedDevices.Clear(); AssociatedDevices.AddRange(node.AssociatedDevices); } } lock (BindingTable) { if (!BindingTable.Equals(node.BindingTable)) { updated = true; BindingTable.Clear(); BindingTable.AddRange(node.BindingTable); } } lock (Neighbors) { if (!Neighbors.Equals(node.Neighbors)) { updated = true; Neighbors.Clear(); Neighbors.AddRange(node.Neighbors); } } lock (Routes) { if (!Routes.Equals(node.Routes)) { updated = true; Routes.Clear(); Routes.AddRange(node.Routes); } } // Endpoints are only copied over if they don't exist in the node // The assumption here is that endpoints are only set once, and not changed. // This should be valid as they are set through the SimpleDescriptor. foreach (var endpoint in node.Endpoints) { if (Endpoints.ContainsKey(endpoint.Key)) { continue; } updated = true; Endpoints[endpoint.Key] = endpoint.Value; } return(updated); }
/// <summary> /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality /// and the method will only return true if the node data has been changed. /// /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param> /// <returns>true if there were changes made as a result of the update</returns> /// </summary> public bool UpdateNode(ZigBeeNode node) { if (!node.IeeeAddress.Equals(IeeeAddress)) { Log.Debug("{IeeeAddress}: Ieee address inconsistent during update <>{NodeIeeeAddress}", IeeeAddress, node.IeeeAddress); return(false); } bool updated = false; if (NetworkAddress != 0 && !NetworkAddress.Equals(node.NetworkAddress)) { Log.Debug("{IeeeAddress}: Network address updated from {NetworkAddress} to {NodeNetworkAddress}", IeeeAddress, NetworkAddress, node.NetworkAddress); updated = true; NetworkAddress = node.NetworkAddress; } if (node.NodeDescriptor != null && (NodeDescriptor == null || !NodeDescriptor.Equals(node.NodeDescriptor))) { Log.Debug("{IeeeAddress}: Node descriptor updated", IeeeAddress); updated = true; NodeDescriptor = node.NodeDescriptor; } if (node.PowerDescriptor != null && (PowerDescriptor == null || !PowerDescriptor.Equals(node.PowerDescriptor))) { Log.Debug("{IeeeAddress}: Power descriptor updated", IeeeAddress); updated = true; PowerDescriptor = node.PowerDescriptor; } lock (_associatedDevices) { if (!_associatedDevices.SetEquals(node._associatedDevices)) { Log.Debug("{IeeeAddress}: Associated devices updated", IeeeAddress); updated = true; _associatedDevices.Clear(); _associatedDevices.UnionWith(node._associatedDevices); } } lock (_bindingTable) { if (!_bindingTable.SetEquals(node._bindingTable)) { Log.Debug("{IeeeAddress}: Binding table updated", IeeeAddress); updated = true; _bindingTable.Clear(); _bindingTable.UnionWith(node._bindingTable); } } lock (_neighbors) { if (!_neighbors.SetEquals(node._neighbors)) { Log.Debug("{IeeeAddress}: Neighbors updated", IeeeAddress); updated = true; _neighbors.Clear(); _neighbors.UnionWith(node._neighbors); } } lock (_routes) { if (!_routes.SetEquals(node._routes)) { Log.Debug("{IeeeAddress}: Routes updated", IeeeAddress); updated = true; _routes.Clear(); _routes.UnionWith(node._routes); } } // Endpoints are only copied over if they don't exist in the node // The assumption here is that endpoints are only set once, and not changed. // This should be valid as they are set through the SimpleDescriptor. foreach (var endpoint in node._endpoints) { if (_endpoints.ContainsKey(endpoint.Key)) { continue; } Log.Debug("{IeeeAddress}: Endpoint {EndpointId} added", IeeeAddress, endpoint.Key); updated = true; _endpoints[endpoint.Key] = endpoint.Value; } return(updated); }
protected bool Equals(Subnet other) { return(NetworkAddress.Equals(other.NetworkAddress) && NetmaskLength == other.NetmaskLength); }
protected bool Equals(Row other) { return(NetworkAddress.Equals(other.NetworkAddress) && ControlPlaneElement == other.ControlPlaneElement); }