|
Class: HistoryCollection
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
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.
copyrightCOPYRIGHT (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.
defaults
-
defaultSizeLimit
-
instance creation
-
new
-
(comment from inherited method)
return an instance of myself without indexed variables
-
new: sizeLimit
-
(comment from inherited method)
return an instance of myself with anInteger indexed variables
accessing
-
at: index
-
(comment from inherited method)
return the indexed instance variable with index, anInteger;
this method can be redefined in subclasses.
-
mostRecentFirst
-
if true, the order is reversed
(affects enumeration).
For backward compatibility, the default is oldest first (do not change)
-
mostRecentFirst: aBoolean
-
if true, the order is reversed
(affects enumeration).
For backward compatibility, the default is oldest first
-
size
-
(comment from inherited method)
return the number of elements in the collection.
concrete implementations must define this
-
sizeLimit
-
-
sizeLimit: anInteger
-
Modified (format): / 17-07-2020 / 13:39:59 / cg
adding
-
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).
-
addFirst: anEntry
-
please only use add:
-
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
-
do: aBlock
-
(comment from inherited method)
evaluate the argument, aBlock for every element in the collection in
sequence order.
private
-
initializeWithSizeLimit: limitArg
-
|