OnJava8-Examples/generics/WatercolorSets.java

54 lines
2.1 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// generics/WatercolorSets.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2015-06-15 17:47:35 -07:00
import generics.watercolors.*;
import java.util.*;
import static onjava.Sets.*;
2015-06-15 17:47:35 -07:00
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);
2015-11-03 12:00:44 -08:00
System.out.println("set1: " + set1);
System.out.println("set2: " + set2);
2015-12-02 09:20:27 -08:00
System.out.println(
"union(set1, set2): " + union(set1, set2));
2015-06-15 17:47:35 -07:00
Set<Watercolors> subset = intersection(set1, set2);
2015-12-02 09:20:27 -08:00
System.out.println(
"intersection(set1, set2): " + subset);
2015-11-03 12:00:44 -08:00
System.out.println("difference(set1, subset): " +
2015-06-15 17:47:35 -07:00
difference(set1, subset));
2015-11-03 12:00:44 -08:00
System.out.println("difference(set2, subset): " +
2015-06-15 17:47:35 -07:00
difference(set2, subset));
2015-11-03 12:00:44 -08:00
System.out.println("complement(set1, set2): " +
2015-06-15 17:47:35 -07:00
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]
2016-07-22 14:45:35 -06:00
union(set1, set2): [MAGENTA, COBALT_BLUE_HUE, VIOLET,
VIRIDIAN_HUE, BURNT_SIENNA, ULTRAMARINE, CERULEAN_BLUE_HUE,
BURNT_UMBER, BRILLIANT_RED, PHTHALO_BLUE, YELLOW_OCHRE,
SAP_GREEN, CRIMSON, ROSE_MADDER, RAW_UMBER,
PERMANENT_GREEN]
intersection(set1, set2): [COBALT_BLUE_HUE, VIRIDIAN_HUE,
ULTRAMARINE, CERULEAN_BLUE_HUE, PHTHALO_BLUE,
PERMANENT_GREEN]
difference(set1, subset): [CRIMSON, MAGENTA, VIOLET,
ROSE_MADDER, BRILLIANT_RED]
difference(set2, subset): [BURNT_SIENNA, BURNT_UMBER,
YELLOW_OCHRE, RAW_UMBER, SAP_GREEN]
complement(set1, set2): [MAGENTA, VIOLET, BURNT_SIENNA,
BURNT_UMBER, BRILLIANT_RED, YELLOW_OCHRE, SAP_GREEN,
CRIMSON, ROSE_MADDER, RAW_UMBER]
2015-09-07 11:44:36 -06:00
*/