@@ -126,16 +126,64 @@ def __setitem__(self, index, value):
126126 raise AssertionError ("UNIQUE keyword prevent inserting this instance." )
127127 self ._container [index - self ._bound_1 ] = value
128128
129- class LIST (list , BaseAggregate ):
129+ class LIST (object ):
130130 """A list data type has as its domain sequences of like elements. The optional lower and upper
131131 bounds, which are integer-valued expressions, define the minimum and maximum number of
132132 elements that can be held in the collection defined by a list data type.
133133 A list data type
134134 definition may optionally specify that a list value cannot contain duplicate elements.
135135 """
136- def __init__ ( self , bound1 , bound2 , base_type ):
137- BaseAggregate .__init__ ( self , bound1 , bound2 , base_type )
136+ def __init__ ( self , bound_1 , bound_2 , base_type , UNIQUE = False ):
137+ if not type (bound_1 )== int :
138+ raise TypeError ("LIST lower bound must be an integer" )
139+ # bound_2 can be set to None
140+ if not type (bound_2 )== int :
141+ raise TypeError ("LIST upper bound must be an integer" )
142+ if not bound_1 >= 0 :
143+ raise AssertionError ("LIST lower bound must be greater of equal to 0" )
144+ if not (bound_1 <= bound_2 ):
145+ raise AssertionError ("ARRAY lower bound must be less than or equal to upper bound" )
146+ # set up class attributes
147+ self ._bound_1 = bound_1
148+ self ._bound_2 = bound_2
149+ self ._base_type = base_type
150+ self ._unique = UNIQUE
151+ self ._optional = OPTIONAL
152+ # preallocate list elements
153+ list_size = bound_2 - bound_1 + 1
154+ self ._container = list_size * [None ]
138155
156+ def bound_1 (self ):
157+ return self ._bound_1
158+
159+ def bound_2 (self ):
160+ return self ._bound_2
161+
162+ def __getitem__ (self , index ):
163+ if index < self ._bound_1 :
164+ raise IndexError ("ARRAY index out of bound (lower bound is %i, passed %i)" % (self ._bound_1 ,index ))
165+ elif (index > self ._bound_2 ):
166+ raise IndexError ("ARRAY index out of bound (upper bound is %i, passed %i)" % (self ._bound_2 ,index ))
167+ else :
168+ value = self ._container [index - self ._bound_1 ]
169+ if not self ._optional and value == None :
170+ raise AssertionError ("Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first." % index )
171+ return value
172+
173+ def __setitem__ (self , index , value ):
174+ if index < self ._bound_1 :
175+ raise IndexError ("ARRAY index out of bound (lower bound is %i, passed %i)" % (self ._bound_1 ,index ))
176+ elif (index > self ._bound_2 ):
177+ raise IndexError ("ARRAY index out of bound (upper bound is %i, passed %i)" % (self ._bound_2 ,index ))
178+ else :
179+ # first check the type of the value
180+ check_type (value ,self ._base_type )
181+ # then check if the value is already in the array
182+ if self ._unique :
183+ if value in self ._container :
184+ raise AssertionError ("UNIQUE keyword prevent inserting this instance." )
185+ self ._container [index - self ._bound_1 ] = value
186+
139187class BAG (tuple , BaseAggregate ):
140188 """A bag data type has as its domain unordered collections of like elements. The optional lower
141189 and upper bounds, which are integer-valued expressions, dene the minimum and maximum
0 commit comments