01: /*
02: * The contents of this file are subject to the terms
03: * of the Common Development and Distribution License
04: * (the "License"). You may not use this file except
05: * in compliance with the License.
06: *
07: * You can obtain a copy of the license at
08: * https://jwsdp.dev.java.net/CDDLv1.0.html
09: * See the License for the specific language governing
10: * permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL
13: * HEADER in each file and include the License file at
14: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
15: * add the following below this CDDL HEADER, with the
16: * fields enclosed by brackets "[]" replaced with your
17: * own identifying information: Portions Copyright [yyyy]
18: * [name of copyright owner]
19: */
20: package com.sun.xml.xsom.util;
21:
22: import com.sun.xml.xsom.XSType;
23:
24: /**
25: * A simple abstraction for a set of Types that defines containment functions.
26: *
27: * @author <a href="mailto:Ryan.Shoemaker@Sun.COM">Ryan Shoemaker</a>, Sun Microsystems, Inc.
28: */
29: public abstract class TypeSet {
30:
31: /**
32: * Return true if this TypeSet contains the specified type.
33: *
34: * Concrete implementations of this method determine what it
35: * means for the TypeSet to "contain" a type.
36: *
37: * @param type the type
38: * @return true iff this TypeSet contains the specified type
39: */
40: public abstract boolean contains(XSType type);
41:
42: /**
43: * Calculate the TypeSet formed by the intersection of two
44: * other TypeSet objects.
45: *
46: * @param a a TypeSet
47: * @param b another TypeSet
48: * @return the intersection of a and b
49: */
50: public static TypeSet intersection(final TypeSet a, final TypeSet b) {
51: return new TypeSet() {
52: public boolean contains(XSType type) {
53: return a.contains(type) && b.contains(type);
54: }
55: };
56: }
57:
58: /**
59: * Calculate the TypeSet formed by the union of two
60: * other TypeSet objects.
61: *
62: * @param a a TypeSet
63: * @param b another TypeSet
64: * @return the union of a and b
65: */
66: public static TypeSet union(final TypeSet a, final TypeSet b) {
67: return new TypeSet() {
68: public boolean contains(XSType type) {
69: return a.contains(type) || b.contains(type);
70: }
71: };
72: }
73: }
|