OnJava8-Examples/generics/WatercolorSets.java

51 lines
1.9 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// generics/WatercolorSets.java
2015-06-15 17:47:35 -07:00
// <20>2015 MindView LLC: see Copyright.txt
import generics.watercolors.*;
import java.util.*;
import static com.mindviewinc.util.Print.*;
import static com.mindviewinc.util.Sets.*;
import static generics.watercolors.Watercolors.*;
public class WatercolorSets {
public static void main(String[] args) {
Set<Watercolors> set1 =
EnumSet.range(BRILLIANT_RED, VIRIDIAN_HUE);
Set<Watercolors> set2 =
EnumSet.range(CERULEAN_BLUE_HUE, BURNT_UMBER);
print("set1: " + set1);
print("set2: " + set2);
print("union(set1, set2): " + union(set1, set2));
Set<Watercolors> subset = intersection(set1, set2);
print("intersection(set1, set2): " + subset);
print("difference(set1, subset): " +
difference(set1, subset));
print("difference(set2, subset): " +
difference(set2, subset));
print("complement(set1, set2): " +
complement(set1, set2));
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
set1: [BRILLIANT_RED, CRIMSON, MAGENTA, ROSE_MADDER,
VIOLET, CERULEAN_BLUE_HUE, PHTHALO_BLUE, ULTRAMARINE,
COBALT_BLUE_HUE, PERMANENT_GREEN, VIRIDIAN_HUE]
set2: [CERULEAN_BLUE_HUE, PHTHALO_BLUE, ULTRAMARINE,
COBALT_BLUE_HUE, PERMANENT_GREEN, VIRIDIAN_HUE, SAP_GREEN,
YELLOW_OCHRE, BURNT_SIENNA, RAW_UMBER, BURNT_UMBER]
union(set1, set2): [CERULEAN_BLUE_HUE, PHTHALO_BLUE,
VIOLET, YELLOW_OCHRE, RAW_UMBER, COBALT_BLUE_HUE,
BURNT_UMBER, ROSE_MADDER, VIRIDIAN_HUE, MAGENTA, SAP_GREEN,
BURNT_SIENNA, PERMANENT_GREEN, BRILLIANT_RED, CRIMSON,
ULTRAMARINE]
intersection(set1, set2): [CERULEAN_BLUE_HUE, PHTHALO_BLUE,
PERMANENT_GREEN, COBALT_BLUE_HUE, VIRIDIAN_HUE,
ULTRAMARINE]
difference(set1, subset): [MAGENTA, VIOLET, BRILLIANT_RED,
CRIMSON, ROSE_MADDER]
difference(set2, subset): [SAP_GREEN, YELLOW_OCHRE,
RAW_UMBER, BURNT_SIENNA, BURNT_UMBER]
complement(set1, set2): [VIOLET, YELLOW_OCHRE, RAW_UMBER,
BURNT_UMBER, ROSE_MADDER, MAGENTA, SAP_GREEN, BURNT_SIENNA,
BRILLIANT_RED, CRIMSON]
2015-09-07 11:44:36 -06:00
*/