Skip to content

Commit 61e867e

Browse files
author
Fraser Greenroyd
authored
Diffing_Engine: Align to changes from Id to ID (#3242)
2 parents ed7a416 + c64ec7e commit 61e867e

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

Diffing_Engine/Compute/DiffWithCustomIds.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,36 @@ public static Diff DiffWithCustomIds(List<object> pastObjects, List<string> past
7474
// "followingObjectsIds": Ids of the "followingObjects" that should be used to match them with the "pastObjects". If no match is found, a followingObject is identified as "added".
7575
// "diffingConfig": Additional configurations.
7676
// "recordEvents": Because this method can be called from many different places, some Notes/Warnings/Errors may not be relevant in all cases, so we give the option to turn them off.
77-
private static Diff Diffing(IEnumerable<object> pastObjects, IEnumerable<string> pastObjectsIds, IEnumerable<object> followingObjects, IEnumerable<string> followingObjectsIds, DiffingConfig diffingConfig = null, bool recordEvents = true)
77+
private static Diff Diffing(IEnumerable<object> pastObjects, IEnumerable<string> pastObjectsIDs, IEnumerable<object> followingObjects, IEnumerable<string> followingObjectsIDs, DiffingConfig diffingConfig = null, bool recordEvents = true)
7878
{
7979
// Null guards.
8080
if (pastObjects == null) pastObjects = new List<object>();
81-
if (pastObjectsIds == null) pastObjectsIds = new List<string>();
81+
if (pastObjectsIDs == null) pastObjectsIDs = new List<string>();
8282
if (followingObjects == null) followingObjects = new List<object>();
83-
if (followingObjectsIds == null) followingObjectsIds = new List<string>();
83+
if (followingObjectsIDs == null) followingObjectsIDs = new List<string>();
8484
if (diffingConfig == null) diffingConfig = new DiffingConfig();
8585
diffingConfig.ComparisonConfig = diffingConfig.ComparisonConfig.SetNewEmptyIEnumPropsIfNull();
8686

8787
// Check if we do not allow duplicate Ids
8888
// (we do not allow duplicate Ids by default – it may make sense in rare cases with Ids imported from some software that allows duplicates).
89-
if (!diffingConfig.AllowDuplicateIds)
89+
if (!diffingConfig.AllowDuplicateIDs)
9090
{
9191
// Take precautions if duplicate Ids are found.
9292
bool duplicateIdsFound = false;
9393

9494
// Get the distinct Ids from the input Id lists (do not admit duplicates).
95-
HashSet<string> pastObjsIdsDistinct = new HashSet<string>(pastObjectsIds);
96-
HashSet<string> follObjsIdsDistinct = new HashSet<string>(followingObjectsIds);
95+
HashSet<string> pastObjsIdsDistinct = new HashSet<string>(pastObjectsIDs);
96+
HashSet<string> follObjsIdsDistinct = new HashSet<string>(followingObjectsIDs);
9797

98-
if (pastObjsIdsDistinct.Count() != pastObjectsIds.Count())
98+
if (pastObjsIdsDistinct.Count() != pastObjectsIDs.Count())
9999
{
100-
if (recordEvents) BH.Engine.Base.Compute.RecordWarning($"Some of the input {nameof(pastObjectsIds)} were duplicate.");
100+
if (recordEvents) BH.Engine.Base.Compute.RecordWarning($"Some of the input {nameof(pastObjectsIDs)} were duplicate.");
101101
duplicateIdsFound = true;
102102
}
103103

104-
if (follObjsIdsDistinct.Count() != followingObjectsIds.Count())
104+
if (follObjsIdsDistinct.Count() != followingObjectsIDs.Count())
105105
{
106-
if (recordEvents) BH.Engine.Base.Compute.RecordWarning($"Some of the input {nameof(followingObjectsIds)} were duplicate.");
106+
if (recordEvents) BH.Engine.Base.Compute.RecordWarning($"Some of the input {nameof(followingObjectsIDs)} were duplicate.");
107107
duplicateIdsFound = true;
108108
}
109109

@@ -112,21 +112,21 @@ private static Diff Diffing(IEnumerable<object> pastObjects, IEnumerable<string>
112112
}
113113

114114
// Check if input objects and correspondent Id lists are of equal size.
115-
if (pastObjects.Count() != pastObjectsIds.Count())
115+
if (pastObjects.Count() != pastObjectsIDs.Count())
116116
{
117-
if (recordEvents) BH.Engine.Base.Compute.RecordError($"The number of input `{nameof(pastObjects)}` must be the same as the number of input `{nameof(pastObjectsIds)}`.");
117+
if (recordEvents) BH.Engine.Base.Compute.RecordError($"The number of input `{nameof(pastObjects)}` must be the same as the number of input `{nameof(pastObjectsIDs)}`.");
118118
return null;
119119
}
120120

121-
if (followingObjects.Count() != followingObjectsIds.Count())
121+
if (followingObjects.Count() != followingObjectsIDs.Count())
122122
{
123-
if (recordEvents) BH.Engine.Base.Compute.RecordError($"The number of input `{nameof(followingObjects)}` must be the same as the number of input `{nameof(followingObjectsIds)}`.");
123+
if (recordEvents) BH.Engine.Base.Compute.RecordError($"The number of input `{nameof(followingObjects)}` must be the same as the number of input `{nameof(followingObjectsIDs)}`.");
124124
return null;
125125
}
126126

127127
// Make dictionary with object ids to speed up/simplify the lookups.
128-
Dictionary<string, object> pastObjs_dict = pastObjectsIds.Zip(pastObjects, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
129-
Dictionary<string, object> follObjs_dict = followingObjectsIds.Zip(followingObjects, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
128+
Dictionary<string, object> pastObjs_dict = pastObjectsIDs.Zip(pastObjects, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
129+
Dictionary<string, object> follObjs_dict = followingObjectsIDs.Zip(followingObjects, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
130130

131131
// Dispatch the objects: new, modified or deleted
132132
List<object> addedObjs = new List<object>();
@@ -240,7 +240,7 @@ private static Diff Diffing(IEnumerable<object> pastObjects, IEnumerable<string>
240240
.Select(k => pastObjs_dict[k]).ToList();
241241

242242
// Add user warnings/notes for specific usage scenarios.
243-
if (!followingObjectsIds.Intersect(pastObjectsIds).Any())
243+
if (!followingObjectsIDs.Intersect(pastObjectsIDs).Any())
244244
{
245245
// If there is no overlap in the keys between the two sets, no "modified" object can have been detected.
246246
// This could be either because there are truly no modified objects, or more likely because the user has input objects that do not have a valid Id assigned.
@@ -265,7 +265,7 @@ private static Diff Diffing(IEnumerable<object> pastObjects, IEnumerable<string>
265265
$"\nThis can also happen if the input objects come from models that were completely re-created between revisions (i.e. their IDs are completely different). In this latter case, the Diffing worked successfully but you may want to use a different ID.");
266266
}
267267

268-
if (followingObjectsIds.Intersect(pastObjectsIds).Any() && diffingConfig.ComparisonConfig.PropertiesToConsider.Any() && !modifiedObjs.Any())
268+
if (followingObjectsIDs.Intersect(pastObjectsIDs).Any() && diffingConfig.ComparisonConfig.PropertiesToConsider.Any() && !modifiedObjs.Any())
269269
{
270270
// If no modified object was found and some PropertiesToConsider was specified,
271271
// add a Note to remind the user that if no differences were found it's probably because of that.

Diffing_Engine/Convert/TryParseObjectToGuid.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public static bool TryParseObjectToGuid(this object obj, out Guid guid)
6262
var sP = obj as StreamPointer;
6363
if (sP != null)
6464
{
65-
guid = sP.StreamId;
65+
guid = sP.StreamID;
6666
return true;
6767
}
6868

6969
// Check if it's a Revision, and extract the StreamId from there.
7070
var rev = obj as Revision;
7171
if (rev != null)
7272
{
73-
guid = rev.StreamId;
73+
guid = rev.StreamID;
7474
return true;
7575
}
7676

Diffing_Engine/Create/Delta.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public static partial class Create
4343
// ----------------------------------------------- //
4444

4545
[Description("Returns a Delta object with the Diff between the two input Revisions, also called `Diff-based Delta`.")]
46-
[Input("previousRevision", "A previous Revision")]
46+
[Input("pastRevision", "A previous Revision")]
4747
[Input("currentRevision", "A new Revision")]
48-
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
48+
[Input("diffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
4949
public static Delta Delta(Revision pastRevision, Revision currentRevision, DiffingConfig diffingConfig = null, string comment = null)
5050
{
5151
if(pastRevision == null)
@@ -62,7 +62,7 @@ public static Delta Delta(Revision pastRevision, Revision currentRevision, Diffi
6262

6363
Diff diff = Compute.DiffRevisions(pastRevision, currentRevision, diffingConfig);
6464

65-
return new Delta(pastRevision.StreamId, diff, pastRevision.RevisionId, currentRevision.RevisionId, DateTime.UtcNow.Ticks, m_Author, comment);
65+
return new Delta(pastRevision.StreamID, diff, pastRevision.RevisionID, currentRevision.RevisionID, DateTime.UtcNow.Ticks, m_Author, comment);
6666
}
6767

6868
// ----------------------------------------------- //
@@ -71,7 +71,7 @@ public static Delta Delta(Revision pastRevision, Revision currentRevision, Diffi
7171

7272
[Description("Returns a Delta object containing all the objects of the input Revision, also called `Revision-Based Delta`.")]
7373
[Input("revision", "A new Revision")]
74-
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
74+
[Input("diffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
7575
public static Delta Delta(Revision revision, DiffingConfig diffingConfig = null, string comment = null)
7676
{
7777
if(revision == null)
@@ -82,31 +82,32 @@ public static Delta Delta(Revision revision, DiffingConfig diffingConfig = null,
8282

8383
Diff diff = Compute.DiffRevisions(null, revision, diffingConfig);
8484

85-
return new Delta(revision.StreamId, diff, revision.RevisionId, new Guid(), DateTime.UtcNow.Ticks, m_Author, comment);
85+
return new Delta(revision.StreamID, diff, revision.RevisionID, new Guid(), DateTime.UtcNow.Ticks, m_Author, comment);
8686
}
8787

88+
[PreviousInputNames("streamID", "streamId")]
8889
[Description("Returns a Delta object, containing all the input objects wrapped in a Revision. Also called `Revision-Based Delta`.")]
8990
[Input("objects", "Objects that will be wrapped into a new Revision in order to produce this Delta.")]
90-
[Input("streamId", "Id of the Stream that will own the revision produced by this Delta.")]
91+
[Input("streamID", "Id of the Stream that will own the revision produced by this Delta.")]
9192
[Input("revisionName", "Name to be assigned to the Revision that this Delta will produce.")]
9293
[Input("comment", "Comment to be stored along the Revision that this Delta will produce.")]
93-
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
94-
public static Delta Delta(List<IBHoMObject> objects, object streamId, string revisionName = null,
94+
[Input("diffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
95+
public static Delta Delta(List<IBHoMObject> objects, object streamID, string revisionName = null,
9596
string comment = null, DiffingConfig diffingConfig = null)
9697
{
97-
Revision revision = Create.Revision(objects, streamId, revisionName, comment, diffingConfig);
98+
Revision revision = Create.Revision(objects, streamID, revisionName, comment, diffingConfig);
9899
return Delta(revision, diffingConfig, comment);
99100
}
100101

101102
[Description("Returns a Delta object based on the provided Diff.")]
102103
[Input("diff", "Diff that will be included in this Delta.")]
103-
[Input("streamId", "Id of the Stream that will own the revision produced by this Delta.")]
104-
[Input("revisionName", "Name to be assigned to the Revision that this Delta will produce.")]
104+
[Input("streamID", "ID of the Stream that will own the revision produced by this Delta.")]
105+
[Input("revisionFrom", "ID of revision this delta is going from..")]
105106
[Input("comment", "Comment to be stored along the Revision that this Delta will produce.")]
106-
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
107-
public static Delta Delta(Diff diff, object streamId, Guid revision_from, string comment = null, DiffingConfig diffingConfig = null)
107+
[Input("diffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
108+
public static Delta Delta(Diff diff, object streamID, Guid revisionFrom, string comment = null, DiffingConfig diffingConfig = null)
108109
{
109-
return new Delta(ProcessStreamId(streamId), diff, revision_from, new Guid(), DateTime.UtcNow.Ticks, m_Author, comment);
110+
return new Delta(ProcessStreamId(streamID), diff, revisionFrom, new Guid(), DateTime.UtcNow.Ticks, m_Author, comment);
110111
}
111112

112113
// ----------------------------------------------- //

0 commit comments

Comments
 (0)