com.powsybl.powerfactory.model.AbstractPowerFactoryData Maven / Gradle / Ivy
The 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.powerfactory.model;
import com.fasterxml.jackson.core.JsonGenerator;
import com.powsybl.commons.json.JsonUtil;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
/**
* @author Geoffroy Jamgotchian {@literal }
*/
abstract class AbstractPowerFactoryData implements PowerFactoryData {
protected final String name;
protected final DataObjectIndex index;
protected AbstractPowerFactoryData(String name, DataObjectIndex index) {
this.name = Objects.requireNonNull(name);
this.index = Objects.requireNonNull(index);
}
public String getName() {
return name;
}
public DataObjectIndex getIndex() {
return index;
}
public abstract void writeJson(JsonGenerator generator) throws IOException;
public void writeJson(Writer writer) {
JsonUtil.writeJson(writer, generator -> {
try {
writeJson(generator);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
public void writeJson(Path file) {
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
writeJson(writer);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy