Class: WirisPlugin::HashCache

Inherits:
HashT
  • Object
show all
Includes:
Wiris
Defined in:
lib/com/wiris/util/type/HashCache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(maxSize) ⇒ HashCache

Returns a new instance of HashCache.



8
9
10
11
12
# File 'lib/com/wiris/util/type/HashCache.rb', line 8

def initialize(maxSize)
    super()
    self.maxSize = maxSize
    self.sortedKeys = Array.new()
end

Instance Attribute Details

#maxSizeObject

Returns the value of attribute maxSize.



6
7
8
# File 'lib/com/wiris/util/type/HashCache.rb', line 6

def maxSize
  @maxSize
end

#sortedKeysObject

Returns the value of attribute sortedKeys.



7
8
9
# File 'lib/com/wiris/util/type/HashCache.rb', line 7

def sortedKeys
  @sortedKeys
end

Instance Method Details

#getMaxSizeObject



13
14
15
# File 'lib/com/wiris/util/type/HashCache.rb', line 13

def getMaxSize()
    return self.maxSize
end

#getSortedKeysObject



19
20
21
# File 'lib/com/wiris/util/type/HashCache.rb', line 19

def getSortedKeys()
    return self.sortedKeys
end

#keysObject



28
29
30
# File 'lib/com/wiris/util/type/HashCache.rb', line 28

def keys()
    return self.sortedKeys::iterator()
end

#remove(key) ⇒ Object



22
23
24
25
26
27
# File 'lib/com/wiris/util/type/HashCache.rb', line 22

def remove(key)
    if self.sortedKeys::remove(key)
        return super(key)
    end
    return false
end

#set(key, value) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/com/wiris/util/type/HashCache.rb', line 31

def set(key, value)
    if (self.sortedKeys != nil) && (self.sortedKeys::length() >= self.maxSize)
        removed = self.sortedKeys::_(0)
        if self.sortedKeys::remove(removed)
            super(removed)
        end
    end
    self.sortedKeys::push(key)
    super(key,value)
end

#setMaxSize(maxSize) ⇒ Object



16
17
18
# File 'lib/com/wiris/util/type/HashCache.rb', line 16

def setMaxSize(maxSize)
    self.maxSize = maxSize
end