def addRecord(self, newID, newGender, newAge, newSales, newBMI, newIncome, autoID, overwrite): typeCheckStringERR(newID) preppedID = None invalidID = False origRec = None insertPos = None overwriteSignal = 0 # will become 1 if overwriting will be used try: preppedID = self._prepID(newID) origRec, insertPos = self._prot_findRecord(preppedID) except InvalidIDException: invalidID = True if origRec is not None and overwrite: overwriteSignal = 1 elif (origRec is not None or invalidID) and autoID: preppedID, insertPos = self._autoID() # doNotUse, insertPos = self._prot_findRecord(preppedID) elif origRec is not None: raise DuplicateIDException() elif invalidID: raise InvalidIDException() newRec = Record(preppedID, newGender) self._allMyRecords[insertPos:insertPos + overwriteSignal] = [newRec] newRec.setAge(newAge) newRec.setSales(newSales) newRec.setBMI(newBMI) newRec.setIncome(newIncome)
def getValue(self, key): typeCheckStringERR(key) if not self._committed: raise EnumException() if key.upper() in self._values: return self._values[key.upper()] else: return self._default
def __init__(self, newID, newGender): typeCheckStringERR(newGender) gender = newGender.upper() if (gender != "M" and gender != "F"): raise InvalidGenderException() self._id = newID self._gender = gender self._age = LimitedInt(0, 99) self._sales = LimitedInt(0, 999) self._bmi = Record._enumBMI.getValue("") # default self._income = LimitedInt(0, 999)
def _prepID(self, theID): typeCheckStringERR(theID) if len(theID) != 4: raise InvalidIDException() prep = theID.upper() if prep[0] not in RecordCollection._letters: raise InvalidIDException() for x in range(1, 4): if prep[x] not in RecordCollection._numerals: raise InvalidIDException() return prep
def hasKey(self, key): typeCheckStringERR(key) if key.upper() in self._values: return True else: return False
def commit(self, default): typeCheckStringERR(default) if (not self._committed) and (default.upper() in self._values): self._committed = True self._default = self._values[default.upper()]
def addValue(self, newString): typeCheckStringERR(newString) if (not self._committed) and (newString.upper() not in self._values): self._values[newString.upper()] = newString