add checks!
This commit is contained in:
parent
9dc55f8897
commit
46d01103c4
@ -14,7 +14,17 @@ class memoryManager():
|
|||||||
self.env = environment
|
self.env = environment
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
def listStorageValid(self,name, index = None):
|
||||||
|
try:
|
||||||
|
if index == None:
|
||||||
|
index = self.listStorage[name]['index']
|
||||||
|
return self.listStorage[name]['list'][index] != None
|
||||||
|
except e as Exception:
|
||||||
|
self.env['runtime']['debug'].writeDebugOut("listStorageValid " + str(e),debug.debugLevel.ERROR)
|
||||||
|
return False
|
||||||
def addValueToFirstIndex(self, name, value, index = 0):
|
def addValueToFirstIndex(self, name, value, index = 0):
|
||||||
|
if not self.listStorageValid(name, index):
|
||||||
|
return
|
||||||
if self.listStorage[name]['maxLength'] != None:
|
if self.listStorage[name]['maxLength'] != None:
|
||||||
self.listStorage[name]['list'] = [value] + self.listStorage[name]['list']
|
self.listStorage[name]['list'] = [value] + self.listStorage[name]['list']
|
||||||
else:
|
else:
|
||||||
@ -23,10 +33,16 @@ class memoryManager():
|
|||||||
def addIndexList(self, name, maxLength = None, currList = [], currIndex = 0):
|
def addIndexList(self, name, maxLength = None, currList = [], currIndex = 0):
|
||||||
self.listStorage[name] = {'list': currList, 'index': currIndex, 'maxLength': maxLength}
|
self.listStorage[name] = {'list': currList, 'index': currIndex, 'maxLength': maxLength}
|
||||||
def isLastIndex(self, name):
|
def isLastIndex(self, name):
|
||||||
return self.listStorage[name]['index'] == len(self.listStorage[name]['list']):
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
|
return self.listStorage[name]['index'] == len(self.listStorage[name]['list'])
|
||||||
def isFirstIndex(self, name):
|
def isFirstIndex(self, name):
|
||||||
return self.listStorage[name]['index'] == 0:
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
|
return self.listStorage[name]['index'] == 0
|
||||||
def getNextIndex(self, name):
|
def getNextIndex(self, name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
if self.isIndexListEmpty(name):
|
if self.isIndexListEmpty(name):
|
||||||
self.listStorage[name]['index'] = -1
|
self.listStorage[name]['index'] = -1
|
||||||
return False
|
return False
|
||||||
@ -35,25 +51,39 @@ class memoryManager():
|
|||||||
self.listStorage[name]['index'] = 0
|
self.listStorage[name]['index'] = 0
|
||||||
return True
|
return True
|
||||||
def setPrefIndex(self, name):
|
def setPrefIndex(self, name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
if self.isIndexListEmpty(name):
|
if self.isIndexListEmpty(name):
|
||||||
self.listStorage[name]['index'] = -1
|
self.listStorage[name]['index'] = -1
|
||||||
return False
|
return False
|
||||||
|
self.listStorage[name]['index'] += 1
|
||||||
|
if self.listStorage[name]['index'] < 0:
|
||||||
|
self.listStorage[name]['index'] = len(self.listStorage[name]['list']) -1
|
||||||
|
return True
|
||||||
def setFirstIndex(self, name):
|
def setFirstIndex(self, name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
if self.isIndexListEmpty(name):
|
if self.isIndexListEmpty(name):
|
||||||
self.listStorage[name]['index'] = -1
|
self.listStorage[name]['index'] = -1
|
||||||
return False
|
return False
|
||||||
self.listStorage[name]['index'] = 0
|
self.listStorage[name]['index'] = 0
|
||||||
return True
|
return True
|
||||||
def setLastIndex(self, name):
|
def setLastIndex(self, name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
if self.isIndexListEmpty(name):
|
if self.isIndexListEmpty(name):
|
||||||
self.listStorage[name]['index'] = -1
|
self.listStorage[name]['index'] = -1
|
||||||
return False
|
return False
|
||||||
self.listStorage[name]['index'] = self.listStorage[name]['list'] -1
|
self.listStorage[name]['index'] = self.listStorage[name]['list'] -1
|
||||||
return True
|
return True
|
||||||
def clearCurrentIndexList(self, name):
|
def clearCurrentIndexList(self, name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
self.listStorage[name]['index'] = []
|
self.listStorage[name]['index'] = []
|
||||||
self.listStorage[name]['index'] = -1
|
self.listStorage[name]['index'] = -1
|
||||||
def getCurrentIndex(self,name):
|
def getCurrentIndex(self,name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
if self.isIndexListEmpty(name):
|
if self.isIndexListEmpty(name):
|
||||||
self.listStorage[name]['index'] = -1
|
self.listStorage[name]['index'] = -1
|
||||||
return False
|
return False
|
||||||
@ -62,6 +92,8 @@ class memoryManager():
|
|||||||
except:
|
except:
|
||||||
retrun -1
|
retrun -1
|
||||||
def isIndexListEmpty(self, name):
|
def isIndexListEmpty(self, name):
|
||||||
|
if not self.listStorageValid(name):
|
||||||
|
return False
|
||||||
return len(self.listStorage[name]['list']) == 0
|
return len(self.listStorage[name]['list']) == 0
|
||||||
def getIndexListElement(self, name):
|
def getIndexListElement(self, name):
|
||||||
if self.isIndexListEmpty(name):
|
if self.isIndexListEmpty(name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user