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

com.powsybl.contingency.json.ContingencyListDeserializer Maven / Gradle / Ivy

There is a newer version: 6.6.0
Show newest version
/**
 * Copyright (c) 2022, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.contingency.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.powsybl.contingency.contingency.list.ContingencyList;
import com.powsybl.contingency.contingency.list.IdentifierContingencyListDeserializer;

import java.io.IOException;

/**
 * @author Etienne Lesot {@literal }
 */
public class ContingencyListDeserializer extends StdDeserializer {

    public ContingencyListDeserializer() {
        super(ContingencyList.class);
    }

    @Override
    public ContingencyList deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
        parser.nextToken();
        while (parser.currentName() != null) {
            if ("type".equals(parser.currentName())) {
                switch (parser.nextTextValue()) {
                    case "default" -> {
                        DefaultContingencyListDeserializer defaultContingencyListDeserializer = new DefaultContingencyListDeserializer();
                        return defaultContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "injectionCriterion" -> {
                        InjectionCriterionContingencyListDeserializer injectionCriterionContingencyListDeserializer = new InjectionCriterionContingencyListDeserializer();
                        return injectionCriterionContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "hvdcCriterion" -> {
                        HvdcLineCriterionContingencyListDeserializer hvdcLineCriterionContingencyListDeserializer = new HvdcLineCriterionContingencyListDeserializer();
                        return hvdcLineCriterionContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "lineCriterion" -> {
                        LineCriterionContingencyListDeserializer lineCriterionContingencyListDeserializer = new LineCriterionContingencyListDeserializer();
                        return lineCriterionContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "twoWindingsTransformerCriterion" -> {
                        TwoWindingsTransformerCriterionContingencyListDeserializer twoWindingsTransformerCriterionContingencyListDeserializer = new TwoWindingsTransformerCriterionContingencyListDeserializer();
                        return twoWindingsTransformerCriterionContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "threeWindingsTransformerCriterion" -> {
                        ThreeWindingsTransformerCriterionContingencyListDeserializer threeWindingsTransformerCriterionContingencyListDeserializer = new ThreeWindingsTransformerCriterionContingencyListDeserializer();
                        return threeWindingsTransformerCriterionContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "tieLineCriterion" -> {
                        TieLineCriterionContingencyListDeserializer tieLineCriterionContingencyListDeserializer = new TieLineCriterionContingencyListDeserializer();
                        return tieLineCriterionContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "list" -> {
                        ListOfContingencyListsDeserializer listOfContingencyListsDeserializer = new ListOfContingencyListsDeserializer();
                        return listOfContingencyListsDeserializer.deserialize(parser, deserializationContext);
                    }
                    case "identifier" -> {
                        IdentifierContingencyListDeserializer identifierContingencyListDeserializer = new IdentifierContingencyListDeserializer();
                        return identifierContingencyListDeserializer.deserialize(parser, deserializationContext);
                    }
                    default -> throw new IllegalStateException("Unexpected field: " + parser.currentName());
                }
            }
            parser.nextToken();
        }
        throw new IllegalArgumentException("contingency List needs a type");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy