LayerSourceSerializer.java
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.KeyValuePair
* com.scene7.is.util.collections.CollectionUtil
* com.scene7.is.util.collections.MapEntry
* com.scene7.is.util.collections.NullSafeMap
* com.scene7.is.util.serializers.EnumSerializer
* com.scene7.is.util.serializers.Serializer
* org.jetbrains.annotations.NotNull
*/
package com.scene7.is.ps.provider;
import com.scene7.is.ps.provider.EmbeddedLayerSource;
import com.scene7.is.ps.provider.ImageLayerSource;
import com.scene7.is.ps.provider.LayerSource;
import com.scene7.is.util.KeyValuePair;
import com.scene7.is.util.collections.CollectionUtil;
import com.scene7.is.util.collections.MapEntry;
import com.scene7.is.util.collections.NullSafeMap;
import com.scene7.is.util.serializers.EnumSerializer;
import com.scene7.is.util.serializers.Serializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
public class LayerSourceSerializer
implements Serializer<LayerSource> {
private static final Serializer<LayerSource> INSTANCE = new LayerSourceSerializer();
private static final Serializer<SourceType> SOURCE_TYPE_SERIALIZER = EnumSerializer.enumSerializer(SourceType.class);
private static final NullSafeMap<Class<LayerSource>, KeyValuePair<SourceType, Serializer<LayerSource>>> SERIALIZER_MAP = CollectionUtil.nullSafe((Map)CollectionUtil.mapOf((MapEntry[])new MapEntry[]{LayerSourceSerializer.mapEntry(ImageLayerSource.class, SourceType.IMAGE, ImageLayerSource.imageLayerSourceSerializer()), LayerSourceSerializer.mapEntry(EmbeddedLayerSource.class, SourceType.EMBEDDED, EmbeddedLayerSource.embeddedLayerSourceSerializer())}));
private static final NullSafeMap<SourceType, Serializer<LayerSource>> REVERSE_SERIALIZER_MAP = CollectionUtil.nullSafe((Map)CollectionUtil.mapOf((MapEntry[])new MapEntry[]{LayerSourceSerializer.mapEntry(SourceType.IMAGE, ImageLayerSource.imageLayerSourceSerializer()), LayerSourceSerializer.mapEntry(SourceType.EMBEDDED, EmbeddedLayerSource.embeddedLayerSourceSerializer())}));
@NotNull
public static Serializer<LayerSource> layerSourceSerializer() {
return INSTANCE;
}
@NotNull
private static <T extends LayerSource> MapEntry<SourceType, Serializer<LayerSource>> mapEntry(@NotNull SourceType sourceType, @NotNull Serializer<T> serializer) {
return MapEntry.mapEntry((Object)((Object)sourceType), serializer);
}
@NotNull
private static <T extends LayerSource> MapEntry<Class<LayerSource>, KeyValuePair<SourceType, Serializer<LayerSource>>> mapEntry(@NotNull Class<T> clazz, @NotNull SourceType sourceType, @NotNull Serializer<T> serializer) {
Class<T> key = clazz;
KeyValuePair value = KeyValuePair.keyValuePair((Object)((Object)sourceType), serializer);
return MapEntry.mapEntry(key, (Object)value);
}
public LayerSource load(@NotNull DataInput in) throws IOException {
SourceType type = (SourceType)((Object)SOURCE_TYPE_SERIALIZER.load(in));
Serializer serializer = (Serializer)REVERSE_SERIALIZER_MAP.get((Object)type);
return (LayerSource)serializer.load(in);
}
public void store(LayerSource value, @NotNull DataOutput out) throws IOException {
KeyValuePair pair = (KeyValuePair)SERIALIZER_MAP.get(value.getClass());
SourceType type = (SourceType)((Object)pair.key);
Serializer serializer = (Serializer)pair.value;
SOURCE_TYPE_SERIALIZER.store((Object)type, out);
serializer.store((Object)value, out);
}
public int dataLength() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
private LayerSourceSerializer() {
}
private static enum SourceType {
IMAGE,
EMBEDDED;
private SourceType() {
}
}
}