From 80811fc743aee7929577dfb6c2a056866a629ddb Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 13 Aug 2024 11:38:02 -0700 Subject: [PATCH 01/19] remove nullable project setting --- Consequences/Consequences.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Consequences/Consequences.csproj b/Consequences/Consequences.csproj index 72230e7..792da74 100644 --- a/Consequences/Consequences.csproj +++ b/Consequences/Consequences.csproj @@ -3,7 +3,6 @@ net8.0 enable - enable true From cb9a15e123a422448617e6b25b7da2ba91f762d6 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 13 Aug 2024 13:55:59 -0700 Subject: [PATCH 02/19] Created the HazardParameter enum #8 --- Consequences/HazardParameter.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Consequences/HazardParameter.cs diff --git a/Consequences/HazardParameter.cs b/Consequences/HazardParameter.cs new file mode 100644 index 0000000..68e3d74 --- /dev/null +++ b/Consequences/HazardParameter.cs @@ -0,0 +1,9 @@ +namespace Consequences; +public enum HazardParameter : long +{ + NoHazard, + Depth = 2, + Velocity = 4, + ArrivalTime = 8, + ArrivalTime2ft = 16 +} From 089d7b165462022df0fdc3d8516b6332eea46cdd Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 13 Aug 2024 15:37:28 -0700 Subject: [PATCH 03/19] Implemented the HazardParameter interface #9 --- Consequences/IHazardInterface.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Consequences/IHazardInterface.cs diff --git a/Consequences/IHazardInterface.cs b/Consequences/IHazardInterface.cs new file mode 100644 index 0000000..3ebd469 --- /dev/null +++ b/Consequences/IHazardInterface.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Consequences; +internal interface IHazardInterface +{ + internal bool Has(HazardParameter hp); + internal T Get(HazardParameter hp); +} From 008e88bb4bdc722550bb83b46253d50791612121 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 13 Aug 2024 15:43:01 -0700 Subject: [PATCH 04/19] changed internal to public for HazardInterface interface and its function signatures #9 --- Consequences/IHazardInterface.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Consequences/IHazardInterface.cs b/Consequences/IHazardInterface.cs index 3ebd469..b831e02 100644 --- a/Consequences/IHazardInterface.cs +++ b/Consequences/IHazardInterface.cs @@ -5,8 +5,8 @@ using System.Threading.Tasks; namespace Consequences; -internal interface IHazardInterface +public interface IHazardInterface { - internal bool Has(HazardParameter hp); - internal T Get(HazardParameter hp); + public bool Has(HazardParameter hp); + public T Get(HazardParameter hp); } From ed3307bb00fac40bf7ca9aefbc9b8bcd85c16214 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 13 Aug 2024 15:55:29 -0700 Subject: [PATCH 05/19] Implemented ResultItem generic class #10 --- Consequences/ResultItem.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Consequences/ResultItem.cs diff --git a/Consequences/ResultItem.cs b/Consequences/ResultItem.cs new file mode 100644 index 0000000..5b174cc --- /dev/null +++ b/Consequences/ResultItem.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Consequences; +public class ResultItem +{ + private string resultName; + private T result; + + public string Name() + { + return resultName; + } + public T Value() + { + return result; + } + +} From 773b62a673437997943cf81493441ddea07aa709 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 09:36:30 -0700 Subject: [PATCH 06/19] Removed lines auto filled by visual studio --- Consequences/Class1.cs | 6 ------ Consequences/IHazardInterface.cs | 8 +------- Consequences/Result.cs | 5 +++++ Consequences/ResultItem.cs | 11 ++--------- 4 files changed, 8 insertions(+), 22 deletions(-) delete mode 100644 Consequences/Class1.cs create mode 100644 Consequences/Result.cs diff --git a/Consequences/Class1.cs b/Consequences/Class1.cs deleted file mode 100644 index d41ed41..0000000 --- a/Consequences/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Consequences; - - public class Class1 - { - - } diff --git a/Consequences/IHazardInterface.cs b/Consequences/IHazardInterface.cs index b831e02..c100138 100644 --- a/Consequences/IHazardInterface.cs +++ b/Consequences/IHazardInterface.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Consequences; +namespace Consequences; public interface IHazardInterface { public bool Has(HazardParameter hp); diff --git a/Consequences/Result.cs b/Consequences/Result.cs new file mode 100644 index 0000000..63df5a2 --- /dev/null +++ b/Consequences/Result.cs @@ -0,0 +1,5 @@ +namespace Consequences; +public struct Result +{ + private ResultItem[] results; +} diff --git a/Consequences/ResultItem.cs b/Consequences/ResultItem.cs index 5b174cc..60539a7 100644 --- a/Consequences/ResultItem.cs +++ b/Consequences/ResultItem.cs @@ -1,22 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Consequences; +namespace Consequences; public class ResultItem { private string resultName; private T result; public string Name() - { + { return resultName; } public T Value() { return result; } - } From 306cfd8ce0c8cc139f7711cf29cfc3260bde2553 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 09:41:42 -0700 Subject: [PATCH 07/19] implemented the ConsequencesReceptor interface #12 --- Consequences/IConsequencesReceptorInterface.cs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Consequences/IConsequencesReceptorInterface.cs diff --git a/Consequences/IConsequencesReceptorInterface.cs b/Consequences/IConsequencesReceptorInterface.cs new file mode 100644 index 0000000..ae81839 --- /dev/null +++ b/Consequences/IConsequencesReceptorInterface.cs @@ -0,0 +1,5 @@ +namespace Consequences; +public interface IConsequencesReceptorInterface +{ + public Result Compute(IHazardInterface hi); +} From 763b559dda077e37ef4ccda0c92c4c374a351523 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 09:50:22 -0700 Subject: [PATCH 08/19] added constructor to ResultItem class #10 --- Consequences/ResultItem.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Consequences/ResultItem.cs b/Consequences/ResultItem.cs index 60539a7..758215d 100644 --- a/Consequences/ResultItem.cs +++ b/Consequences/ResultItem.cs @@ -4,6 +4,12 @@ public class ResultItem private string resultName; private T result; + public ResultItem(string name, T res) + { + resultName = name; + result = res; + } + public string Name() { return resultName; From 0e3b91c03e99888a90f299ce7eb9134a9923d69e Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 10:05:57 -0700 Subject: [PATCH 09/19] implemented a fetch method for ResultItem #11 --- Consequences/Result.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Consequences/Result.cs b/Consequences/Result.cs index 63df5a2..3dc7e03 100644 --- a/Consequences/Result.cs +++ b/Consequences/Result.cs @@ -2,4 +2,16 @@ public struct Result { private ResultItem[] results; + + public ResultItem Fetch(string name) + { + for (int i = 0; i < results.Length; i++) + { + if (results[i].Name() == name) + { + return results[i]; + } + } + return null; + } } From a8e80d1ad4beca6c9d7fe27ac6673f0278df9896 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 14:47:33 -0700 Subject: [PATCH 10/19] added [Flags] attribute b/c this is a bitflag enum #8 --- Consequences/HazardParameter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Consequences/HazardParameter.cs b/Consequences/HazardParameter.cs index 68e3d74..9abd15e 100644 --- a/Consequences/HazardParameter.cs +++ b/Consequences/HazardParameter.cs @@ -1,5 +1,6 @@ namespace Consequences; -public enum HazardParameter : long +[Flags] +public enum HazardParameter { NoHazard, Depth = 2, From 70b943fb73eb53c443b8103e42316ed967aa189b Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 15:59:38 -0700 Subject: [PATCH 11/19] changed backing int --- Consequences/HazardParameter.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Consequences/HazardParameter.cs b/Consequences/HazardParameter.cs index 9abd15e..03ebb2d 100644 --- a/Consequences/HazardParameter.cs +++ b/Consequences/HazardParameter.cs @@ -1,10 +1,10 @@ namespace Consequences; [Flags] -public enum HazardParameter +public enum HazardParameter // backed by an int by default { - NoHazard, - Depth = 2, - Velocity = 4, - ArrivalTime = 8, - ArrivalTime2ft = 16 + NoHazard = 0, + Depth = 1, + Velocity = 2, + ArrivalTime = 4, + ArrivalTime2ft = 8 } From 22ee348b42dbd87115b480225a94b58049a2689d Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Aug 2024 16:01:29 -0700 Subject: [PATCH 12/19] added generics --- Consequences/IConsequencesReceptorInterface.cs | 4 ++-- Consequences/IHazardInterface.cs | 2 +- Consequences/Result.cs | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Consequences/IConsequencesReceptorInterface.cs b/Consequences/IConsequencesReceptorInterface.cs index ae81839..8b1cd5e 100644 --- a/Consequences/IConsequencesReceptorInterface.cs +++ b/Consequences/IConsequencesReceptorInterface.cs @@ -1,5 +1,5 @@ namespace Consequences; -public interface IConsequencesReceptorInterface +public interface IConsequencesReceptor { - public Result Compute(IHazardInterface hi); + public Result Compute(IHazard hi); } diff --git a/Consequences/IHazardInterface.cs b/Consequences/IHazardInterface.cs index c100138..03aa53c 100644 --- a/Consequences/IHazardInterface.cs +++ b/Consequences/IHazardInterface.cs @@ -1,5 +1,5 @@ namespace Consequences; -public interface IHazardInterface +public interface IHazard { public bool Has(HazardParameter hp); public T Get(HazardParameter hp); diff --git a/Consequences/Result.cs b/Consequences/Result.cs index 3dc7e03..2f0fbff 100644 --- a/Consequences/Result.cs +++ b/Consequences/Result.cs @@ -1,9 +1,10 @@ namespace Consequences; -public struct Result +public struct Result { - private ResultItem[] results; + private ResultItem[] results; - public ResultItem Fetch(string name) + // retrieve a ResultItem from a Result by name + public ResultItem Fetch(string name) { for (int i = 0; i < results.Length; i++) { From 847d8cc868f32e42113ea6cccb4bdf3aa7bd358c Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 11:52:20 -0700 Subject: [PATCH 13/19] fixed namespaing --- Consequences/Consequences.csproj | 1 + .../Consequences/IConsequencesReceptorInterface.cs | 8 ++++++++ Consequences/HazardParameter.cs | 10 ---------- Consequences/Hazards/HazardParameter.cs | 10 ++++++++++ Consequences/{ => Hazards}/IHazardInterface.cs | 3 ++- Consequences/IConsequencesReceptorInterface.cs | 5 ----- Consequences/{ => Results}/Result.cs | 10 +++------- Consequences/{ => Results}/ResultItem.cs | 6 +++--- 8 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 Consequences/Consequences/IConsequencesReceptorInterface.cs delete mode 100644 Consequences/HazardParameter.cs create mode 100644 Consequences/Hazards/HazardParameter.cs rename Consequences/{ => Hazards}/IHazardInterface.cs (75%) delete mode 100644 Consequences/IConsequencesReceptorInterface.cs rename Consequences/{ => Results}/Result.cs (65%) rename Consequences/{ => Results}/ResultItem.cs (81%) diff --git a/Consequences/Consequences.csproj b/Consequences/Consequences.csproj index 792da74..a031e44 100644 --- a/Consequences/Consequences.csproj +++ b/Consequences/Consequences.csproj @@ -4,6 +4,7 @@ net8.0 enable true + USACE.HEC \ No newline at end of file diff --git a/Consequences/Consequences/IConsequencesReceptorInterface.cs b/Consequences/Consequences/IConsequencesReceptorInterface.cs new file mode 100644 index 0000000..11da7a5 --- /dev/null +++ b/Consequences/Consequences/IConsequencesReceptorInterface.cs @@ -0,0 +1,8 @@ +using USACE.HEC.Hazards; +using USACE.HEC.Results; + +namespace USACE.HEC.Consequences; +public interface IConsequencesReceptor +{ + public Result Compute(IHazard hi); +} diff --git a/Consequences/HazardParameter.cs b/Consequences/HazardParameter.cs deleted file mode 100644 index 03ebb2d..0000000 --- a/Consequences/HazardParameter.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Consequences; -[Flags] -public enum HazardParameter // backed by an int by default -{ - NoHazard = 0, - Depth = 1, - Velocity = 2, - ArrivalTime = 4, - ArrivalTime2ft = 8 -} diff --git a/Consequences/Hazards/HazardParameter.cs b/Consequences/Hazards/HazardParameter.cs new file mode 100644 index 0000000..2908694 --- /dev/null +++ b/Consequences/Hazards/HazardParameter.cs @@ -0,0 +1,10 @@ +namespace USACE.HEC.Hazards; +[Flags] +public enum HazardParameter // backed by an int by default +{ + NoHazard = 0, + Depth = 1, + Velocity = 2, + ArrivalTime = 4, + ArrivalTime2ft = 8 +} diff --git a/Consequences/IHazardInterface.cs b/Consequences/Hazards/IHazardInterface.cs similarity index 75% rename from Consequences/IHazardInterface.cs rename to Consequences/Hazards/IHazardInterface.cs index 03aa53c..5b6559b 100644 --- a/Consequences/IHazardInterface.cs +++ b/Consequences/Hazards/IHazardInterface.cs @@ -1,6 +1,7 @@ -namespace Consequences; +namespace USACE.HEC.Hazards; public interface IHazard { public bool Has(HazardParameter hp); public T Get(HazardParameter hp); } + \ No newline at end of file diff --git a/Consequences/IConsequencesReceptorInterface.cs b/Consequences/IConsequencesReceptorInterface.cs deleted file mode 100644 index 8b1cd5e..0000000 --- a/Consequences/IConsequencesReceptorInterface.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Consequences; -public interface IConsequencesReceptor -{ - public Result Compute(IHazard hi); -} diff --git a/Consequences/Result.cs b/Consequences/Results/Result.cs similarity index 65% rename from Consequences/Result.cs rename to Consequences/Results/Result.cs index 2f0fbff..a3fab32 100644 --- a/Consequences/Result.cs +++ b/Consequences/Results/Result.cs @@ -1,5 +1,5 @@ -namespace Consequences; -public struct Result +namespace USACE.HEC.Results; +public struct Result { private ResultItem[] results; @@ -7,12 +7,8 @@ public struct Result public ResultItem Fetch(string name) { for (int i = 0; i < results.Length; i++) - { - if (results[i].Name() == name) - { + if (results[i].Name() == name) return results[i]; - } - } return null; } } diff --git a/Consequences/ResultItem.cs b/Consequences/Results/ResultItem.cs similarity index 81% rename from Consequences/ResultItem.cs rename to Consequences/Results/ResultItem.cs index 758215d..3ce3004 100644 --- a/Consequences/ResultItem.cs +++ b/Consequences/Results/ResultItem.cs @@ -1,4 +1,4 @@ -namespace Consequences; +namespace USACE.HEC.Results; public class ResultItem { private string resultName; @@ -11,10 +11,10 @@ public ResultItem(string name, T res) } public string Name() - { + { return resultName; } - public T Value() + public T Value() { return result; } From 2084404eb55f4faa283c56d5f5eb5ea2a3082d5f Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 11:59:39 -0700 Subject: [PATCH 14/19] renamed interface files --- ...IConsequencesReceptorInterface.cs => IConsequencesReceptor.cs} | 0 Consequences/Hazards/{IHazardInterface.cs => IHazard.cs} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Consequences/Consequences/{IConsequencesReceptorInterface.cs => IConsequencesReceptor.cs} (100%) rename Consequences/Hazards/{IHazardInterface.cs => IHazard.cs} (100%) diff --git a/Consequences/Consequences/IConsequencesReceptorInterface.cs b/Consequences/Consequences/IConsequencesReceptor.cs similarity index 100% rename from Consequences/Consequences/IConsequencesReceptorInterface.cs rename to Consequences/Consequences/IConsequencesReceptor.cs diff --git a/Consequences/Hazards/IHazardInterface.cs b/Consequences/Hazards/IHazard.cs similarity index 100% rename from Consequences/Hazards/IHazardInterface.cs rename to Consequences/Hazards/IHazard.cs From 5e373786eee6d5774b19b6207711c4fe9322db63 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 13:06:29 -0700 Subject: [PATCH 15/19] removed generic from ConsequenceReceptor interface --- Consequences/Consequences/IConsequencesReceptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consequences/Consequences/IConsequencesReceptor.cs b/Consequences/Consequences/IConsequencesReceptor.cs index 11da7a5..de6ff61 100644 --- a/Consequences/Consequences/IConsequencesReceptor.cs +++ b/Consequences/Consequences/IConsequencesReceptor.cs @@ -4,5 +4,5 @@ namespace USACE.HEC.Consequences; public interface IConsequencesReceptor { - public Result Compute(IHazard hi); + public Result Compute(IHazard hi); } From 75023aa715cc7a8f487b6fef6a700926d05c28d1 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 13:07:06 -0700 Subject: [PATCH 16/19] changed ResultItem to struct --- Consequences/Results/ResultItem.cs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Consequences/Results/ResultItem.cs b/Consequences/Results/ResultItem.cs index 3ce3004..fae3e72 100644 --- a/Consequences/Results/ResultItem.cs +++ b/Consequences/Results/ResultItem.cs @@ -1,21 +1,6 @@ namespace USACE.HEC.Results; -public class ResultItem +public struct ResultItem { - private string resultName; - private T result; - - public ResultItem(string name, T res) - { - resultName = name; - result = res; - } - - public string Name() - { - return resultName; - } - public T Value() - { - return result; - } + public string ResultName; + public object Result; } From d57ca50ca9ba4f4bd03d738fce3f890c01bf6af8 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 13:07:34 -0700 Subject: [PATCH 17/19] changed Result to a class --- Consequences/Results/Result.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Consequences/Results/Result.cs b/Consequences/Results/Result.cs index a3fab32..be02e89 100644 --- a/Consequences/Results/Result.cs +++ b/Consequences/Results/Result.cs @@ -1,14 +1,14 @@ namespace USACE.HEC.Results; -public struct Result +public class Result { - private ResultItem[] results; + private ResultItem[] results; // retrieve a ResultItem from a Result by name - public ResultItem Fetch(string name) + public ResultItem Fetch(string name) { for (int i = 0; i < results.Length; i++) - if (results[i].Name() == name) + if (results[i].ResultName == name) return results[i]; - return null; + throw new Exception("Name not found."); } } From 1b681e3f501ace126138b2aca9b95c0bb9e7fbe4 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 13:37:59 -0700 Subject: [PATCH 18/19] removed generic --- Consequences/Consequences/IConsequencesReceptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consequences/Consequences/IConsequencesReceptor.cs b/Consequences/Consequences/IConsequencesReceptor.cs index de6ff61..ba9c1af 100644 --- a/Consequences/Consequences/IConsequencesReceptor.cs +++ b/Consequences/Consequences/IConsequencesReceptor.cs @@ -2,7 +2,7 @@ using USACE.HEC.Results; namespace USACE.HEC.Consequences; -public interface IConsequencesReceptor +public interface IConsequencesReceptor { public Result Compute(IHazard hi); } From 30be5066c62e3dc754ddd60baffb61bcd06ac257 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Aug 2024 13:40:15 -0700 Subject: [PATCH 19/19] added constructor and changed return if name not found --- Consequences/Results/Result.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Consequences/Results/Result.cs b/Consequences/Results/Result.cs index be02e89..55d1a05 100644 --- a/Consequences/Results/Result.cs +++ b/Consequences/Results/Result.cs @@ -1,14 +1,22 @@ namespace USACE.HEC.Results; public class Result { - private ResultItem[] results; + private ResultItem[] _results; + + public Result(ResultItem[] results) + { + _results = results; + } // retrieve a ResultItem from a Result by name public ResultItem Fetch(string name) { - for (int i = 0; i < results.Length; i++) - if (results[i].ResultName == name) - return results[i]; - throw new Exception("Name not found."); + for (int i = 0; i < _results.Length; i++) + if (_results[i].ResultName == name) + return _results[i]; + // return empty ResultItem if not found + ResultItem item = new ResultItem(); + item.ResultName = name; + return item; } }