Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions OSLC4Net_SDK/OSLC4Net.Client/Oslc/Resources/ParameterInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OSLC4Net.Client.Oslc.Resources;
[OslcResourceShape(title = "Parameter Instance Resource Shape",
describes = new string[] { AutomationConstants.TYPE_PARAMETER_INSTANCE })]
[OslcNamespace(AutomationConstants.AUTOMATION_NAMESPACE)]
public class ParameterInstance : AbstractResource
public class ParameterInstance : AbstractResource, IComparable<ParameterInstance>, IEquatable<ParameterInstance>
{

private string name;
Expand Down Expand Up @@ -138,8 +138,54 @@ public void SetServiceProvider(Uri serviceProvider)
this.serviceProvider = serviceProvider;
}

public int CompareTo(ParameterInstance o)
public int CompareTo(ParameterInstance? o)
{
return o.GetName().CompareTo(name);
if (o is null)
{
return 1;
}

var oName = o.GetName();
if (name is null && oName is null)
{
return 0;
}

if (oName is null)
{
return 1;
}

if (name is null)
{
return -1;
}

return string.Compare(name, oName, StringComparison.Ordinal);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

public bool Equals(ParameterInstance? other)
{
if (other is null)
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return CompareTo(other) == 0;
}

public override bool Equals(object? obj)
{
return Equals(obj as ParameterInstance);
}

public override int GetHashCode()
{
return name != null ? StringComparer.Ordinal.GetHashCode(name) : 0;
}
}
30 changes: 29 additions & 1 deletion OSLC4Net_SDK/OSLC4Net.Core/Model/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OSLC4Net.Core.Model;
[OslcNamespace(OslcConstants.OSLC_CORE_NAMESPACE)]
[OslcResourceShape(title = "OSLC Property Resource Shape",
describes = new[] { OslcConstants.TYPE_PROPERTY })]
public sealed class Property : AbstractResource, IComparable<Property>
public sealed class Property : AbstractResource, IComparable<Property>, IEquatable<Property>
{
private readonly IList<string> allowedValues = new List<string>();
private readonly List<Uri> range = new();
Expand Down Expand Up @@ -76,6 +76,34 @@ public int CompareTo(Property? o)
UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.Ordinal);
}

public bool Equals(Property? other)
{
if (other is null)
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return CompareTo(other) == 0;
}

public override bool Equals(object? obj)
{
return Equals(obj as Property);
}

public override int GetHashCode()
{
var nameHash = name != null ? StringComparer.Ordinal.GetHashCode(name) : 0;
var uriString = propertyDefinition?.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped);
var uriHash = uriString != null ? StringComparer.Ordinal.GetHashCode(uriString) : 0;
return HashCode.Combine(nameHash, uriHash);
}

public void AddAllowedValue(string allowedValue)
{
allowedValues.Add(allowedValue);
Expand Down
Loading