1
1
package dev .ultreon .ubo .types ;
2
2
3
3
import dev .ultreon .ubo .DataTypes ;
4
+ import org .jetbrains .annotations .NotNull ;
4
5
5
6
import java .io .DataInput ;
6
7
import java .io .DataOutput ;
7
8
import java .io .IOException ;
8
9
import java .util .Arrays ;
10
+ import java .util .Iterator ;
9
11
10
- public class DoubleArrayType implements ArrayType <double []> {
12
+ public class DoubleArrayType implements ArrayType <double [], Double > {
11
13
private double [] obj ;
12
14
13
15
public DoubleArrayType (double [] obj ) {
14
16
this .obj = obj ;
15
17
}
16
18
19
+ public DoubleArrayType (int size ) {
20
+ this .obj = new double [size ];
21
+ }
22
+
17
23
@ Override
18
24
public double [] getValue () {
19
25
return obj ;
@@ -65,10 +71,29 @@ public DoubleArrayType copy() {
65
71
return new DoubleArrayType (obj .clone ());
66
72
}
67
73
74
+ @ Override
68
75
public int size () {
69
76
return obj .length ;
70
77
}
71
78
79
+ @ Override
80
+ public Double get (int index ) {
81
+ return obj [index ];
82
+ }
83
+
84
+ @ Override
85
+ public void set (int index , Double value ) {
86
+ obj [index ] = value ;
87
+ }
88
+
89
+ public double getDouble (int index ) {
90
+ return obj [index ];
91
+ }
92
+
93
+ public void set (int index , double value ) {
94
+ obj [index ] = value ;
95
+ }
96
+
72
97
@ Override
73
98
public String writeUso () {
74
99
StringBuilder builder = new StringBuilder ("(d;" );
@@ -87,4 +112,32 @@ public String writeUso() {
87
112
public String toString () {
88
113
return writeUso ();
89
114
}
115
+
116
+ @ Override
117
+ public @ NotNull Iterator <Double > iterator () {
118
+ return new DoubleIterator (obj );
119
+ }
120
+
121
+ public static class DoubleIterator implements Iterator <Double > {
122
+ private final double [] obj ;
123
+ private int index ;
124
+
125
+ public DoubleIterator (double [] obj ) {
126
+ this .obj = obj ;
127
+ }
128
+
129
+ @ Override
130
+ public boolean hasNext () {
131
+ return index < obj .length ;
132
+ }
133
+
134
+ @ Override
135
+ public Double next () {
136
+ return obj [index ++];
137
+ }
138
+
139
+ public double nextDouble () {
140
+ return obj [index ++];
141
+ }
142
+ }
90
143
}
0 commit comments