Skip to content

Commit 8f58d46

Browse files
committed
cleanup create api
1 parent 0fedf6f commit 8f58d46

3 files changed

Lines changed: 21 additions & 26 deletions

File tree

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,10 @@ public static Group create(
4747
return new Group(storeHandle, groupMetadata);
4848
}
4949

50-
public static Group create(
51-
@Nonnull StoreHandle storeHandle
52-
) throws IOException, ZarrException {
50+
public static Group create(@Nonnull StoreHandle storeHandle) throws IOException, ZarrException {
5351
return create(storeHandle, new GroupMetadata());
5452
}
5553

56-
public static Group create(Path path, GroupMetadata groupMetadata) throws IOException {
57-
return create(new StoreHandle(new FilesystemStore(path)), groupMetadata);
58-
}
59-
60-
public static Group create(String path, GroupMetadata groupMetadata) throws IOException {
61-
return create(Paths.get(path), groupMetadata);
62-
}
63-
6454
public static Group create(Path path) throws IOException, ZarrException {
6555
return create(new StoreHandle(new FilesystemStore(path)));
6656
}
@@ -79,13 +69,8 @@ public Node get(String key) throws ZarrException {
7969
}
8070
}
8171

82-
public Group createGroup(String key, GroupMetadata groupMetadata)
83-
throws IOException, ZarrException {
84-
return Group.create(storeHandle.resolve(key), groupMetadata);
85-
}
86-
8772
public Group createGroup(String key) throws IOException, ZarrException {
88-
return Group.create(storeHandle.resolve(key), new GroupMetadata());
73+
return Group.create(storeHandle.resolve(key));
8974
}
9075

9176
public Array createArray(String key, ArrayMetadata arrayMetadata)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ private Array writeMetadata(ArrayMetadata newArrayMetadata) throws ZarrException
193193
* Sets a new shape for the Zarr array. It only changes the metadata, no array data is modified or
194194
* deleted. This method returns a new instance of the Zarr array class and the old instance
195195
* becomes invalid.
196+
* TODO: test
196197
*
197198
* @param newShape the new shape of the Zarr array
198199
* @throws ZarrException if the new metadata is invalid
@@ -231,6 +232,7 @@ public Array setAttributes(Map<String, Object> newAttributes) throws ZarrExcepti
231232
* attributes as input and needs to return the new set of attributes. The attributes in the
232233
* callback may be mutated. This method overwrites and removes any existing attributes. This
233234
* method returns a new instance of the Zarr array class and the old instance becomes invalid.
235+
* TODO: test
234236
*
235237
* @param attributeMapper the callback that is used to construct the new attributes
236238
* @throws ZarrException throws ZarrException if the new metadata is invalid

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.zarr.zarrjava.v2.ArrayMetadata;
77
import dev.zarr.zarrjava.v3.Array;
88
import dev.zarr.zarrjava.v3.Group;
9+
import dev.zarr.zarrjava.v3.GroupMetadata;
910
import org.junit.jupiter.api.Assertions;
1011
import org.junit.jupiter.api.Test;
1112

@@ -14,6 +15,8 @@
1415
import java.nio.file.NoSuchFileException;
1516
import java.nio.file.Path;
1617
import java.nio.file.Paths;
18+
import java.util.HashMap;
19+
import java.util.Map;
1720

1821

1922
public class ZarrApiTest extends ZarrTest {
@@ -42,7 +45,7 @@ public void testGenericOpenV3() throws ZarrException, IOException {
4245
group = (Group) dev.zarr.zarrjava.v3.Node.open(groupHandle);
4346
Assertions.assertInstanceOf(Group.class, group.get("color"));
4447

45-
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(new FilesystemStore(TESTDATA).resolve("non_existing")));
48+
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(TESTDATA.resolve("non_existing")));
4649
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v3.Node.open(v2Handle));
4750
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v3.Group.open(v2Handle));
4851
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v3.Array.open(v2Handle));
@@ -84,8 +87,8 @@ public void testGenericOpenOverloadsV3() throws ZarrException, IOException {
8487
group = (Group) dev.zarr.zarrjava.v3.Node.open(groupPath.toString());
8588
Assertions.assertInstanceOf(Group.class, group.get("color"));
8689

87-
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(new FilesystemStore(TESTDATA).resolve("non_existing")));
88-
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(new FilesystemStore(TESTDATA).resolve("non_existing").toString()));
90+
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(TESTDATA.resolve("non_existing")));
91+
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(TESTDATA.resolve("non_existing").toString()));
8992

9093
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v3.Node.open(v2GroupPath));
9194
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v3.Node.open(v2GroupPath.toString()));
@@ -121,7 +124,7 @@ public void testGenericOpenV2() throws ZarrException, IOException {
121124
group = (dev.zarr.zarrjava.v2.Group) dev.zarr.zarrjava.v2.Node.open(groupHandle);
122125
Assertions.assertInstanceOf(dev.zarr.zarrjava.v2.Group.class, group.get("subgroup"));
123126

124-
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(new FilesystemStore(TESTDATA).resolve("non_existing")));
127+
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(TESTDATA.resolve("non_existing")));
125128
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v2.Node.open(v3Handle));
126129
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v2.Group.open(v3Handle));
127130
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v2.Array.open(v3Handle));
@@ -163,8 +166,8 @@ public void testGenericOpenOverloadsV2() throws ZarrException, IOException {
163166
group = (dev.zarr.zarrjava.v2.Group) dev.zarr.zarrjava.v2.Node.open(groupPath.toString());
164167
Assertions.assertInstanceOf(dev.zarr.zarrjava.v2.Group.class, group.get("subgroup"));
165168

166-
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(new FilesystemStore(TESTDATA).resolve("non_existing")));
167-
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(new FilesystemStore(TESTDATA).resolve("non_existing").toString()));
169+
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(TESTDATA.resolve("non_existing")));
170+
Assertions.assertThrows(NoSuchFileException.class, () -> Node.open(TESTDATA.resolve("non_existing").toString()));
168171

169172
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v2.Node.open(v3GroupPath));
170173
Assertions.assertThrows(NoSuchFileException.class, () -> dev.zarr.zarrjava.v2.Node.open(v3GroupPath.toString()));
@@ -239,15 +242,20 @@ public void testCreateGroupV3() throws ZarrException, IOException {
239242
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testCreateGroupV3");
240243
Path storeHandlePath = TESTOUTPUT.resolve("testCreateGroupV3Path");
241244
String storeHandleString = String.valueOf(TESTOUTPUT.resolve("testCreateGroupV3String"));
245+
Map<String, Object> attributes = new HashMap<>();
246+
attributes.put("hello", "world");
242247

243-
dev.zarr.zarrjava.v3.Group.create(storeHandle);
248+
Group group = Group.create(storeHandle, new GroupMetadata(attributes));
244249
Assertions.assertTrue(storeHandle.resolve("zarr.json").exists());
250+
Assertions.assertEquals("world", group.metadata.attributes.get("hello"));
245251

246-
dev.zarr.zarrjava.v3.Group.create(storeHandlePath);
252+
group = Group.create(storeHandlePath, new GroupMetadata(attributes));
247253
Assertions.assertTrue(Files.exists(storeHandlePath.resolve("zarr.json")));
254+
Assertions.assertEquals("world", group.metadata.attributes.get("hello"));
248255

249-
dev.zarr.zarrjava.v3.Group.create(storeHandleString);
256+
group = Group.create(storeHandleString, new GroupMetadata(attributes));
250257
Assertions.assertTrue(Files.exists(Paths.get(storeHandleString).resolve("zarr.json")));
258+
Assertions.assertEquals("world", group.metadata.attributes.get("hello"));
251259
}
252260

253261
}

0 commit comments

Comments
 (0)