Skip to content

Commit

Permalink
Merge pull request #182 from mP1/feature/SpreadsheetExpressionFunctio…
Browse files Browse the repository at this point in the history
…nCellFormula

SpreadsheetExpressionFunctionCellFormula
  • Loading branch information
mP1 authored Oct 31, 2024
2 parents 79bd033 + c695145 commit cceac7d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Note the list is incomplete when compared to Excel and Sheets and should be cons
- cell
- cellFormattedValue
- cellFormatter
- cellFormula
- cellParser
- cellStyle
- cellValue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2022 Miroslav Pokorny (github.com/mP1)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package walkingkooka.spreadsheet.expression.function;

import walkingkooka.spreadsheet.SpreadsheetCell;
import walkingkooka.spreadsheet.SpreadsheetFormula;

/**
* A custom function that retrieves the {@link SpreadsheetFormula} for the current cell.
* <br>
* This function exists primarily to support filtering cells using a predicate of the current cell.
*/
final class SpreadsheetExpressionFunctionCellFormula extends SpreadsheetExpressionFunctionCell<SpreadsheetFormula> {

/**
* Singleton
*/
final static SpreadsheetExpressionFunctionCellFormula INSTANCE = new SpreadsheetExpressionFunctionCellFormula();

private SpreadsheetExpressionFunctionCellFormula() {
super("cellFormula");
}

@Override
public Class<SpreadsheetFormula> returnType() {
return SpreadsheetFormula.class;
}

@Override
SpreadsheetFormula extractCellPropertyOrNull(final SpreadsheetCell cell) {
return cell.formula();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static ExpressionFunctionProvider expressionFunctionProvider(final CaseSe
SpreadsheetExpressionFunctions.cell(),
SpreadsheetExpressionFunctions.cellFormattedValue(),
SpreadsheetExpressionFunctions.cellFormatter(),
SpreadsheetExpressionFunctions.cellFormula(),
SpreadsheetExpressionFunctions.cellParser(),
SpreadsheetExpressionFunctions.cellStyle(),
SpreadsheetExpressionFunctions.cellValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import walkingkooka.net.AbsoluteUrl;
import walkingkooka.reflect.PublicStaticHelper;
import walkingkooka.spreadsheet.SpreadsheetError;
import walkingkooka.spreadsheet.SpreadsheetFormula;
import walkingkooka.spreadsheet.expression.SpreadsheetExpressionEvaluationContext;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterSelector;
import walkingkooka.spreadsheet.parser.SpreadsheetParserSelector;
Expand Down Expand Up @@ -189,6 +190,13 @@ public static ExpressionFunction<SpreadsheetFormatterSelector, SpreadsheetExpres
return SpreadsheetExpressionFunctionCellFormatter.INSTANCE;
}

/**
* {@see SpreadsheetExpressionFunctionCellFormula}
*/
public static ExpressionFunction<SpreadsheetFormula, SpreadsheetExpressionEvaluationContext> cellFormula() {
return SpreadsheetExpressionFunctionCellFormula.INSTANCE;
}

/**
* {@see SpreadsheetExpressionFunctionCellParser}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2022 Miroslav Pokorny (github.com/mP1)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package walkingkooka.spreadsheet.expression.function;

import org.junit.jupiter.api.Test;
import walkingkooka.spreadsheet.SpreadsheetCell;
import walkingkooka.spreadsheet.SpreadsheetFormula;

public final class SpreadsheetExpressionFunctionCellFormulaTest extends SpreadsheetExpressionFunctionCellTestCase<SpreadsheetExpressionFunctionCellFormula, SpreadsheetFormula> {

@Override
public SpreadsheetExpressionFunctionCellFormula createBiFunction() {
return SpreadsheetExpressionFunctionCellFormula.INSTANCE;
}

@Override
SpreadsheetFormula valuePresent() {
return SpreadsheetFormula.EMPTY.setText("=1+2");
}

@Override
SpreadsheetFormula valueAbsent() {
return SpreadsheetFormula.EMPTY;
}

@Override
SpreadsheetCell setProperty(final SpreadsheetCell cell,
final SpreadsheetFormula formula) {
return cell.setFormula(formula);
}

// toString.........................................................................................................

@Test
public void testToString() {
this.toStringAndCheck(
this.createBiFunction(),
"cellFormula"
);
}

// class............................................................................................................

@Override
public Class<SpreadsheetExpressionFunctionCellFormula> type() {
return SpreadsheetExpressionFunctionCellFormula.class;
}
}

0 comments on commit cceac7d

Please sign in to comment.