Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
Signed-off-by: zhaohehuhu <[email protected]>
  • Loading branch information
zhaohehuhu committed Jan 22, 2025
1 parent 86ce276 commit 5d35a7e
Showing 1 changed file with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,57 @@
@SuppressWarnings("rawtypes")
public class JavaImmutableMapSerializer extends Serializer<Map<?, ?>> {

@Override
public void write(Kryo kryo, Output output, Map<?, ?> map) {
ImmSerMapEntry[] entries = map
.entrySet()
.stream()
.map(ImmSerMapEntry::new)
.toArray(ImmSerMapEntry[]::new);

kryo.writeObject(output, new ImmSerMap(entries));
}
@Override
public void write(Kryo kryo, Output output, Map<?, ?> map) {
ImmSerMapEntry[] entries = map
.entrySet()
.stream()
.map(ImmSerMapEntry::new)
.toArray(ImmSerMapEntry[]::new);

kryo.writeObject(output, new ImmSerMap(entries));
}

@Override
public Map<?, ?> read(Kryo kryo, Input input, Class<Map<?, ?>> type) {
return Map.ofEntries(kryo.readObject(input, ImmSerMap.class).getEntries());
}
@Override
public Map<?, ?> read(Kryo kryo, Input input, Class<Map<?, ?>> type) {
return Map.ofEntries(kryo.readObject(input, ImmSerMap.class).getEntries());
}


private static class ImmSerMap implements Serializable {
private static class ImmSerMap implements Serializable {

private final ImmSerMapEntry<?, ?>[] array;
private final ImmSerMapEntry<?, ?>[] array;

private ImmSerMap(ImmSerMapEntry[] array) {
this.array = array;
}
private ImmSerMap(ImmSerMapEntry[] array) {
this.array = array;
}

private Map.Entry[] getEntries() {
return array;
private Map.Entry[] getEntries() {
return array;
}
}
}

private static class ImmSerMapEntry<K, V> implements Map.Entry<K, V>, Serializable {
private static class ImmSerMapEntry<K, V> implements Map.Entry<K, V>, Serializable {

private final Object[] entry;
private final Object[] entry;

private ImmSerMapEntry(Map.Entry<K, V> entry) {
this.entry = new Object[] { entry.getKey(), entry.getValue() };
}
private ImmSerMapEntry(Map.Entry<K, V> entry) {
this.entry = new Object[] { entry.getKey(), entry.getValue() };
}

@Override
public K getKey() {
return (K) entry[0];
}
@Override
public K getKey() {
return (K) entry[0];
}

@Override
public V getValue() {
return (V) entry[1];
}
@Override
public V getValue() {
return (V) entry[1];
}

@Override
public V setValue(V value) {
throw new UnsupportedOperationException();
@Override
public V setValue(V value) {
throw new UnsupportedOperationException();
}
}
}
}

0 comments on commit 5d35a7e

Please sign in to comment.