Skip to content

Commit

Permalink
Merge pull request #563 from NordicSemiconductor/improvement/equatable
Browse files Browse the repository at this point in the history
[Breaking] Fixed Equatable implementation
  • Loading branch information
philips77 authored Oct 11, 2023
2 parents 0111351 + 2554f40 commit bcf32f6
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 28 deletions.
6 changes: 5 additions & 1 deletion nRFMeshProvision/Mesh Model/ApplicationKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ public class ApplicationKey: Key, Codable {
extension ApplicationKey: Equatable {

public static func == (lhs: ApplicationKey, rhs: ApplicationKey) -> Bool {
return lhs.index == rhs.index && lhs.key == rhs.key
return lhs.index == rhs.index
&& lhs.key == rhs.key
&& lhs.oldKey == rhs.oldKey
&& lhs.name == rhs.name
&& lhs.boundNetworkKeyIndex == rhs.boundNetworkKeyIndex
}

public static func != (lhs: ApplicationKey, rhs: ApplicationKey) -> Bool {
Expand Down
8 changes: 3 additions & 5 deletions nRFMeshProvision/Mesh Model/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,9 @@ public class Element: Codable {
extension Element: Equatable, Hashable {

public static func == (lhs: Element, rhs: Element) -> Bool {
return lhs.parentNode === rhs.parentNode && lhs.index == rhs.index
}

public static func != (lhs: Element, rhs: Element) -> Bool {
return lhs.parentNode !== rhs.parentNode || lhs.index != rhs.index
return lhs.parentNode === rhs.parentNode
&& lhs.index == rhs.index
&& lhs.name == rhs.name
}

public func hash(into hasher: inout Hasher) {
Expand Down
6 changes: 2 additions & 4 deletions nRFMeshProvision/Mesh Model/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,8 @@ extension Group: Equatable, Hashable {

public static func == (lhs: Group, rhs: Group) -> Bool {
return lhs.groupAddress == rhs.groupAddress
}

public static func != (lhs: Group, rhs: Group) -> Bool {
return lhs.groupAddress != rhs.groupAddress
&& lhs.parentAddress == rhs.parentAddress
&& lhs.name == rhs.name
}

public func hash(into hasher: inout Hasher) {
Expand Down
10 changes: 5 additions & 5 deletions nRFMeshProvision/Mesh Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ internal extension Model {
extension Model: Equatable, Hashable {

public static func == (lhs: Model, rhs: Model) -> Bool {
return lhs.modelId == rhs.modelId && lhs.parentElement == rhs.parentElement
}

public static func != (lhs: Model, rhs: Model) -> Bool {
return lhs.modelId != rhs.modelId || lhs.parentElement != rhs.parentElement
return lhs.modelId == rhs.modelId
&& lhs.parentElement == rhs.parentElement
&& lhs.bind == rhs.bind
&& lhs.subscribe == rhs.subscribe
&& lhs.publish == rhs.publish
}

public func hash(into hasher: inout Hasher) {
Expand Down
8 changes: 4 additions & 4 deletions nRFMeshProvision/Mesh Model/NetworkKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ extension NetworkKey: Equatable {

public static func == (lhs: NetworkKey, rhs: NetworkKey) -> Bool {
return lhs.index == rhs.index
}

public static func != (lhs: NetworkKey, rhs: NetworkKey) -> Bool {
return lhs.index != rhs.index
&& lhs.phase == rhs.phase
&& lhs.key == rhs.key
&& lhs.oldKey == rhs.oldKey
&& lhs.name == rhs.name
}

}
Expand Down
7 changes: 6 additions & 1 deletion nRFMeshProvision/Mesh Model/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ extension Node: Equatable {

public static func == (lhs: Node, rhs: Node) -> Bool {
return lhs.uuid == rhs.uuid
}
&& lhs.isConfigComplete == rhs.isConfigComplete
&& lhs.isCompositionDataReceived == rhs.isCompositionDataReceived
&& lhs.isExcluded == rhs.isExcluded
&& lhs.name == rhs.name
&& lhs.defaultTTL == rhs.defaultTTL
}

}
8 changes: 4 additions & 4 deletions nRFMeshProvision/Mesh Model/Provisioner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ extension Provisioner: Equatable {

public static func == (lhs: Provisioner, rhs: Provisioner) -> Bool {
return lhs.uuid == rhs.uuid
}

public static func != (lhs: Provisioner, rhs: Provisioner) -> Bool {
return lhs.uuid != rhs.uuid
&& lhs.name == rhs.name
&& lhs.allocatedUnicastRange == rhs.allocatedUnicastRange
&& lhs.allocatedGroupRange == rhs.allocatedGroupRange
&& lhs.allocatedSceneRange == rhs.allocatedSceneRange
}

}
6 changes: 3 additions & 3 deletions nRFMeshProvision/Mesh Model/Publish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ import Foundation
/// To set the publication on a Model, send the ``ConfigModelPublicationSet`` or
/// ``ConfigModelPublicationVirtualAddressSet`` messages to the Configuration Server model
/// on the Node. The *Set* messages are confirmed with a ``ConfigModelPublicationStatus``.
public struct Publish: Codable {
public struct Publish: Codable, Equatable {
/// The configuration for disabling publication.
///
/// - since: 3.0
public static let disabled = Publish()

/// The object is used to describe the number of times a message is published and
/// the interval between retransmissions of the published message.
public struct Retransmit: Codable {
public struct Retransmit: Codable, Equatable {
/// Retransmission of published messages is disabled.
///
/// - since: 3.0
Expand Down Expand Up @@ -104,7 +104,7 @@ public struct Publish: Codable {
/// are periodically published by a Model.
///
/// - since: 3.0
public struct Period: Codable {
public struct Period: Codable, Equatable {
/// Periodic publishing of status messages is disabled.
///
/// - since: 3.0
Expand Down
3 changes: 2 additions & 1 deletion nRFMeshProvision/Mesh Model/Scene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Foundation
/// A Scene represents a set of states stored with a Scene Number.
///
/// A Scene is identified by a ``SceneNumber`` and may have a
/// human-reaadable name associated.
/// human-readable name associated.
///
/// A Node having a Scene Server model can store the states of other
/// models and restore them on demand.
Expand Down Expand Up @@ -159,6 +159,7 @@ extension Scene: Equatable, Hashable {

public static func == (lhs: Scene, rhs: Scene) -> Bool {
return lhs.number == rhs.number
&& lhs.name == rhs.name
}

public func hash(into hasher: inout Hasher) {
Expand Down

0 comments on commit bcf32f6

Please sign in to comment.