
io.github.hlfsousa.ncml.examples.ucararray.SampleModelInitializer Maven / Gradle / Ivy
package io.github.hlfsousa.ncml.examples.ucararray;
/*-
* #%L
* ncml-io
* %%
* Copyright (C) 2020 - 2021 Henrique L. F. de Sousa
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
// imports >>
import java.util.*;
import java.util.function.Consumer;
import io.github.hlfsousa.ncml.io.ArrayUtils;
import ucar.nc2.Dimension;
import ucar.ma2.Array;
import io.github.hlfsousa.ncml.examples.ucararray.SampleModel.*;
import io.github.hlfsousa.ncml.examples.ucararray.SampleModelVO.*;
// << imports
public class SampleModelInitializer {
private static final Map> INITIALIZERS = new HashMap<>();
static {
INITIALIZERS.put(null, model -> {
if (model.getTitle() == null) {
model.setTitle("Sample NetCDF file");
}
// customGroupInit >>
// << customGroupInit
});
// userGroupInitializers >>
// << userGroupInitializers
}
public static SampleModel initialize(SampleModel value) {
return initialize(null, value);
}
public static SampleModel initialize(String key, SampleModel value) {
if (value == null) {
value = new SampleModelVO();
}
if (!INITIALIZERS.containsKey(key)) {
key = null;
}
INITIALIZERS.get(key).accept(value);
return value;
}
public static class TemperatureMapInitializer {
private static final Map>> INITIALIZERS = new HashMap<>();
static {
INITIALIZERS.put(null, model -> {
if (model.getUnits() == null) {
model.setUnits("Celsius degrees");
}
// customInit_temperatureMap >>
// << customInit_temperatureMap
});
// userInitializers_temperatureMap >>
// << userInitializers_temperatureMap
}
public static TemperatureMapVariable initialize(TemperatureMapVariable value) {
return initialize(null, value);
}
public static TemperatureMapVariable initialize(String key, TemperatureMapVariable value) {
if (value == null) {
value = new TemperatureMapVO();
}
INITIALIZERS.get(key).accept(value);
return value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy