Skip to content

Commit

Permalink
REL-3342: Reverting to fix the break in serialization from deleting i…
Browse files Browse the repository at this point in the history
…nner classes.
  • Loading branch information
sraaphorst committed Jan 5, 2018
1 parent 4c8f234 commit f902f8c
Showing 1 changed file with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.gemini.spModel.gemini.gpi;

import edu.gemini.pot.sp.ISPObsComponent;
import edu.gemini.shared.util.immutable.ApplyOp;
import edu.gemini.shared.util.immutable.Function1;
import edu.gemini.shared.util.immutable.ImList;
import edu.gemini.spModel.config.AbstractObsComponentCB;
import edu.gemini.spModel.core.Magnitude;
Expand All @@ -15,7 +17,6 @@
import edu.gemini.spModel.util.SPTreeUtil;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -29,7 +30,6 @@ public GpiCB(ISPObsComponent obsComp) {
super(obsComp);
}

@Override
public Object clone() {
GpiCB result = (GpiCB) super.clone();
result._sysConfig = null;
Expand All @@ -44,46 +44,61 @@ protected void thisReset(Map<String, Object> options) {
_sysConfig = dataObj.getSysConfig();
}

@Override
protected boolean thisHasConfiguration() {
if (_sysConfig == null)
return false;
return (_sysConfig.getParameterCount() > 0);
}

@Override
protected void thisApplyNext(final IConfig config, final IConfig prevFull) {
protected void thisApplyNext(final IConfig config, IConfig prevFull) {
final String systemName = _sysConfig.getSystemName();
final Collection<IParameter> sysConfig = _sysConfig.getParameters();
Collection<IParameter> sysConfig = _sysConfig.getParameters();

final class MagnitudeFilter implements Function1<Magnitude, Boolean> {
private final MagnitudeBand band;

private MagnitudeFilter(MagnitudeBand band) {
this.band = band;
}

@Override
public Boolean apply(Magnitude magnitude) {
return magnitude.band().equals(band);
}
}

final class MagnitudeSetter implements ApplyOp<Magnitude> {
private final String magProp;

private MagnitudeSetter(String magHProp) {
this.magProp = magHProp;
}

for (final IParameter param : sysConfig) {
@Override
public void apply(Magnitude magnitude) {
config.putParameter(systemName,
DefaultParameter.getInstance(magProp,
magnitude.value()));
}
}
for (IParameter param : sysConfig) {
config.putParameter(systemName,
DefaultParameter.getInstance(param.getName(), param.getValue()));
}
config.putParameter(systemName,
StringParameter.getInstance(InstConstants.INSTRUMENT_NAME_PROP,
Gpi.INSTRUMENT_NAME_PROP));

// Set the magnitude properties.
final ISPObsComponent targetcomp = SPTreeUtil.findTargetEnvNode(getObsComponent().getContextObservation());
if (targetcomp != null) {
final TargetObsComp toc = (TargetObsComp) targetcomp.getDataObject();
if (toc != null) {
// The Asterism here should be Single(base), so we only need to concern ourselves with the head target.
toc.getAsterism().allSpTargetsJava().headOption().foreach(base -> {
final ImList<Magnitude> magnitudes = base.getMagnitudesJava();
MAG_PROPERTIES.forEach((band, propName) ->
magnitudes.find(m -> m.band().equals(band)).
foreach(mag -> config.putParameter(systemName, DefaultParameter.getInstance(propName, mag.value()))));
});
if (toc.getAsterism().allSpTargetsJava().head() != null) {
ImList<Magnitude> magnitudes = toc.getAsterism().allSpTargetsJava().head().getMagnitudesJava();
magnitudes.filter(new MagnitudeFilter(MagnitudeBand.H$.MODULE$)).headOption().foreach(new MagnitudeSetter(Gpi.MAG_H_PROP));
magnitudes.filter(new MagnitudeFilter(MagnitudeBand.I$.MODULE$)).headOption().foreach(new MagnitudeSetter(Gpi.MAG_I_PROP));
}
}
}
}

// The magnitude bands of interest and their property names in the configuration.
private static final Map<MagnitudeBand, String> MAG_PROPERTIES = new HashMap<>();
static {
MAG_PROPERTIES.put(MagnitudeBand.H$.MODULE$, Gpi.MAG_H_PROP);
MAG_PROPERTIES.put(MagnitudeBand.I$.MODULE$, Gpi.MAG_I_PROP);
}
}

0 comments on commit f902f8c

Please sign in to comment.