3232using System . Collections ;
3333using System . Collections . Generic ;
3434using System . Collections . Specialized ;
35+ using System . Data ;
3536using System . Globalization ;
3637using System . Linq ;
3738using System . Xml . Linq ;
@@ -171,7 +172,7 @@ public SortOrder OrderY
171172 /// <summary>
172173 /// Handles the event of CollectionChanged
173174 /// </summary>
174- public event NotifyCollectionChangedEventHandler CollectionChanged ;
175+ public event NotifyCollectionChangedEventHandler ? CollectionChanged ;
175176
176177 #endregion
177178
@@ -243,7 +244,12 @@ public UncertainOrderedPairedData(IList<UncertainOrdinate> data, bool strictOnX,
243244 _orderY = yOrder ;
244245 _uncertainOrdinates = new List < UncertainOrdinate > ( data . Count ) ;
245246 for ( int i = 0 ; i < data . Count ; i ++ )
246- _uncertainOrdinates . Add ( new UncertainOrdinate ( data [ i ] . X , data [ i ] . Y . Clone ( ) ) ) ;
247+ {
248+ var o = data [ i ] ;
249+ UnivariateDistributionBase ? yValue = o . Y ? . Clone ( ) ;
250+ if ( yValue is not null ) { _uncertainOrdinates . Add ( new UncertainOrdinate ( o . X , yValue ) ) ; }
251+ }
252+
247253 Validate ( ) ;
248254 }
249255
@@ -266,8 +272,12 @@ private UncertainOrderedPairedData(IList<UncertainOrdinate> data, bool strictOnX
266272 _orderY = yOrder ;
267273 _uncertainOrdinates = new List < UncertainOrdinate > ( data . Count ) ;
268274 for ( int i = 0 ; i < data . Count ; i ++ )
269- _uncertainOrdinates . Add ( new UncertainOrdinate ( data [ i ] . X , data [ i ] . Y . Clone ( ) ) ) ;
270-
275+ {
276+ var o = data [ i ] ;
277+ UnivariateDistributionBase ? yValue = o . Y ? . Clone ( ) ;
278+ if ( yValue is not null ) { _uncertainOrdinates . Add ( new UncertainOrdinate ( o . X , yValue ) ) ; }
279+ }
280+
271281 _isValid = dataValid ;
272282 }
273283
@@ -277,34 +287,44 @@ private UncertainOrderedPairedData(IList<UncertainOrdinate> data, bool strictOnX
277287 /// <param name="el">The XElement the UncertainOrderPairedData object is being created from.</param>
278288 public UncertainOrderedPairedData ( XElement el )
279289 {
290+ var strictX = el . Attribute ( "X_Strict" ) ;
280291 // Get Order
281- if ( el . Attribute ( "X_Strict" ) != null )
282- bool . TryParse ( el . Attribute ( "X_Strict" ) . Value , out _strictX ) ;
283- if ( el . Attribute ( "Y_Strict" ) != null )
284- bool . TryParse ( el . Attribute ( "Y_Strict" ) . Value , out _strictY ) ;
292+ if ( strictX != null ) { bool . TryParse ( strictX . Value , out _strictX ) ; }
293+
294+ var strictY = el . Attribute ( "Y_Strict" ) ;
295+ if ( strictY != null ) { bool . TryParse ( strictY . Value , out _strictY ) ; }
296+
285297 // Get Strictness
286- if ( el . Attribute ( "X_Order" ) != null )
287- Enum . TryParse ( el . Attribute ( "X_Order" ) . Value , out _orderX ) ;
288- if ( el . Attribute ( "Y_Order" ) != null )
289- Enum . TryParse ( el . Attribute ( "Y_Order" ) . Value , out _orderY ) ;
298+ var orderX = el . Attribute ( "X_Order" ) ;
299+ if ( orderX != null ) { Enum . TryParse ( orderX . Value , out _orderX ) ; }
300+
301+ var orderY = el . Attribute ( "Y_Order" ) ;
302+ if ( orderY != null ) { Enum . TryParse ( orderY . Value , out _orderY ) ; }
303+
290304 // Distribution type
291305 Distribution = UnivariateDistributionType . Deterministic ;
292- if ( el . Attribute ( "Distribution" ) != null )
306+ var distributionAttr = el . Attribute ( "Distribution" ) ;
307+ if ( distributionAttr != null )
293308 {
294309 var argresult = Distribution ;
295- Enum . TryParse ( el . Attribute ( "Distribution" ) . Value , out argresult ) ;
310+ Enum . TryParse ( distributionAttr . Value , out argresult ) ;
296311 Distribution = argresult ;
297312 }
298313 // new prop
299-
300- if ( el . Attribute ( nameof ( AllowDifferentDistributionTypes ) ) != null )
314+ var allowDiffAtr = el . Attribute ( nameof ( AllowDifferentDistributionTypes ) ) ;
315+ if ( allowDiffAtr != null )
301316 {
302- bool . TryParse ( el . Attribute ( nameof ( AllowDifferentDistributionTypes ) ) . Value , out _allowDifferentDistributionTypes ) ;
317+ bool . TryParse ( allowDiffAtr . Value , out _allowDifferentDistributionTypes ) ;
303318 // Get Ordinates
304319 var curveEl = el . Element ( "Ordinates" ) ;
305320 _uncertainOrdinates = new List < UncertainOrdinate > ( ) ;
306- foreach ( XElement ord in curveEl . Elements ( nameof ( UncertainOrdinate ) ) )
307- _uncertainOrdinates . Add ( new UncertainOrdinate ( ord ) ) ;
321+
322+ if ( curveEl != null )
323+ {
324+ foreach ( XElement ord in curveEl . Elements ( nameof ( UncertainOrdinate ) ) )
325+ _uncertainOrdinates . Add ( new UncertainOrdinate ( ord ) ) ;
326+ }
327+
308328 }
309329 else
310330 {
@@ -315,15 +335,19 @@ public UncertainOrderedPairedData(XElement el)
315335 {
316336 foreach ( XElement o in curveEl . Elements ( "Ordinate" ) )
317337 {
318- double . TryParse ( o . Attribute ( "X" ) . Value , NumberStyles . Any , CultureInfo . InvariantCulture , out var xout ) ;
319- xData . Add ( xout ) ;
338+ var xAttr = o . Attribute ( "X" ) ;
339+ if ( xAttr != null && double . TryParse ( xAttr . Value , NumberStyles . Any , CultureInfo . InvariantCulture , out var xout ) ) { xData . Add ( xout ) ; }
340+ else { xData . Add ( 0.0 ) ; }
341+
320342 var dist = UnivariateDistributionFactory . CreateDistribution ( Distribution ) ;
321343 var props = dist . GetParameterPropertyNames ;
322344 var paramVals = new double [ ( props . Count ( ) ) ] ;
345+
323346 for ( int i = 0 ; i < props . Count ( ) ; i ++ )
324347 {
325- double . TryParse ( o . Attribute ( props [ i ] ) . Value , NumberStyles . Any , CultureInfo . InvariantCulture , out var result ) ;
326- paramVals [ i ] = result ;
348+ var pAttr = o . Attribute ( props [ i ] ) ;
349+ if ( pAttr != null && double . TryParse ( pAttr . Value , NumberStyles . Any , CultureInfo . InvariantCulture , out var result ) ) { paramVals [ i ] = result ; }
350+ else { paramVals [ i ] = 0.0 ; }
327351 }
328352
329353 dist . SetParameters ( paramVals ) ;
@@ -488,7 +512,14 @@ public List<string> GetErrors()
488512 {
489513 if ( left . _uncertainOrdinates [ i ] . X != right . _uncertainOrdinates [ i ] . X )
490514 return false ;
491- if ( left . _uncertainOrdinates [ i ] . Y == right . _uncertainOrdinates [ i ] . Y == false )
515+
516+ var leftY = left . _uncertainOrdinates [ i ] . Y ;
517+ var rightY = right . _uncertainOrdinates [ i ] . Y ;
518+ if ( leftY is null && rightY is null )
519+ continue ;
520+ if ( leftY is null || rightY is null )
521+ return false ;
522+ if ( ! leftY . Equals ( rightY ) )
492523 return false ;
493524 }
494525 return true ;
@@ -510,7 +541,7 @@ public List<string> GetErrors()
510541 /// </summary>
511542 /// <param name="obj">The object to compare with the current object.</param>
512543 /// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
513- public override bool Equals ( object obj )
544+ public override bool Equals ( object ? obj )
514545 {
515546 if ( obj is UncertainOrderedPairedData other )
516547 {
0 commit comments