AggregatorYoungest extends AbstractAggregator { public AggregatorYoungest(VariableContext varCtx, String mjdVarName, float referenceMjd, String... varNames) { super(Descriptor.NAME, createIntermediateFeatureNames(mjdVarName, varNames), createIntermediateFeatureNames(mjdVarName, varNames), createOutputFeatureNames(mjdVarName, varNames)); if (varCtx == null) { throw new NullPointerException("varCtx"); } if (varNames == null) { throw new NullPointerException("varNames"); } if (varNames.length == 0) { throw new NullPointerException("varNames"); } this.referenceMjd = referenceMjd; numVariables = varNames.length; varIndices = new int[varNames.length]; for (int i = 0; i < varNames.length; i++) { int varIndex = varCtx.getVariableIndex(varNames[i]); if (varIndex < 0) { throw new IllegalArgumentException("varIndices[" + i + "] < 0"); } varIndices[i] = varIndex; } } AggregatorYoungest(VariableContext varCtx, String mjdVarName, float referenceMjd, String... varNames); @Override void initSpatial(BinContext ctx, WritableVector vector); @Override void aggregateSpatial(BinContext ctx, Observation observationVector, WritableVector spatialVector); @Override void completeSpatial(BinContext ctx, int numObs, WritableVector numSpatialObs); @Override void initTemporal(BinContext ctx, WritableVector vector); @Override void aggregateTemporal(BinContext ctx, Vector spatialVector, int numSpatialObs,
                                  WritableVector temporalVector); @Override void completeTemporal(BinContext ctx, int numTemporalObs, WritableVector temporalVector); @Override void computeOutput(Vector temporalVector, WritableVector outputVector); @Override String toString(); boolean requiresGrowableSpatialData();  }
@Test public void testAggregatorYoungest() { VectorImpl svec = vec(NaN, NaN); VectorImpl tvec = vec(NaN, NaN); VectorImpl out = vec(NaN, NaN); agg.initSpatial(ctx, svec); assertEquals(Float.NaN, svec.get(0), 0.0f); agg.aggregateSpatial(ctx, obs(6, 0.99f, 0.88f, 5.5f), svec); agg.aggregateSpatial(ctx, obs(4, 0.99f, 0.88f, NaN), svec); agg.aggregateSpatial(ctx, obs(5, 0.99f, 0.88f, 0.1f), svec); assertEquals(5.5f, svec.get(0), 1e-5f); agg.completeSpatial(ctx, 3, svec); assertEquals(5.5f, svec.get(0), 1e-5f); agg.initTemporal(ctx, tvec); assertEquals(NaN, tvec.get(0), 0.0f); agg.aggregateTemporal(ctx, vec(0.3f, 7), 3, tvec); agg.aggregateTemporal(ctx, vec(1.1f, 9), 3, tvec); agg.aggregateTemporal(ctx, vec(4.7f, 8), 3, tvec); agg.completeTemporal(ctx, 3, tvec); assertEquals(1.1f, tvec.get(0), 1e-5f); assertEquals(9, tvec.get(1), 1e-5f); agg.computeOutput(tvec, out); assertEquals(1.1f, out.get(1), 1e-5f); assertEquals(9, out.get(0), 1e-5f); }