Skip to content

Commit e287318

Browse files
committed
documentation for Array methods and improve parameter descriptions
1 parent e07b7fe commit e287318

File tree

4 files changed

+81
-58
lines changed

4 files changed

+81
-58
lines changed

src/main/java/dev/zarr/zarrjava/interfaces/Array.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public interface Array {
2222
* Writes a ucar.ma2.Array into the Zarr array at a specified offset. The shape of the Zarr array
2323
* needs be large enough for the write.
2424
*
25-
* @param offset
26-
* @param array
27-
* @param parallel
25+
* @param offset the offset where to write the data
26+
* @param array the data to write
27+
* @param parallel utilizes parallelism if true
2828
*/
2929
default void write(long[] offset, ucar.ma2.Array array, boolean parallel) {
3030
ArrayMetadata metadata = metadata();
@@ -74,11 +74,12 @@ default void write(long[] offset, ucar.ma2.Array array, boolean parallel) {
7474

7575
/**
7676
* Writes one chunk into the Zarr array as specified by the chunk coordinates. The shape of the
77-
* Zarr array needs be large enough for the write.
77+
* Zarr array needs to be large enough to write.
7878
*
79-
* @param chunkCoords
80-
* @param chunkArray
81-
* @throws ZarrException
79+
* @param chunkCoords The coordinates of the chunk as computed by the offset of the chunk divided
80+
* by the chunk shape.
81+
* @param chunkArray The data to write into the chunk
82+
* @throws ZarrException throws ZarrException if the write fails
8283
*/
8384
default void writeChunk(long[] chunkCoords, ucar.ma2.Array chunkArray) throws ZarrException {
8485
ArrayMetadata metadata = metadata();
@@ -99,7 +100,7 @@ default void writeChunk(long[] chunkCoords, ucar.ma2.Array chunkArray) throws Za
99100
*
100101
* @param chunkCoords The coordinates of the chunk as computed by the offset of the chunk divided
101102
* by the chunk shape.
102-
* @throws ZarrException
103+
* @throws ZarrException throws ZarrException if the requested chunk is outside the array's domain or if the read fails
103104
*/
104105
@Nonnull
105106
default ucar.ma2.Array readChunk(long[] chunkCoords)
@@ -126,7 +127,7 @@ default ucar.ma2.Array readChunk(long[] chunkCoords)
126127
* the Zarr array needs be large enough for the write.
127128
* Utilizes no parallelism.
128129
*
129-
* @param array
130+
* @param array the data to write
130131
*/
131132
default void write(ucar.ma2.Array array) {
132133
write(new long[metadata().ndim()], array);
@@ -137,8 +138,8 @@ default void write(ucar.ma2.Array array) {
137138
* needs be large enough for the write.
138139
* Utilizes no parallelism.
139140
*
140-
* @param offset
141-
* @param array
141+
* @param offset the offset where to write the data
142+
* @param array the data to write
142143
*/
143144
default void write(long[] offset, ucar.ma2.Array array) {
144145
write(offset, array, false);
@@ -148,8 +149,8 @@ default void write(long[] offset, ucar.ma2.Array array) {
148149
* Writes a ucar.ma2.Array into the Zarr array at the beginning of the Zarr array. The shape of
149150
* the Zarr array needs be large enough for the write.
150151
*
151-
* @param array
152-
* @param parallel
152+
* @param array the data to write
153+
* @param parallel utilizes parallelism if true
153154
*/
154155
default void write(ucar.ma2.Array array, boolean parallel) {
155156
write(new long[metadata().ndim()], array, parallel);
@@ -159,7 +160,7 @@ default void write(ucar.ma2.Array array, boolean parallel) {
159160
* Reads the entire Zarr array into an ucar.ma2.Array.
160161
* Utilizes no parallelism.
161162
*
162-
* @throws ZarrException
163+
* @throws ZarrException throws ZarrException if the read fails
163164
*/
164165
@Nonnull
165166
default ucar.ma2.Array read() throws ZarrException {
@@ -170,9 +171,9 @@ default ucar.ma2.Array read() throws ZarrException {
170171
* Reads a part of the Zarr array based on a requested offset and shape into an ucar.ma2.Array.
171172
* Utilizes no parallelism.
172173
*
173-
* @param offset
174-
* @param shape
175-
* @throws ZarrException
174+
* @param offset the offset where to start reading
175+
* @param shape the shape of the data to read
176+
* @throws ZarrException throws ZarrException if the requested data is outside the array's domain or if the read fails
176177
*/
177178
@Nonnull
178179
default ucar.ma2.Array read(final long[] offset, final int[] shape) throws ZarrException {
@@ -182,8 +183,8 @@ default ucar.ma2.Array read(final long[] offset, final int[] shape) throws ZarrE
182183
/**
183184
* Reads the entire Zarr array into an ucar.ma2.Array.
184185
*
185-
* @param parallel
186-
* @throws ZarrException
186+
* @param parallel utilizes parallelism if true
187+
* @throws ZarrException throws ZarrException if the requested data is outside the array's domain or if the read fails
187188
*/
188189
@Nonnull
189190
default ucar.ma2.Array read(final boolean parallel) throws ZarrException {
@@ -209,10 +210,10 @@ default boolean chunkIsInArray(long[] chunkCoords) {
209210
/**
210211
* Reads a part of the Zarr array based on a requested offset and shape into an ucar.ma2.Array.
211212
*
212-
* @param offset
213-
* @param shape
214-
* @param parallel
215-
* @throws ZarrException
213+
* @param offset the offset where to start reading
214+
* @param shape the shape of the data to read
215+
* @param parallel utilizes parallelism if true
216+
* @throws ZarrException throws ZarrException if the requested data is outside the array's domain or if the read fails
216217
*/
217218
@Nonnull
218219
default ucar.ma2.Array read(final long[] offset, final int[] shape, final boolean parallel) throws ZarrException {

src/main/java/dev/zarr/zarrjava/v2/Array.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import dev.zarr.zarrjava.ZarrException;
55
import dev.zarr.zarrjava.store.StoreHandle;
6-
import dev.zarr.zarrjava.utils.IndexingUtils;
7-
import dev.zarr.zarrjava.utils.MultiArrayUtils;
86
import dev.zarr.zarrjava.utils.Utils;
97
import dev.zarr.zarrjava.v3.codec.CodecPipeline;
108
import dev.zarr.zarrjava.v3.codec.Codec;
119
import dev.zarr.zarrjava.v3.codec.core.BytesCodec;
12-
import ucar.ma2.InvalidRangeException;
1310

1411
import javax.annotation.Nonnull;
1512
import java.io.IOException;
1613
import java.nio.ByteBuffer;
1714
import java.util.Arrays;
1815
import java.util.function.Function;
1916
import java.util.stream.Collectors;
20-
import java.util.stream.Stream;
2117

2218
import static dev.zarr.zarrjava.v3.Node.makeObjectMapper;
2319

@@ -38,6 +34,13 @@ protected Array(StoreHandle storeHandle, ArrayMetadata arrayMetadata) throws IOE
3834
), metadata.coreArrayMetadata);
3935
}
4036

37+
/**
38+
* Opens an existing Zarr array at a specified storage location.
39+
*
40+
* @param storeHandle the storage location of the Zarr array
41+
* @throws IOException throws IOException if the metadata cannot be read
42+
* @throws ZarrException throws ZarrException if the Zarr array cannot be opened
43+
*/
4144
public static Array open(StoreHandle storeHandle) throws IOException, ZarrException {
4245
return new Array(
4346
storeHandle,
@@ -49,11 +52,32 @@ public static Array open(StoreHandle storeHandle) throws IOException, ZarrExcept
4952
);
5053
}
5154

55+
/**
56+
* Creates a new Zarr array with the provided metadata at a specified storage location. This
57+
* method will raise an exception if a Zarr array already exists at the specified storage
58+
* location.
59+
*
60+
* @param storeHandle the storage location of the Zarr array
61+
* @param arrayMetadata the metadata of the Zarr array
62+
* @throws IOException if the metadata cannot be serialized
63+
* @throws ZarrException if the Zarr array cannot be created
64+
*/
5265
public static Array create(StoreHandle storeHandle, ArrayMetadata arrayMetadata)
5366
throws IOException, ZarrException {
5467
return Array.create(storeHandle, arrayMetadata, false);
5568
}
5669

70+
/**
71+
* Creates a new Zarr array with the provided metadata at a specified storage location. If
72+
* `existsOk` is false, this method will raise an exception if a Zarr array already exists at the
73+
* specified storage location.
74+
*
75+
* @param storeHandle the storage location of the Zarr array
76+
* @param arrayMetadata the metadata of the Zarr array
77+
* @param existsOk if true, no exception is raised if the Zarr array already exists
78+
* @throws IOException throws IOException if the metadata cannot be serialized
79+
* @throws ZarrException throws ZarrException if the Zarr array cannot be created
80+
*/
5781
public static Array create(StoreHandle storeHandle, ArrayMetadata arrayMetadata, boolean existsOk)
5882
throws IOException, ZarrException {
5983
StoreHandle metadataHandle = storeHandle.resolve(ZARRAY);
@@ -85,8 +109,6 @@ public static ArrayMetadataBuilder metadataBuilder(ArrayMetadata existingMetadat
85109
return ArrayMetadataBuilder.fromArrayMetadata(existingMetadata);
86110
}
87111

88-
89-
90112
@Override
91113
public String toString() {
92114
return String.format("<v2.Array {%s} (%s) %s>", storeHandle,

src/main/java/dev/zarr/zarrjava/v3/Array.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import dev.zarr.zarrjava.ZarrException;
55
import dev.zarr.zarrjava.store.StoreHandle;
6-
import dev.zarr.zarrjava.utils.MultiArrayUtils;
76
import dev.zarr.zarrjava.utils.Utils;
87
import dev.zarr.zarrjava.v3.codec.CodecPipeline;
98
import java.io.IOException;
@@ -21,7 +20,7 @@ public class Array extends Node implements dev.zarr.zarrjava.interfaces.Array {
2120
CodecPipeline codecPipeline;
2221

2322
protected Array(StoreHandle storeHandle, ArrayMetadata arrayMetadata)
24-
throws IOException, ZarrException {
23+
throws ZarrException {
2524
super(storeHandle);
2625
this.metadata = arrayMetadata;
2726
this.codecPipeline = new CodecPipeline(arrayMetadata.codecs, arrayMetadata.coreArrayMetadata);
@@ -30,9 +29,9 @@ protected Array(StoreHandle storeHandle, ArrayMetadata arrayMetadata)
3029
/**
3130
* Opens an existing Zarr array at a specified storage location.
3231
*
33-
* @param storeHandle
34-
* @throws IOException
35-
* @throws ZarrException
32+
* @param storeHandle the storage location of the Zarr array
33+
* @throws IOException throws IOException if the metadata cannot be read
34+
* @throws ZarrException throws ZarrException if the Zarr array cannot be opened
3635
*/
3736
public static Array open(StoreHandle storeHandle) throws IOException, ZarrException {
3837
return new Array(
@@ -50,10 +49,10 @@ public static Array open(StoreHandle storeHandle) throws IOException, ZarrExcept
5049
* method will raise an exception if a Zarr array already exists at the specified storage
5150
* location.
5251
*
53-
* @param storeHandle
54-
* @param arrayMetadata
55-
* @throws IOException
56-
* @throws ZarrException
52+
* @param storeHandle the storage location of the Zarr array
53+
* @param arrayMetadata the metadata of the Zarr array
54+
* @throws IOException if the metadata cannot be serialized
55+
* @throws ZarrException if the Zarr array cannot be created
5756
*/
5857
public static Array create(StoreHandle storeHandle, ArrayMetadata arrayMetadata)
5958
throws IOException, ZarrException {
@@ -65,11 +64,11 @@ public static Array create(StoreHandle storeHandle, ArrayMetadata arrayMetadata)
6564
* `existsOk` is false, this method will raise an exception if a Zarr array already exists at the
6665
* specified storage location.
6766
*
68-
* @param storeHandle
69-
* @param arrayMetadata
70-
* @param existsOk
71-
* @throws IOException
72-
* @throws ZarrException
67+
* @param storeHandle the storage location of the Zarr array
68+
* @param arrayMetadata the metadata of the Zarr array
69+
* @param existsOk if true, no exception is raised if the Zarr array already exists
70+
* @throws IOException throws IOException if the metadata cannot be serialized
71+
* @throws ZarrException throws ZarrException if the Zarr array cannot be created
7372
*/
7473
public static Array create(StoreHandle storeHandle, ArrayMetadata arrayMetadata, boolean existsOk)
7574
throws IOException, ZarrException {
@@ -91,11 +90,12 @@ public static Array create(StoreHandle storeHandle, ArrayMetadata arrayMetadata,
9190
* be used to construct the metadata of the Zarr array. If `existsOk` is false, this method will
9291
* raise an exception if a Zarr array already exists at the specified storage location.
9392
*
94-
* @param storeHandle
95-
* @param arrayMetadataBuilderMapper
96-
* @param existsOk
97-
* @throws IOException
98-
* @throws ZarrException
93+
* @param storeHandle the storage location of the Zarr array
94+
* @param arrayMetadataBuilderMapper a callback of ArrayMetadataBuilder -> ArrayMetadataBuilder that is
95+
* used to construct the metadata of the Zarr array
96+
* @param existsOk if true, no exception is raised if the Zarr array already exists
97+
* @throws IOException if the metadata cannot be serialized
98+
* @throws ZarrException if the Zarr array cannot be created
9999
*/
100100
public static Array create(StoreHandle storeHandle,
101101
Function<ArrayMetadataBuilder, ArrayMetadataBuilder> arrayMetadataBuilderMapper,
@@ -142,9 +142,9 @@ private Array writeMetadata(ArrayMetadata newArrayMetadata) throws ZarrException
142142
* deleted. This method returns a new instance of the Zarr array class and the old instance
143143
* becomes invalid.
144144
*
145-
* @param newShape
146-
* @throws ZarrException
147-
* @throws IOException
145+
* @param newShape the new shape of the Zarr array
146+
* @throws ZarrException if the new metadata is invalid
147+
* @throws IOException throws IOException if the new metadata cannot be serialized
148148
*/
149149
public Array resize(long[] newShape) throws ZarrException, IOException {
150150
if (newShape.length != metadata.ndim()) {
@@ -162,9 +162,9 @@ public Array resize(long[] newShape) throws ZarrException, IOException {
162162
* Sets the attributes of the Zarr array. It overwrites and removes any existing attributes. This
163163
* method returns a new instance of the Zarr array class and the old instance becomes invalid.
164164
*
165-
* @param newAttributes
166-
* @throws ZarrException
167-
* @throws IOException
165+
* @param newAttributes the new attributes of the Zarr array
166+
* @throws ZarrException throws ZarrException if the new metadata is invalid
167+
* @throws IOException throws IOException if the new metadata cannot be serialized
168168
*/
169169
public Array setAttributes(Map<String, Object> newAttributes) throws ZarrException, IOException {
170170
ArrayMetadata newArrayMetadata =
@@ -180,9 +180,10 @@ public Array setAttributes(Map<String, Object> newAttributes) throws ZarrExcepti
180180
* callback may be mutated. This method overwrites and removes any existing attributes. This
181181
* method returns a new instance of the Zarr array class and the old instance becomes invalid.
182182
*
183-
* @param attributeMapper
184-
* @throws ZarrException
185-
* @throws IOException
183+
* @param attributeMapper a callback of Map<String, Object> -> Map<String, Object> that is used to construct the new
184+
* attributes
185+
* @throws ZarrException throws ZarrException if the new metadata is invalid
186+
* @throws IOException throws IOException if the new metadata cannot be serialized
186187
*/
187188
public Array updateAttributes(Function<Map<String, Object>, Map<String, Object>> attributeMapper)
188189
throws ZarrException, IOException {

src/test/java/dev/zarr/zarrjava/ZarrTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import dev.zarr.zarrjava.v3.*;
1313
import dev.zarr.zarrjava.v3.codec.Codec;
1414
import dev.zarr.zarrjava.v3.codec.CodecBuilder;
15-
import dev.zarr.zarrjava.v3.codec.core.BloscCodec;
1615
import dev.zarr.zarrjava.v3.codec.core.BytesCodec;
1716
import dev.zarr.zarrjava.v3.codec.core.ShardingIndexedCodec;
1817
import dev.zarr.zarrjava.v3.codec.core.TransposeCodec;

0 commit comments

Comments
 (0)