Skip to content
Reference > Classes

Set

Definition

Set var = .... ;

Extends

Extended By

None

Description

A mutable collection of unique data entries. Attempts to add duplicates will be ignored. Entries are stored in the order inserted (Backed by Java LinkedHashSet)

Method Summary

Owner Name Return Type Description
Set constructor(value) Set Construct a new set, duplicate values will be omitted
Set add(values) Boolean Adds all supplied values if they don't already exist. Returns "true" if the set changed as a result of this call, "false" if not.
Collection addAll(valuesToAdd) Object Adds all elements contained in the iterable to this collection
Collection clear() Boolean Removes all elements in this collection. Returns "true" if this operation removed at least 1 element, returns "false" if it was empty.
Set contains(value) Boolean Returns true if the set contains ANY of the supplied values
Object getClassName() String Returns the string name of this object's class type.
Iterable iterator() Iterator Returns an iterator over this container's objects. Methods are defined in the Iterator class.
Set remove(values) Boolean Remove all supplied values if they exist. Returns true if the set changed as a result of this call.
Collection size() Integer Returns the size of this collection
Collection sort() List Returns a sorted list of the specified collection. Sorting is done according to the elements' type's natural ordering. This sort is guaranteed to be stable, equal elements will not be reordered as a result of the sort.
Object toJson() String Returns a string of a json representation of this object.
Set venn(otherSet, inThis, inOther, inBoth) Set Returns a new set of values which is a combination of this set and the other set according to the Boolean flags set by the user. Each Boolean flag determines which portions of the Venn diagram are included in the final set.

Method Definitions


constructor(value)

Set set = new Set(Object ... value)

Description

Construct a new set, duplicate values will be omitted

Parameter Definition

Name Type Description
value Object ...  values contained in set

Example 1

1
2
3
Set s = new Set("a","b","c");

// s = [a, b, c]

Example 2

1
2
3
Set s = new Set("a", "a", "b", null);

// s = [a, b, null]

add(values)

Boolean Set::add(Object ... values)

Description

Adds all supplied values if they don't already exist. Returns "true" if the set changed as a result of this call, "false" if not.

Parameter Definition

Name Type Description
values Object ...  values to add

Example 1

1
2
3
4
Set s = new Set("a","b","c");
s.add("a");

// s = [a, b, c]

Example 2

1
2
3
4
Set s = new Set("a","b","c");
s.add("d");

// s = [a, b, c, d]

addAll(valuesToAdd)

Object Collection::addAll(Iterable valuesToAdd)

Description

Adds all elements contained in the iterable to this collection

Parameter Definition

Name Type Description
valuesToAdd Iterable  The values to add to this collection

Example 2

1
2
3
4
5
Set s1 = new Set("a","b","c");
Set s2 = new Set("c","d");
Set s = s1.addAll(s2);

// s = [a, b, c, d]

clear()

Boolean Collection::clear()

Description

Removes all elements in this collection. Returns "true" if this operation removed at least 1 element, returns "false" if it was empty.

Example 2

1
2
3
4
Set s = new Set("a","b","c");
s.clear();

// s = []

contains(value)

Boolean Set::contains(Object ... value)

Description

Returns true if the set contains ANY of the supplied values

Parameter Definition

Name Type Description
value Object ...  value(s) to check

Example 1

1
2
3
4
5
6
Set s = new Set("a","b","c");
s.contains("a");
s.contains("d");

// s.contains("a") = true
// s.contains("d") = false

getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.

Example 11

1
2
3
4
Set s = new Set("a", "b", "c");
s.getClassName();

// s.getClassName() = Set

iterator()

Iterator Iterable::iterator()

Description

Returns an iterator over this container's objects. Methods are defined in the Iterator class.

Example 1

1
2
3
4
5
6
7
8
Set s = new Set("3","f","o","r","g","e");
Iterator i = s.iterator();
string temp = "";
while(i.hasNext()) { 
    temp += i.next();
}
// i.hasNext() = false
// temp = 3forge

remove(values)

Boolean Set::remove(Object ... values)

Description

Remove all supplied values if they exist. Returns true if the set changed as a result of this call.

Parameter Definition

Name Type Description
values Object ...  values to remove

Example 1

1
2
3
4
Set s = new Set("a","b","c","d");
s.remove("d");

// s = [a, b, c]

size()

Integer Collection::size()

Description

Returns the size of this collection

Example 2

1
2
3
4
Set s = new Set("a","b","c");
s.size();

// s.size() = 3

sort()

List Collection::sort()

Description

Returns a sorted list of the specified collection. Sorting is done according to the elements' type's natural ordering. This sort is guaranteed to be stable, equal elements will not be reordered as a result of the sort.

Example 2

1
2
3
4
5
6
7
Set s1 = new Set("c","b","a");
Set s2 = new Set(3,1,2);
s1.sort();
s2.sort();

// s1.sort() = [a, b, c]
// s2.sort() = [1, 2, 3]

toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.

Example 11

1
2
3
4
Set s = new Set("a", "b", "c");
s.toJson();

// s.toJson() = ["a","b","c"]

venn(otherSet,inThis,inOther,inBoth)

Set Set::venn(Set otherSet, Boolean inThis, Boolean inOther, Boolean inBoth)

Description

Returns a new set of values which is a combination of this set and the other set according to the Boolean flags set by the user. Each Boolean flag determines which portions of the Venn diagram are included in the final set.

Parameter Definition

Name Type Description
otherSet Set  the other set, that along with this set constitutes a Venn diagram
inThis Boolean  include values that are only in this set
inOther Boolean  include values that are only in the other set
inBoth Boolean  include values that are in both sets

Example 1

1
2
3
4
5
Set s1 = new Set("a","b","c","d");
Set s2 = new Set("d","e","f");
s1.venn(s2,true,true,false);

// s1.venn(s2,true,true,false) = [a, b, c, e, f]

this is the set containing elements in s1 and s2, but not in both.

Example 2

1
2
3
4
5
Set s1 = new Set("a","b","c","d");
Set s2 = new Set("d","e","f");
s1.venn(s2,false,true,false);

// s1.venn(s2,false,true,false); = [e, f]

this is the set containing no elements from s1 and only elements from s2 that are also not in s1.