Skip to content

Commit

Permalink
Make collection natively support duplicate elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco De Salvo committed Oct 4, 2024
1 parent 0f8fb19 commit 66b8201
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions RDFSharp.Test/Model/RDFCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void ShouldAddItemsToCollection(RDFModelEnums.RDFItemTypes itemType)
coll.AddItem(new RDFResource("http://item/"));
}

Assert.IsTrue(coll.ItemsCount == 1);
Assert.IsTrue(coll.ItemsCount == 2); //Duplicates are allowed (e.g.: OWL property chains)
Assert.IsFalse(coll.ReificationSubject.Equals(RDFVocabulary.RDF.NIL));
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public void ShouldNotRemoveItemsFromCollectionBecauseWrongType(RDFModelEnums.RDF
coll.RemoveItem(new RDFPlainLiteral("lit"));
}

Assert.IsTrue(coll.ItemsCount == 1);
Assert.IsTrue(coll.ItemsCount == 2);
Assert.IsFalse(coll.ReificationSubject.Equals(RDFVocabulary.RDF.NIL));
}

Expand All @@ -185,7 +185,7 @@ public void ShouldNotRemoveItemsFromCollectionBecauseNull(RDFModelEnums.RDFItemT
coll.RemoveItem(null as RDFResource);
}

Assert.IsTrue(coll.ItemsCount == 1);
Assert.IsTrue(coll.ItemsCount == 2);
Assert.IsFalse(coll.ReificationSubject.Equals(RDFVocabulary.RDF.NIL));
}

Expand Down
13 changes: 5 additions & 8 deletions RDFSharp/Model/RDFCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,11 @@ public RDFCollection AddItem(RDFLiteral item)
/// </summary>
internal void AddItemInternal(RDFPatternMember item)
{
if (Items.Find(x => x.Equals(item)) == null)
{
//Add item to collection
Items.Add(item);
//Update ReificationSubject (if collection has left "rdf:nil" configuration)
if (ItemsCount == 1)
ReificationSubject = InternalReificationSubject;
}
//Add item to collection
Items.Add(item);
//Update ReificationSubject (if collection has left "rdf:nil" configuration)
if (ItemsCount == 1)
ReificationSubject = InternalReificationSubject;
}
#endregion

Expand Down

0 comments on commit 66b8201

Please sign in to comment.