eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'HistoryCollection':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: HistoryCollection


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--HistoryCollection
            |
            +--HistoryCollectionWithoutDuplicates

Package:
stx:libbasic2
Category:
Collections-Sequenceable
Version:
rev: 1.10 date: 2023/12/19 15:45:39
user: cg
file: HistoryCollection.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


I am like an OrderedCollection, but when an entry is added,
I will check my size and remove the oldest entry.
Thus keeping only the N newest added entries.
An alternative name could have been LeastRecentlyUsedCollection or LRUCollection.

Useful for history of recent messages.

    |h|

    h := HistoryCollection new:10.
    h addAll:(1 to:10).
    Transcript showCR:h.
    h addAll(11 to:15).
    Transcript showCR:h.
    h addAll(16 to:20).
    Transcript showCR:h.

or recently used files.
    |h|

    h := HistoryCollection new:10.
    h mostRecentFirst:true.
    h addAll:(1 to:10).
    Transcript showCR:h.
    h add:5.
    Transcript showCR:h.
    h add:1.
    Transcript showCR:h.
    h addAll(11 to:15).
    Transcript showCR:h.
    h addAll(16 to:20).
    Transcript showCR:h.

copyright

COPYRIGHT (c) 2020 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

defaults
o  defaultSizeLimit

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables

o  new: sizeLimit
(comment from inherited method)
return an instance of myself with anInteger indexed variables


Instance protocol:

accessing
o  at: index
(comment from inherited method)
return the indexed instance variable with index, anInteger;
this method can be redefined in subclasses.

o  mostRecentFirst
if true, the order is reversed
(affects enumeration).
For backward compatibility, the default is oldest first (do not change)

o  mostRecentFirst: aBoolean
if true, the order is reversed
(affects enumeration).
For backward compatibility, the default is oldest first

o  size
(comment from inherited method)
return the number of elements in the collection.
concrete implementations must define this

o  sizeLimit

o  sizeLimit: anInteger
Modified (format): / 17-07-2020 / 13:39:59 / cg

adding
o  add: anEntry
(comment from inherited method)
append the argument, anObject to the collection.
Return the argument, anObject.

Notice that this modifies the receiver, NOT a copy.
Also note that it may be a slow operation for some collections,
due to the grow:-message, which is inefficient for fixed size
collections (i.e. for Strings and Arrays it is not recommended).

o  addFirst: anEntry
please only use add:

o  removeLast
(comment from inherited method)
remove the last element of the receiver and return it.

Notice that this modifies the receiver, NOT a copy.
Also note that it may be a slow operation for some collections,
due to the grow:-message, which is inefficient for fixed size
collections (i.e. for Strings and Arrays it is not recommended).

enumerating
o  do: aBlock
(comment from inherited method)
evaluate the argument, aBlock for every element in the collection in
sequence order.

private
o  initializeWithSizeLimit: limitArg



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 08 Sep 2024 03:01:10 GMT