
io.github.hlfsousa.ncml.examples.ucararray.GroupMapWrapper 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%
*/
import io.github.hlfsousa.ncml.io.ConvertUtils;
import io.github.hlfsousa.ncml.io.RuntimeConfiguration;
import io.github.hlfsousa.ncml.io.wrapper.NetcdfWrapper;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import ucar.ma2.*;
import ucar.nc2.Dimension;
import ucar.nc2.Group;
import ucar.nc2.Variable;
public class GroupMapWrapper extends NetcdfWrapper implements GroupMap {
private class ItemsWrapper implements ItemsVariable {
private final Variable variable;
private Array value;
public ItemsWrapper(Variable variable) {
this.variable = variable;
}
@Override
public Array getValue() {
if (value == null) {
value = getNumericArray(variable);
}
return value;
}
@Override
public void setValue(Array value) {
throw new UnsupportedOperationException();
}
public List getDimensions() {
return variable.getDimensions();
}
public void setDimensions(List dimensions) {
throw new UnsupportedOperationException();
}
}
public GroupMapWrapper(Group group, RuntimeConfiguration runtimeConfiguration) {
super(group, runtimeConfiguration);
}
private ConvertUtils convertUtils = ConvertUtils.getInstance();
private Map variableCache = new HashMap();
// additionalFields >>
// << additionalFields
@SuppressWarnings("unchecked")
public ItemsVariable getItems() {
return (ItemsVariable) variableCache.computeIfAbsent("items",
varName -> Optional.ofNullable(group.findVariable(varName))
.map(ItemsWrapper::new)
.orElse(null));
}
public void setItems(ItemsVariable items) {
throw new UnsupportedOperationException();
}
@Override
public String getName() {
return Optional.ofNullable(group.findAttribute("name"))
.map(name -> name.getStringValue())
.orElse(null);
}
@Override
public void setName(String name) {
throw new UnsupportedOperationException();
}
// additionalMethods >>
// << additionalMethods
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy