Skip to content

Commit 09aebaa

Browse files
author
brokkoli71
committed
add Group.create with Attributes
1 parent f018f0a commit 09aebaa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import dev.zarr.zarrjava.ZarrException;
5+
import dev.zarr.zarrjava.core.Attributes;
56
import dev.zarr.zarrjava.store.FilesystemStore;
67
import dev.zarr.zarrjava.store.StoreHandle;
78
import dev.zarr.zarrjava.utils.Utils;
@@ -64,14 +65,26 @@ public static Group create(@Nonnull StoreHandle storeHandle) throws IOException,
6465
return create(storeHandle, new GroupMetadata());
6566
}
6667

68+
public static Group create(@Nonnull StoreHandle storeHandle, Attributes attributes) throws IOException, ZarrException {
69+
return create(storeHandle, new GroupMetadata(attributes));
70+
}
71+
6772
public static Group create(Path path) throws IOException, ZarrException {
6873
return create(new StoreHandle(new FilesystemStore(path)));
6974
}
7075

76+
public static Group create(Path path, Attributes attributes) throws IOException, ZarrException {
77+
return create(new StoreHandle(new FilesystemStore(path)), attributes);
78+
}
79+
7180
public static Group create(String path) throws IOException, ZarrException {
7281
return create(Paths.get(path));
7382
}
7483

84+
public static Group create(String path, Attributes attributes) throws IOException, ZarrException {
85+
return create(Paths.get(path), attributes);
86+
}
87+
7588
@Nullable
7689
public Node get(String key) throws ZarrException {
7790
StoreHandle keyHandle = storeHandle.resolve(key);
@@ -102,7 +115,7 @@ public String toString() {
102115
}
103116

104117
@Override
105-
public dev.zarr.zarrjava.core.GroupMetadata metadata() {
118+
public GroupMetadata metadata() {
106119
return metadata;
107120
}
108121
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ public GroupMetadata() throws ZarrException {
3535
this(ZARR_FORMAT, null);
3636
}
3737

38+
public GroupMetadata(Attributes attributes) throws ZarrException {
39+
this(ZARR_FORMAT, attributes);
40+
}
41+
3842
@Override
3943
public @Nonnull Attributes attributes() throws ZarrException {
44+
if (attributes == null) {
45+
throw new ZarrException("Group attributes have not been set.");
46+
}
4047
return attributes;
4148
}
4249
}

0 commit comments

Comments
 (0)