From f902f8cdb744b5b946780f9669b9ceebff535914 Mon Sep 17 00:00:00 2001 From: sraaphorst Date: Fri, 5 Jan 2018 16:22:25 -0300 Subject: [PATCH] REL-3342: Reverting to fix the break in serialization from deleting inner classes. --- .../edu/gemini/spModel/gemini/gpi/GpiCB.java | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/bundle/edu.gemini.pot/src/main/java/edu/gemini/spModel/gemini/gpi/GpiCB.java b/bundle/edu.gemini.pot/src/main/java/edu/gemini/spModel/gemini/gpi/GpiCB.java index 1c4c395b73..9343810d53 100644 --- a/bundle/edu.gemini.pot/src/main/java/edu/gemini/spModel/gemini/gpi/GpiCB.java +++ b/bundle/edu.gemini.pot/src/main/java/edu/gemini/spModel/gemini/gpi/GpiCB.java @@ -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; @@ -15,7 +17,6 @@ import edu.gemini.spModel.util.SPTreeUtil; import java.util.Collection; -import java.util.HashMap; import java.util.Map; /** @@ -29,7 +30,6 @@ public GpiCB(ISPObsComponent obsComp) { super(obsComp); } - @Override public Object clone() { GpiCB result = (GpiCB) super.clone(); result._sysConfig = null; @@ -44,46 +44,61 @@ protected void thisReset(Map 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 sysConfig = _sysConfig.getParameters(); + Collection sysConfig = _sysConfig.getParameters(); + + final class MagnitudeFilter implements Function1 { + 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 { + 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 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 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 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); - } } \ No newline at end of file