Skip to content

Commit d11c7a9

Browse files
committed
[property] Add cardinality accessor methods
1 parent 9822545 commit d11c7a9

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

odml/property.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def __init__(self, name=None, values=None, parent=None, unit=None,
133133

134134
self.parent = parent
135135

136-
self._val_cardinality = val_cardinality
136+
self._val_cardinality = None
137+
self.val_cardinality = val_cardinality
137138

138139
for err in validation.Validation(self).errors:
139140
if err.is_error:
@@ -513,6 +514,34 @@ def dependency_value(self, new_value):
513514
new_value = None
514515
self._dependency_value = new_value
515516

517+
@property
518+
def val_cardinality(self):
519+
"""
520+
The value cardinality of a Property. It defines how many values
521+
are minimally required and how many values should be maximally
522+
stored. Use 'values_set_cardinality' to set.
523+
"""
524+
return self._val_cardinality
525+
526+
@val_cardinality.setter
527+
def val_cardinality(self, new_value):
528+
"""
529+
Sets the values cardinality of a Property.
530+
531+
The following cardinality cases are supported:
532+
(n, n) - default, no restriction
533+
(d, n) - minimally d entries, no maximum
534+
(n, d) - maximally d entries, no minimum
535+
(d, d) - minimally d entries, maximally d entries
536+
537+
Only positive integers are supported. 'None' is used to denote
538+
no restrictions on a maximum or minimum.
539+
540+
:param new_value: Can be either 'None', a positive integer, which will set the maximum
541+
or an integer 2-tuple of the format '(min, max)'.
542+
"""
543+
self._val_cardinality = new_value
544+
516545
def remove(self, value):
517546
"""
518547
Remove a value from this property. Only the first encountered

0 commit comments

Comments
 (0)