LayerSourceSerializer.java 3.85 KB
/*
 * 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() {
        }
    }

}