From a014f22d8c8c5c15aa08500a02da0d0717d62b64 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 13 Nov 2019 21:06:46 +0100 Subject: Pass interpreter tests --- .../cloudatlas/interpreter/EnvironmentRow.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/interpreter/EnvironmentRow.java (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/interpreter/EnvironmentRow.java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/EnvironmentRow.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/EnvironmentRow.java new file mode 100644 index 0000000..76a9cf2 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/EnvironmentRow.java @@ -0,0 +1,28 @@ +package pl.edu.mimuw.cloudatlas.interpreter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import pl.edu.mimuw.cloudatlas.model.ValueNull; + +class EnvironmentRow extends Environment { + private final TableRow row; + private final Map columns = new HashMap(); + + public EnvironmentRow(TableRow row, List columns) { + this.row = row; + int i = 0; + for(String c : columns) + this.columns.put(c, i++); + } + + public Result getIdent(String ident) { + try { + return new ResultSingle(row.getIth(columns.get(ident))); + } catch(NullPointerException exception) { + return new ResultSingle(ValueNull.getInstance()); + } + } +} + -- cgit v1.2.3