1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public abstract class AbstractDoubleCollection implements DoubleCollection {
36 public abstract DoubleIterator iterator();
37 public abstract int size();
38
39 protected AbstractDoubleCollection() { }
40
41
42 public boolean add(double element) {
43 throw new UnsupportedOperationException("add(double) is not supported.");
44 }
45
46 public boolean addAll(DoubleCollection c) {
47 boolean modified = false;
48 for(DoubleIterator iter = c.iterator(); iter.hasNext(); ) {
49 modified |= add(iter.next());
50 }
51 return modified;
52 }
53
54 public void clear() {
55 for(DoubleIterator iter = iterator(); iter.hasNext();) {
56 iter.next();
57 iter.remove();
58 }
59 }
60
61 public boolean contains(double element) {
62 for(DoubleIterator iter = iterator(); iter.hasNext();) {
63 if(iter.next() == element) {
64 return true;
65 }
66 }
67 return false;
68 }
69
70 public boolean containsAll(DoubleCollection c) {
71 for(DoubleIterator iter = c.iterator(); iter.hasNext();) {
72 if(!contains(iter.next())) {
73 return false;
74 }
75 }
76 return true;
77 }
78
79 public boolean isEmpty() {
80 return (0 == size());
81 }
82
83 public boolean removeElement(double element) {
84 for(DoubleIterator iter = iterator(); iter.hasNext();) {
85 if(iter.next() == element) {
86 iter.remove();
87 return true;
88 }
89 }
90 return false;
91 }
92
93 public boolean removeAll(DoubleCollection c) {
94 boolean modified = false;
95 for(DoubleIterator iter = c.iterator(); iter.hasNext(); ) {
96 modified |= removeElement(iter.next());
97 }
98 return modified;
99 }
100
101 public boolean retainAll(DoubleCollection c) {
102 boolean modified = false;
103 for(DoubleIterator iter = iterator(); iter.hasNext();) {
104 if(!c.contains(iter.next())) {
105 iter.remove();
106 modified = true;
107 }
108 }
109 return modified;
110 }
111
112 public double[] toArray() {
113 double[] array = new double[size()];
114 int i = 0;
115 for(DoubleIterator iter = iterator(); iter.hasNext();) {
116 array[i] = iter.next();
117 i++;
118 }
119 return array;
120 }
121
122 public double[] toArray(double[] a) {
123 if(a.length < size()) {
124 return toArray();
125 } else {
126 int i = 0;
127 for(DoubleIterator iter = iterator(); iter.hasNext();) {
128 a[i] = iter.next();
129 i++;
130 }
131 return a;
132 }
133 }
134 }