Skip to content

Commit 297f7f5

Browse files
committed
clear cached values (min/max, range) when removing / updating an expression column
1 parent 0b47d6f commit 297f7f5

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/main/java/fr/jmmc/oitools/fits/FitsTable.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,19 @@ protected final void clearColumnsRangeValue() {
10631063
}
10641064
}
10651065

1066+
/**
1067+
* Clear the Map storing min/max column values for the given column name
1068+
* @param name column name
1069+
*/
1070+
protected final void clearColumnsRangeValue(final String name) {
1071+
if (this.columnsRangeValue != null) {
1072+
// see getColumnRange(name):
1073+
final String key = name + "_RANGE";
1074+
columnsRangeValue.remove(key); // Range
1075+
columnsRangeValue.remove(name); // [min;max] values
1076+
}
1077+
}
1078+
10661079
/**
10671080
* Return the Map storing min/max column values
10681081
*
@@ -1086,7 +1099,7 @@ public Range getColumnRange(final String name) {
10861099
final String key = name + "_RANGE";
10871100

10881101
/* retrieve value in columnsRangeValue map of associated column */
1089-
Range cached = (Range) getColumnsRangeValue().get(key);
1102+
Range cached = (Range) getColumnsRangeValue().get(key); // Range
10901103

10911104
if (cached == null) {
10921105
final Object range = getMinMaxColumnValue(name);

src/main/java/fr/jmmc/oitools/model/OIData.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ public final boolean[][] getFlag() {
312312
* @throws RuntimeException
313313
*/
314314
public void checkExpression(final String name, final String expression) throws RuntimeException {
315-
316315
// Test if name conflicts with standard columns (VIS2DATA)
317316
if (getColumnDesc(name) != null) {
318317
throw new IllegalArgumentException("Column name [" + name + "] already existing (OIFITS standard) !");
@@ -331,11 +330,12 @@ public void updateExpressionColumn(final String name, final String expression) {
331330
// remove column (descriptor and values) if existing:
332331
removeExpressionColumn(name);
333332

334-
addDerivedColumnMeta(new WaveColumnMeta(name, "expression: " + expression,
335-
Types.TYPE_DBL, this, expression));
333+
final WaveColumnMeta colMeta = new WaveColumnMeta(name, "expression: " + expression,
334+
Types.TYPE_DBL, this, expression);
335+
addDerivedColumnMeta(colMeta);
336336

337337
// Force computation now (not lazy):
338-
getExprColumnDoubles(name, expression);
338+
getExprColumnDoubles(name, colMeta);
339339
}
340340

341341
/**
@@ -345,6 +345,9 @@ public void updateExpressionColumn(final String name, final String expression) {
345345
public void removeExpressionColumn(final String name) {
346346
final ColumnMeta column = getColumnDerivedDesc(name);
347347

348+
// anyway clear cached values:
349+
clearColumnsRangeValue(name);
350+
348351
// check if the column has an expression
349352
if (column instanceof WaveColumnMeta) {
350353
final WaveColumnMeta colMeta = (WaveColumnMeta) column;
@@ -512,19 +515,19 @@ protected double[][] getSpatialCoord(final String name, final String coordName)
512515
}
513516

514517
/**
515-
* Return the array with the given expression
518+
* Return the computed expression f[x][y] for the given column name
516519
* @param name derived column name
517-
* @param expression expression entered by the user
520+
* @param colMeta the corresponding column descriptor
518521
* @return the computed expression f[x][y]
519522
*/
520-
protected double[][] getExprColumnDoubles(final String name, final String expression) {
523+
protected double[][] getExprColumnDoubles(final String name, final WaveColumnMeta colMeta) {
521524
// lazy: get previously computed results:
522525
double[][] exprResults = this.getColumnDerivedDoubles(name);
523526

524527
// check if expression changed ?
525-
if (exprResults == null) {
528+
if ((exprResults == null) && (colMeta.getExpression() != null)) {
526529
// not computed; do it now (LAZY):
527-
exprResults = ExpressionEvaluator.getInstance().eval(this, name, expression, false);
530+
exprResults = ExpressionEvaluator.getInstance().eval(this, name, colMeta.getExpression(), false);
528531

529532
// store computed results for next time:
530533
this.setColumnDerivedValue(name, exprResults);
@@ -957,14 +960,12 @@ protected double[][] getDerivedColumnAsDoubles(final String name) {
957960
return getSpatialFreq();
958961
}
959962
// handle user expressions
960-
for (ColumnMeta column : getColumnDerivedDescCollection()) {
961-
if (column.getName().equals(name)) {
962-
if (column instanceof WaveColumnMeta) {
963-
WaveColumnMeta colMeta = (WaveColumnMeta) column;
963+
for (final ColumnMeta column : getColumnDerivedDescCollection()) {
964+
if (column.getName().equals(name) && (column instanceof WaveColumnMeta)) {
965+
final WaveColumnMeta colMeta = (WaveColumnMeta) column;
964966

965-
if (colMeta.getExpression() != null) {
966-
return getExprColumnDoubles(name, colMeta.getExpression());
967-
}
967+
if (colMeta.getExpression() != null) {
968+
return getExprColumnDoubles(name, colMeta);
968969
}
969970
}
970971
}

0 commit comments

Comments
 (0)