1414import java .util .Arrays ;
1515import java .util .stream .Stream ;
1616
17- public interface Array {
17+ public abstract class Array extends Node {
1818
19- ArrayMetadata metadata ();
20-
21- StoreHandle storeHandle ();
19+ protected CodecPipeline codecPipeline ;
20+ protected abstract ArrayMetadata metadata ();
2221
23- CodecPipeline codecPipeline ();
22+ protected Array (StoreHandle storeHandle ) throws ZarrException {
23+ super (storeHandle );
24+ }
2425
2526 /**
2627 * Writes a ucar.ma2.Array into the Zarr array at a specified offset. The shape of the Zarr array
2728 * needs be large enough for the write.
2829 *
29- * @param offset the offset where to write the data
30- * @param array the data to write
30+ * @param offset the offset where to write the data
31+ * @param array the data to write
3132 * @param parallel utilizes parallelism if true
3233 */
33- default void write (long [] offset , ucar .ma2 .Array array , boolean parallel ) {
34+ public void write (long [] offset , ucar .ma2 .Array array , boolean parallel ) {
3435 ArrayMetadata metadata = metadata ();
3536 if (offset .length != metadata .ndim ()) {
3637 throw new IllegalArgumentException ("'offset' needs to have rank '" + metadata .ndim () + "'." );
@@ -82,19 +83,19 @@ default void write(long[] offset, ucar.ma2.Array array, boolean parallel) {
8283 *
8384 * @param chunkCoords The coordinates of the chunk as computed by the offset of the chunk divided
8485 * by the chunk shape.
85- * @param chunkArray The data to write into the chunk
86+ * @param chunkArray The data to write into the chunk
8687 * @throws ZarrException throws ZarrException if the write fails
8788 */
88- default void writeChunk (long [] chunkCoords , ucar .ma2 .Array chunkArray ) throws ZarrException {
89+ public void writeChunk (long [] chunkCoords , ucar .ma2 .Array chunkArray ) throws ZarrException {
8990 ArrayMetadata metadata = metadata ();
9091 String [] chunkKeys = metadata .chunkKeyEncoding ().encodeChunkKey (chunkCoords );
91- StoreHandle chunkHandle = storeHandle () .resolve (chunkKeys );
92+ StoreHandle chunkHandle = storeHandle .resolve (chunkKeys );
9293 Object parsedFillValue = metadata .parsedFillValue ();
9394
9495 if (parsedFillValue != null && MultiArrayUtils .allValuesEqual (chunkArray , parsedFillValue )) {
9596 chunkHandle .delete ();
9697 } else {
97- ByteBuffer chunkBytes = codecPipeline () .encode (chunkArray );
98+ ByteBuffer chunkBytes = codecPipeline .encode (chunkArray );
9899 chunkHandle .set (chunkBytes );
99100 }
100101 }
@@ -108,22 +109,21 @@ default void writeChunk(long[] chunkCoords, ucar.ma2.Array chunkArray) throws Za
108109 * @throws ZarrException throws ZarrException if the requested chunk is outside the array's domain or if the read fails
109110 */
110111 @ Nonnull
111- default ucar .ma2 .Array readChunk (long [] chunkCoords )
112- throws ZarrException {
112+ public ucar .ma2 .Array readChunk (long [] chunkCoords ) throws ZarrException {
113113 ArrayMetadata metadata = metadata ();
114114 if (!chunkIsInArray (chunkCoords )) {
115115 throw new ZarrException ("Attempting to read data outside of the array's domain." );
116116 }
117117
118118 final String [] chunkKeys = metadata .chunkKeyEncoding ().encodeChunkKey (chunkCoords );
119- final StoreHandle chunkHandle = storeHandle () .resolve (chunkKeys );
119+ final StoreHandle chunkHandle = storeHandle .resolve (chunkKeys );
120120
121121 ByteBuffer chunkBytes = chunkHandle .read ();
122122 if (chunkBytes == null ) {
123123 return metadata .allocateFillValueChunk ();
124124 }
125125
126- return codecPipeline () .decode (chunkBytes );
126+ return codecPipeline .decode (chunkBytes );
127127 }
128128
129129
@@ -134,7 +134,7 @@ default ucar.ma2.Array readChunk(long[] chunkCoords)
134134 *
135135 * @param array the data to write
136136 */
137- default void write (ucar .ma2 .Array array ) {
137+ public void write (ucar .ma2 .Array array ) {
138138 write (new long [metadata ().ndim ()], array );
139139 }
140140
@@ -144,20 +144,20 @@ default void write(ucar.ma2.Array array) {
144144 * Utilizes no parallelism.
145145 *
146146 * @param offset the offset where to write the data
147- * @param array the data to write
147+ * @param array the data to write
148148 */
149- default void write (long [] offset , ucar .ma2 .Array array ) {
149+ public void write (long [] offset , ucar .ma2 .Array array ) {
150150 write (offset , array , false );
151151 }
152152
153153 /**
154154 * Writes a ucar.ma2.Array into the Zarr array at the beginning of the Zarr array. The shape of
155155 * the Zarr array needs be large enough for the write.
156156 *
157- * @param array the data to write
157+ * @param array the data to write
158158 * @param parallel utilizes parallelism if true
159159 */
160- default void write (ucar .ma2 .Array array , boolean parallel ) {
160+ public void write (ucar .ma2 .Array array , boolean parallel ) {
161161 write (new long [metadata ().ndim ()], array , parallel );
162162 }
163163
@@ -168,7 +168,7 @@ default void write(ucar.ma2.Array array, boolean parallel) {
168168 * @throws ZarrException throws ZarrException if the read fails
169169 */
170170 @ Nonnull
171- default ucar .ma2 .Array read () throws ZarrException {
171+ public ucar .ma2 .Array read () throws ZarrException {
172172 return read (new long [metadata ().ndim ()], Utils .toIntArray (metadata ().shape ()));
173173 }
174174
@@ -177,11 +177,11 @@ default ucar.ma2.Array read() throws ZarrException {
177177 * Utilizes no parallelism.
178178 *
179179 * @param offset the offset where to start reading
180- * @param shape the shape of the data to read
180+ * @param shape the shape of the data to read
181181 * @throws ZarrException throws ZarrException if the requested data is outside the array's domain or if the read fails
182182 */
183183 @ Nonnull
184- default ucar .ma2 .Array read (final long [] offset , final int [] shape ) throws ZarrException {
184+ public ucar .ma2 .Array read (final long [] offset , final int [] shape ) throws ZarrException {
185185 return read (offset , shape , false );
186186 }
187187
@@ -192,11 +192,11 @@ default ucar.ma2.Array read(final long[] offset, final int[] shape) throws ZarrE
192192 * @throws ZarrException throws ZarrException if the requested data is outside the array's domain or if the read fails
193193 */
194194 @ Nonnull
195- default ucar .ma2 .Array read (final boolean parallel ) throws ZarrException {
195+ public ucar .ma2 .Array read (final boolean parallel ) throws ZarrException {
196196 return read (new long [metadata ().ndim ()], Utils .toIntArray (metadata ().shape ()), parallel );
197197 }
198198
199- default boolean chunkIsInArray (long [] chunkCoords ) {
199+ boolean chunkIsInArray (long [] chunkCoords ) {
200200 final int [] chunkShape = metadata ().chunkShape ();
201201 for (int dimIdx = 0 ; dimIdx < metadata ().ndim (); dimIdx ++) {
202202 if (chunkCoords [dimIdx ] < 0
@@ -210,15 +210,14 @@ default boolean chunkIsInArray(long[] chunkCoords) {
210210 /**
211211 * Reads a part of the Zarr array based on a requested offset and shape into an ucar.ma2.Array.
212212 *
213- * @param offset the offset where to start reading
214- * @param shape the shape of the data to read
213+ * @param offset the offset where to start reading
214+ * @param shape the shape of the data to read
215215 * @param parallel utilizes parallelism if true
216216 * @throws ZarrException throws ZarrException if the requested data is outside the array's domain or if the read fails
217217 */
218218 @ Nonnull
219- default ucar .ma2 .Array read (final long [] offset , final int [] shape , final boolean parallel ) throws ZarrException {
219+ public ucar .ma2 .Array read (final long [] offset , final int [] shape , final boolean parallel ) throws ZarrException {
220220 ArrayMetadata metadata = metadata ();
221- CodecPipeline codecPipeline = codecPipeline ();
222221 if (offset .length != metadata .ndim ()) {
223222 throw new IllegalArgumentException ("'offset' needs to have rank '" + metadata .ndim () + "'." );
224223 }
@@ -258,7 +257,7 @@ default ucar.ma2.Array read(final long[] offset, final int[] shape, final boolea
258257 }
259258
260259 final String [] chunkKeys = metadata .chunkKeyEncoding ().encodeChunkKey (chunkCoords );
261- final StoreHandle chunkHandle = storeHandle () .resolve (chunkKeys );
260+ final StoreHandle chunkHandle = storeHandle .resolve (chunkKeys );
262261 if (!chunkHandle .exists ()) {
263262 return ;
264263 }
@@ -281,11 +280,11 @@ default ucar.ma2.Array read(final long[] offset, final int[] shape, final boolea
281280 return outputArray ;
282281 }
283282
284- default ArrayAccessor access () {
283+ public ArrayAccessor access () {
285284 return new ArrayAccessor (this );
286285 }
287286
288- final class ArrayAccessor {
287+ public static final class ArrayAccessor {
289288 @ Nullable
290289 long [] offset ;
291290 @ Nullable
0 commit comments