Debian Codegraph @

net/sf/saxon/z/IntSingletonSet.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.z;
9
10 /**
11 * An immutable integer set containing a single integer
12 */
13 public class IntSingletonSet implements IntSet {
14
15 private int value;
16
17 public IntSingletonSet(int value) {
18 this.value = value;
19 }
20
21 public int getMember() {
22 return value;
23 }
24
25 public void clear() {
26 throw new UnsupportedOperationException("IntSingletonSet is immutable");
27 }
28
29 public IntSet copy() {
30 return this;
31 }
32
33 public IntSet mutableCopy() {
34 IntHashSet intHashSet = new IntHashSet();
35 intHashSet.add(value);
36 return intHashSet;
37 }
38
39 public int size() {
40 return 1;
41 }
42
43 public boolean isEmpty() {
44 return false;
45 }
46
47 public boolean contains(int value) {
48 return this.value == value;
49 }
50
51 public boolean remove(int value) {
52 throw new UnsupportedOperationException("IntSingletonSet is immutable");
53 }
54
55 public boolean add(int value) {
56 throw new UnsupportedOperationException("IntSingletonSet is immutable");
57 }
58
59 public IntIterator iterator() {
60 return new IntSingletonIterator(value);
61 }
62
63 public IntSet union(IntSet other) {
64 IntSet n = other.mutableCopy();
65 n.add(value);
66 return n;
67 }
68
69 public IntSet intersect(IntSet other) {
70 if (other.contains(value)) {
71 return this;
72 } else {
73 return IntEmptySet.getInstance();
74 }
75 }
76
77 public IntSet except(IntSet other) {
78 if (other.contains(value)) {
79 return IntEmptySet.getInstance();
80 } else {
81 return this;
82 }
83 }
84
85 public boolean containsAll(/*@NotNull*/ IntSet other) {
86 if (other.size() > 1) {
87 return false;
88 }
89 IntIterator ii = other.iterator();
90 while (ii.hasNext()) {
91 if (value != ii.next()) {
92 return false;
93 }
94 }
95 return true;
96 }
97 }
98