Set Class
Set Class
Set consist of a data set that contains values of the same type, where value is unique.
A Set is alway sorted on the value.
Contents
[hide][edit]How to use
[edit]Define
Set s = new Set(Types::STRING);
[edit]Insert a value
s.add("Wassini"); s.add("Eric");
[edit]Exists value
To see if a value already is added, use the in method:
if (s.in("Wassini")) print "Yes!"; else print "No!";
[edit]Getting values
There are several ways to get the values in the set.
- Using a SetIterator
- Using a SetEnumerator
[edit]SetIterator
The SetIterator loops throug the complete set:
SetIterator si; si = new SetIterator(s); while (si.more()) { print si.value(); si.next(); }
[edit]SetEnumerator
SetEnumerator class is like SetIterator class, but does not allows the deletion of elements during enumeration and SetIterator does.
SetEnumerator se=s.getEnumerator(); while (se.moveNext()) { print se.current(); }
[edit]Removing values
Just use the remove method to remove the active value.
s.remove("Wassini");
[edit]Other methods
// Get number of elements: print s.elements(); // Determines whether the set is empty: print s.empty(); // Get the type of the values print s.typeId(); // Get a description of the type of the elements: print s.definitionString(); // Dump the whole set as a string: print s.toString();
[edit]Passing across tiers
The Set can be passed across tiers by converting it to a container. The pack method converts it to a container:
container packedSet = s.pack();
To convert the packed container back to a Set, call the static create method of the Set class:
Set s = Set:create(packedSet);