5252 NumNodes
5353 NumTypes
5454 end
55-
55+
5656 properties (SetAccess = protected )
5757 % Nodes - Dictionary storing instances as values with identifiers
5858 % as keys
6767
6868 properties (SetAccess = protected )
6969 LinkResolver
70-
70+
7171 % MetadataStore - Optional metadata store for saving/loading
7272 MetadataStore openminds.interface.MetadataStore = openminds.internal.FileMetadataStore.empty
7373 end
74-
74+
7575 methods % Constructor
7676 function obj = Collection(instance , options )
7777 % Create an instance of an openMINDS collection
9898 % creates a collection with the specified metadata store. If no
9999 % instances are provided, the collection will automatically load
100100 % instances from the store.
101-
101+
102102 % collection = openminds.Collection(..., NameA, ValueA, ... )
103103 % also specifies optional name value pairs when creating the
104104 % collection.
107107 % - Name : A name for the collection
108108 % - Description : A description of the collection
109109 % - MetadataStore : A metadata store for saving/loading instances
110-
110+
111111 arguments (Repeating )
112112 instance % openminds.abstract.Schema
113113 end
127127 obj.Nodes = containers .Map ;
128128 obj.TypeMap = containers .Map ;
129129 end
130-
130+
131131 obj .initializeFromInstances(instance )
132132
133133 obj.Name = options .Name ;
134134 obj.Description = options .Description ;
135135 obj.MetadataStore = options .MetadataStore ;
136-
136+
137137 % Auto-load from MetadataStore if provided and no instances given
138138 if isempty(instance ) && ~isempty(obj .MetadataStore )
139139 obj .load();
149149 numNodes = length(obj .Nodes );
150150 end
151151 end
152-
152+
153153 function numTypes = get .NumTypes(obj )
154154 if isa(obj .TypeMap , ' dictionary' )
155155 numTypes = numEntries(obj .TypeMap );
@@ -203,7 +203,7 @@ function add(obj, instance, options)
203203 end
204204 end
205205 end
206-
206+
207207 function tf = contains(obj , instance )
208208 % Todo:work for arrays
209209 tf = false ;
@@ -214,10 +214,10 @@ function add(obj, instance, options)
214214 end
215215 end
216216 end
217-
217+
218218 function remove(obj , instance )
219219 % remove - Remove metadata instance from the collection
220-
220+
221221 if isstring(instance ) || ischar(instance )
222222 instanceId = instance ;
223223 elseif openminds .utility .isInstance(instance )
@@ -254,11 +254,11 @@ function remove(obj, instance)
254254 instance = instance{1 };
255255 end
256256 end
257-
257+
258258 function instances = getAll(obj )
259259 % getAll - Get all instances of collection
260260 instances = obj .Nodes .values();
261-
261+
262262 % For older MATLAB releases, the instances might be nested a
263263 % cell array, need to unnest if that's the case:
264264 if iscell(instances{1 })
@@ -273,11 +273,11 @@ function remove(obj, instance)
273273 end
274274
275275 tf = false ;
276-
276+
277277 if obj .NumNodes == 0
278278 return
279279 end
280-
280+
281281 typeKeys = obj .TypeMap .keys ;
282282 tf = any( endsWith(typeKeys , " ." +type ) ); % i.e ".Person"
283283 end
@@ -297,10 +297,10 @@ function remove(obj, instance)
297297 if obj .NumNodes == 0
298298 return
299299 end
300-
300+
301301 instanceKeys = obj .getInstanceKeysForType(type );
302302 if isempty(instanceKeys ); return ; end
303-
303+
304304 if isa(obj .Nodes , ' dictionary' )
305305 instances = obj .Nodes(instanceKeys );
306306 else
@@ -368,22 +368,22 @@ function updateLinks(obj)
368368 % ------
369369 %
370370 % outputPaths (cell): A list of the file paths created.
371-
371+
372372 arguments
373373 obj openminds.Collection
374374 savePath (1 ,1 ) string = " "
375375 options.MetadataStore openminds.interface.MetadataStore = openminds.internal.FileMetadataStore.empty
376376 % options.SaveFormat = "jsonld" Implement if more formats are supported
377377 end
378-
378+
379379 % Update links before saving
380380 obj .updateLinks()
381381 instances = obj .getAll();
382382
383383 if savePath ~= " "
384384 tempStore = openminds .internal .store .createTemporaryStore(savePath );
385385 outputPaths = tempStore .save(instances );
386-
386+
387387 elseif ~isempty(options .MetadataStore )
388388 outputPaths = obj .MetadataStore .save(instances );
389389
@@ -395,7 +395,7 @@ function updateLinks(obj)
395395 error(' openminds:Collection:NoSavePath' , ...
396396 ' Either provide savePath or configure a MetadataStore' );
397397 end
398-
398+
399399 if ~nargout
400400 clear outputPaths
401401 end
@@ -444,7 +444,7 @@ function load(obj, loadPath, options)
444444 error(' openminds:Collection:PathNotFound' , ' Path not found: %s ' , loadPath );
445445 end
446446 end
447-
447+
448448 for i = 1 : numel(instances )
449449 if openminds .utility .isInstance(instances{i })
450450 obj .addNode(instances{i });
@@ -477,13 +477,13 @@ function load(obj, loadPath, options)
477477 % --------
478478 % collection : openminds.Collection
479479 % A new collection loaded with instances from the store
480-
480+
481481 arguments
482482 metadataStore (1 ,1 ) openminds.interface.MetadataStore
483483 options.Name (1 ,1 ) string = " "
484484 options.Description (1 ,1 ) string = " "
485485 end
486-
486+
487487 % Create collection with the metadata store
488488 collection = openminds .Collection(' MetadataStore' , metadataStore , ...
489489 ' Name' , options .Name , ' Description' , options .Description );
@@ -501,7 +501,7 @@ function load(obj, loadPath, options)
501501 end
502502
503503 wasAdded = false ;
504-
504+
505505 if isempty(instance .id )
506506 instance.id = obj .getBlankNodeIdentifier();
507507 end
@@ -544,12 +544,12 @@ function load(obj, loadPath, options)
544544 obj .TypeMap(instanceType ) = {string(instance .id )};
545545 end
546546 end
547-
547+
548548 if ~nargout
549549 clear wasAdded
550550 end
551551 end
552-
552+
553553 % Add sub node instances (linked types) to the Node container.
554554 function addSubNodes(obj , instance )
555555 % Add links.
@@ -566,7 +566,7 @@ function addSubNodes(obj, instance)
566566 obj .addNode(embeddedInstances{i }, ' AddSubNodesOnly' , true );
567567 end
568568 end
569-
569+
570570 function identifier = getBlankNodeIdentifier(obj )
571571 fmt = ' _:%06d ' ;
572572 identifier = length(obj ) + 1 ;
@@ -581,19 +581,19 @@ function initializeFromInstances(obj, instance)
581581 isFilePath = @(x ) (ischar(x ) || isstring(x )) && isfile(x );
582582 isFolderPath = @(x ) (ischar(x ) || isstring(x )) && isfolder(x );
583583 isMetadata = @(x ) openminds .utility .isInstance(x );
584-
584+
585585 % Initialize from file(s)
586586 if all( cellfun(isFilePath , instance ) )
587587 obj .load(instance{: })
588-
588+
589589 % Initialize from folder
590590 elseif all( cellfun(isFolderPath , instance ) )
591591 obj .load(instance{: })
592-
592+
593593 % Initialize from instance(s)
594594 elseif all( cellfun(isMetadata , instance ) )
595595 obj .add(instance{: });
596-
596+
597597 else
598598 ME = MException(...
599599 ' OPENMINDS_MATLAB:Collection:InvalidInstanceSpecification' , ...
@@ -611,7 +611,7 @@ function initializeFromInstances(obj, instance)
611611
612612 if obj .NumTypes > 0
613613 typeKeys = obj .TypeMap .keys ;
614-
614+
615615 isMatch = strcmp(typeKeys , instanceType .ClassName );
616616 if any(isMatch )
617617 if isa(obj .TypeMap , ' dictionary' )
@@ -629,9 +629,9 @@ function initializeFromInstances(obj, instance)
629629 instanceKeys = {};
630630 return
631631 end
632-
632+
633633 existingKeys = obj .Nodes .keys();
634-
634+
635635 % Sanity check, make sure all keys exist in Nodes dictionary
636636 assert( all( ismember( instanceKeys , existingKeys ) ), ...
637637 ' TypeMap has too many keys' )
0 commit comments