Skip to content

Commit

Permalink
use 'is (not) null' instead of '==/!=' for the comparison of referenc…
Browse files Browse the repository at this point in the history
…e types
  • Loading branch information
smdn committed Apr 2, 2024
1 parent a1eba23 commit f9f9911
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ IReadOnlyList<EchonetClassGroupSpecification> specs
/// <returns></returns>
public static SpecificationMaster GetInstance()
{
if (_Instance == null) {
if (_Instance is null) {
const string specificationMasterJsonFileName = "SpecificationMaster.json";

using (var stream = GetSpecificationMasterDataStream(specificationMasterJsonFileName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ private async ValueTask HandleInstanceListNotificationReceivedAsync(EchonetNode

foreach (var eoj in instanceList) {
var device = sourceNode.Devices.FirstOrDefault(d => d.EOJ == eoj);
if (device == null) {

if (device is null) {
device = new(eoj);
sourceNode.Devices.Add(device);
}
Expand Down Expand Up @@ -964,7 +965,7 @@ private void HandleFrameReceived(object? sender, (IPAddress address, Frame frame
var sourceNode = Nodes.SingleOrDefault(n => value.address is not null && value.address.Equals(n.Address));

//未知のノードの場合
if (sourceNode == null) {
if (sourceNode is null) {
//ノードを生成
sourceNode = new(
address: value.address,
Expand Down Expand Up @@ -1055,7 +1056,7 @@ private void HandleFrameReceived(object? sender, (IPAddress address, Frame frame
}

task?.ContinueWith((t) => {
if (t.Exception != null) {
if (t.Exception is not null) {
_logger?.LogTrace(t.Exception, "Exception");
}
});
Expand Down Expand Up @@ -1088,7 +1089,7 @@ private async Task<bool> HandlePropertyValueWriteRequestAsync((IPAddress address
if (edata.OPCList is null)
throw new InvalidOperationException($"{nameof(edata.OPCList)} is null");

if (destObject == null) {
if (destObject is null) {
//対象となるオブジェクト自体が存在しない場合には、「不可応答」も返さないものとする。
return false;
}
Expand Down Expand Up @@ -1166,7 +1167,7 @@ private async Task<bool> HandlePropertyValueWriteRequestResponseRequiredAsync((I
var hasError = false;
var opcList = new List<PropertyRequest>(capacity: edata.OPCList.Count);

if (destObject == null) {
if (destObject is null) {
//DEOJがない場合、全OPCをそのまま返す
hasError = true;
opcList.AddRange(edata.OPCList);
Expand Down Expand Up @@ -1256,7 +1257,7 @@ private async Task<bool> HandlePropertyValueReadRequest((IPAddress address, Fram
var hasError = false;
var opcList = new List<PropertyRequest>(capacity: edata.OPCList.Count);

if (destObject == null) {
if (destObject is null) {
//DEOJがない場合、全OPCをそのまま返す
hasError = true;
opcList.AddRange(edata.OPCList);
Expand Down Expand Up @@ -1352,7 +1353,7 @@ private async Task<bool> HandlePropertyValueWriteReadRequestAsync((IPAddress add
var opcSetList = new List<PropertyRequest>(capacity: edata.OPCSetList.Count);
var opcGetList = new List<PropertyRequest>(capacity: edata.OPCGetList.Count);

if (destObject == null) {
if (destObject is null) {
//DEOJがない場合、全OPCをそのまま返す
hasError = true;
opcSetList.AddRange(edata.OPCSetList);
Expand Down Expand Up @@ -1470,7 +1471,8 @@ private async Task<bool> HandlePropertyValueNotificationRequestAsync((IPAddress

var hasError = false;
var sourceObject = sourceNode.Devices.FirstOrDefault(d => d.EOJ == edata.SEOJ);
if (sourceObject == null) {

if (sourceObject is null) {
//ノードプロファイルからの通知の場合
if (sourceNode.NodeProfile.EOJ == edata.SEOJ) {
sourceObject = sourceNode.NodeProfile;
Expand All @@ -1482,6 +1484,7 @@ private async Task<bool> HandlePropertyValueNotificationRequestAsync((IPAddress
sourceNode.Devices.Add(sourceObject);
}
}

foreach (var opc in edata.OPCList) {
var property = sourceObject.Properties.FirstOrDefault(p => p.Spec.Code == opc.EPC);

Expand All @@ -1507,6 +1510,7 @@ private async Task<bool> HandlePropertyValueNotificationRequestAsync((IPAddress
await HandleInstanceListNotificationReceivedAsync(sourceNode, opc.EDT).ConfigureAwait(false);
}
}

return !hasError;
}

Expand Down Expand Up @@ -1540,15 +1544,15 @@ private async Task<bool> HandlePropertyValueNotificationResponseRequiredAsync((I
var hasError = false;
var opcList = new List<PropertyRequest>(capacity: edata.OPCList.Count);

if (destObject == null) {
if (destObject is null) {
//指定された DEOJ が存在しない場合には電文を廃棄する。
//"けどこっそり保持する"
hasError = true;
}

var sourceObject = sourceNode.Devices.FirstOrDefault(d => d.EOJ == edata.SEOJ);

if (sourceObject == null) {
if (sourceObject is null) {
//ノードプロファイルからの通知の場合
if (sourceNode.NodeProfile.EOJ == edata.SEOJ) {
sourceObject = sourceNode.NodeProfile;
Expand All @@ -1564,7 +1568,7 @@ private async Task<bool> HandlePropertyValueNotificationResponseRequiredAsync((I
foreach (var opc in edata.OPCList) {
var property = sourceObject.Properties.FirstOrDefault(p => p.Spec.Code == opc.EPC);

if (property == null) {
if (property is null) {
//未知のプロパティ
//新規作成
property = new(edata.SEOJ.ClassGroupCode, edata.SEOJ.ClassCode, opc.EPC);
Expand All @@ -1591,7 +1595,7 @@ private async Task<bool> HandlePropertyValueNotificationResponseRequiredAsync((I
opcList.Add(new(opc.EPC));
}

if (destObject != null) {
if (destObject is not null) {
await SendFrameAsync(
request.address,
buffer => FrameSerializer.SerializeEchonetLiteFrameFormat1(
Expand Down

0 comments on commit f9f9911

Please sign in to comment.