All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jdash.client.response.LevelSearchResponseDeserializer Maven / Gradle / Ivy

The newest version!
package jdash.client.response;

import jdash.client.exception.ActionFailedException;
import jdash.common.entity.GDLevel;
import jdash.common.entity.GDSong;
import jdash.common.internal.GDCreatorInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static jdash.common.internal.InternalUtils.*;

class LevelSearchResponseDeserializer implements Function> {

    @Override
    public List apply(String response) {
        ActionFailedException.throwIfEquals(response, "-1", "Failed to load levels");
        ArrayList list = new ArrayList<>();
        String[] split1 = response.split("#");
        String levels = split1[0];
        String creators = split1[1];
        String songs = split1[2];
        Map structuredCreatorsInfo = structureCreatorsInfo(creators);
        Map structuredSongsInfo = structureSongsInfo(songs);
        String[] levelArray = levels.split("\\|");
        for (String l : levelArray) {
            Map data = splitToMap(l, ":");
            list.add(buildLevel(data, structuredCreatorsInfo, structuredSongsInfo));
        }
        return list;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy