@@ -52,16 +52,7 @@ public static Group open(String path) throws IOException {
5252 public static Group create (
5353 @ Nonnull StoreHandle storeHandle , @ Nonnull GroupMetadata groupMetadata
5454 ) throws IOException {
55- ObjectWriter objectWriter = makeObjectWriter ();
56- ByteBuffer metadataBytes = ByteBuffer .wrap (objectWriter .writeValueAsBytes (groupMetadata ));
57- storeHandle .resolve (ZGROUP ).set (metadataBytes );
58- if (groupMetadata .attributes != null ) {
59- StoreHandle attrsHandle = storeHandle .resolve (ZATTRS );
60- ByteBuffer attrsBytes = ByteBuffer .wrap (
61- objectWriter .writeValueAsBytes (groupMetadata .attributes ));
62- attrsHandle .set (attrsBytes );
63- }
64- return new Group (storeHandle , groupMetadata );
55+ return new Group (storeHandle , groupMetadata ).writeMetadata ();
6556 }
6657
6758 public static Group create (@ Nonnull StoreHandle storeHandle ) throws IOException , ZarrException {
@@ -108,10 +99,38 @@ public Array createArray(String key, ArrayMetadata arrayMetadata)
10899 }
109100
110101 public Array createArray (String key , Function <ArrayMetadataBuilder , ArrayMetadataBuilder > arrayMetadataBuilderMapper )
111- throws IOException , ZarrException {
102+ throws IOException , ZarrException {
112103 return Array .create (storeHandle .resolve (key ), arrayMetadataBuilderMapper , false );
113104 }
114105
106+ private Group writeMetadata () throws IOException {
107+ return writeMetadata (this .metadata );
108+ }
109+
110+ private Group writeMetadata (GroupMetadata newGroupMetadata ) throws IOException {
111+ ObjectWriter objectWriter = makeObjectWriter ();
112+ ByteBuffer metadataBytes = ByteBuffer .wrap (objectWriter .writeValueAsBytes (newGroupMetadata ));
113+ storeHandle .resolve (ZGROUP ).set (metadataBytes );
114+ if (newGroupMetadata .attributes != null ) {
115+ StoreHandle attrsHandle = storeHandle .resolve (ZATTRS );
116+ ByteBuffer attrsBytes = ByteBuffer .wrap (
117+ objectWriter .writeValueAsBytes (newGroupMetadata .attributes ));
118+ attrsHandle .set (attrsBytes );
119+ }
120+ return new Group (storeHandle , newGroupMetadata );
121+ }
122+
123+ public Group setAttributes (Attributes newAttributes ) throws ZarrException , IOException {
124+ GroupMetadata newGroupMetadata = new GroupMetadata (newAttributes );
125+ return writeMetadata (newGroupMetadata );
126+ }
127+
128+ public Group updateAttributes (Function <Attributes , Attributes > attributeMapper )
129+ throws ZarrException , IOException {
130+ return setAttributes (attributeMapper .apply (metadata .attributes ));
131+ }
132+
133+
115134 @ Override
116135 public String toString () {
117136 return String .format ("<v2.Group {%s}>" , storeHandle );
0 commit comments