def __setitem__(self, index, value):
     if index<self._bound_1:
         raise IndexError("ARRAY index out of bound (lower bound is %i, passed %i)"%(self._bound_1,index))
     elif(index>self._bound_2):
         raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index))
     else:
         # first check the type of the value
         check_type(value,self.get_type())
         # then check if the value is already in the array
         if self._unique:
             if value in self._container:
                 raise AssertionError("UNIQUE keyword prevents inserting this instance.")
         self._container[index-self._bound_1] = value
 def add(self,value):
     '''
     Adds a value to the bag
     '''
     if self._unbounded:
         check_type(value,self.get_type())
         self._container.append(value)
     else:
         # first ensure that the bag is not full
         if len(self._container) == self._bound_2 - self._bound_1 + 1:
             raise AssertionError('BAG is full. Impossible to add any more item')
         else:
             check_type(value,self.get_type())
             self._container.append(value)
Beispiel #3
0
 def add(self, value):
     '''
     Adds a value to the bag
     '''
     if self._unbounded:
         check_type(value, self.get_type())
         self._container.append(value)
     else:
         # first ensure that the bag is not full
         if len(self._container) == self._bound_2 - self._bound_1 + 1:
             raise AssertionError(
                 'BAG is full. Impossible to add any more item')
         else:
             check_type(value, self.get_type())
             self._container.append(value)
Beispiel #4
0
 def __setitem__(self, index, value):
     if index < self._bound_1:
         raise IndexError(
             "ARRAY index out of bound (lower bound is %i, passed %i)" %
             (self._bound_1, index))
     elif (index > self._bound_2):
         raise IndexError(
             "ARRAY index out of bound (upper bound is %i, passed %i)" %
             (self._bound_2, index))
     else:
         # first check the type of the value
         check_type(value, self.get_type())
         # then check if the value is already in the array
         if self._unique:
             if value in self._container:
                 raise AssertionError(
                     "UNIQUE keyword prevents inserting this instance.")
         self._container[index - self._bound_1] = value
Beispiel #5
0
 def __setitem__(self, index, value):
     # case bounded
     if not self._unbounded:
         if index < self._bound_1:
             raise IndexError(
                 "ARRAY index out of bound (lower bound is %i, passed %i)" %
                 (self._bound_1, index))
         elif (index > self._bound_2):
             raise IndexError(
                 "ARRAY index out of bound (upper bound is %i, passed %i)" %
                 (self._bound_2, index))
         else:
             # first check the type of the value
             check_type(value, self.get_type())
             # then check if the value is already in the array
             if self._unique:
                 if value in self._container:
                     raise AssertionError(
                         "UNIQUE keyword prevent inserting this instance.")
             self._container[index - self._bound_1] = value
     # case unbounded
     else:
         if index < self._bound_1:
             raise IndexError(
                 "ARRAY index out of bound (lower bound is %i, passed %i)" %
                 (self._bound_1, index))
         # if the _container list is of good size, just do like the bounded case
         if (index - self._bound_1 < len(self._container)):
             # first check the type of the value
             check_type(value, self.get_type)
             # then check if the value is already in the array
             if self._unique:
                 if value in self._container:
                     raise AssertionError(
                         "UNIQUE keyword prevent inserting this instance.")
             self._container[index - self._bound_1] = value
         # in the other case, we have to extend the base _container list
         else:
             delta_size = (index - self._bound_1) - len(self._container) + 1
             #create a list of None, and extend the list
             list_extension = delta_size * [None]
             self._container.extend(list_extension)
             # first check the type of the value
             check_type(value, self.get_type())
             # then check if the value is already in the array
             if self._unique:
                 if value in self._container:
                     raise AssertionError(
                         "UNIQUE keyword prevent inserting this instance.")
             self._container[index - self._bound_1] = value
 def __setitem__(self, index, value):
     # case bounded
     if not self._unbounded:
         if index<self._bound_1:
             raise IndexError("ARRAY index out of bound (lower bound is %i, passed %i)"%(self._bound_1,index))
         elif(index>self._bound_2):
             raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index))
         else:
             # first check the type of the value
             check_type(value,self.get_type())
             # then check if the value is already in the array
             if self._unique:
                 if value in self._container:
                     raise AssertionError("UNIQUE keyword prevent inserting this instance.")
             self._container[index-self._bound_1] = value
     # case unbounded
     else:
         if index<self._bound_1:
             raise IndexError("ARRAY index out of bound (lower bound is %i, passed %i)"%(self._bound_1,index))
         # if the _container list is of good size, just do like the bounded case
         if (index-self._bound_1<len(self._container)):
             # first check the type of the value
             check_type(value,self.get_type)
             # then check if the value is already in the array
             if self._unique:
                 if value in self._container:
                     raise AssertionError("UNIQUE keyword prevent inserting this instance.")
             self._container[index-self._bound_1] = value
         # in the other case, we have to extend the base _container list
         else:
             delta_size = (index-self._bound_1) - len(self._container) + 1
             #create a list of None, and extend the list
             list_extension = delta_size*[None]
             self._container.extend(list_extension)
             # first check the type of the value
             check_type(value,self.get_type())
             # then check if the value is already in the array
             if self._unique:
                 if value in self._container:
                     raise AssertionError("UNIQUE keyword prevent inserting this instance.")
             self._container[index-self._bound_1] = value