-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[endec] Implement EdmMap allowing for easy map operations within EdmE…
…ndec
- Loading branch information
1 parent
1cecd45
commit efa8ed0
Showing
2 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/io/wispforest/owo/serialization/format/edm/EdmMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.wispforest.owo.serialization.format.edm; | ||
|
||
import io.wispforest.owo.serialization.endec.KeyedEndec; | ||
import io.wispforest.owo.serialization.util.MapCarrier; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
|
||
public final class EdmMap extends EdmElement<Map<String, EdmElement<?>>> implements MapCarrier { | ||
|
||
EdmMap(EdmElement<Map<String, EdmElement<?>>> mapElement) { | ||
super(mapElement.value(), mapElement.type()); | ||
} | ||
|
||
@Override | ||
public <T> T getWithErrors(@NotNull KeyedEndec<T> key) { | ||
return key.endec().decodeFully(EdmDeserializer::of, this.value().get(key.key())); | ||
} | ||
|
||
@Override | ||
public <T> void put(@NotNull KeyedEndec<T> key, @NotNull T value) { | ||
this.value().put(key.key(), key.endec().encodeFully(EdmSerializer::of, value)); | ||
} | ||
|
||
@Override | ||
public <T> void delete(@NotNull KeyedEndec<T> key) { | ||
this.value().remove(key.key()); | ||
} | ||
|
||
@Override | ||
public <T> boolean has(@NotNull KeyedEndec<T> key) { | ||
return this.value().containsKey(key.key()); | ||
} | ||
} |