Mathematical sets in java.
Creating MSet
MSet<Long> longSet = MSet.of(1L, 2L, 3L); //from array
ArrayList<String> strings = new ArrayList<>(); //from collection
strings.add("v1");
strings.add("v2");
MSet<String> stringSet = MSet.of(strings);
MSet<Integer> integerSet = IntStream.range(0, 10) //from stream
.boxed()
.collect(MSet.toMSet());
Iterating through set :
for (Integer value : set) { //foreach loop
//...
}
set.stream() //stream
.forEach(value -> { /* ... */});
Iterator<Integer> iterator = set.iterator(); //iterator
while (iterator.hasNext()) {
Integer value = iterator.next();
// ...
}
Some set operations:
MSet.of(1, 2, 3).union(MSet.of(2, 3, 4)); //union {1,2,3,4}
MSet.of(1, 2, 3).intersection(MSet.of(2, 3, 4)); //intersection {2,3}
MSet.of(1, 2, 3).contains(1); // true
MSet.of(1, 2, 3).intersection(MSet.of(2, 3, 4)).contains(1); // false
Universal set bounded operations:
MSet.of(1, 2, 3)
.complement()
.contains(4, MSet.of(1, 2, 3, 4)) //true
MSet.of(1, 2, 3)
.complement()
.contains(1, MSet.of(1, 2, 3, 4)) //false
This project is licensed under Apache License, version 2.0
Releases are available in Maven Central
Add this snippet to the pom.xml dependencies
section:
<dependency>
<groupId>com.ochumak</groupId>
<artifactId>mset-core</artifactId>
<version>1.6</version>
</dependency>
Add this snippet to the build.gradle dependencies
section:
compile 'com.ochumak:mset-core:1.6'
Pull requests are welcome.