m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/EnvironmentRow.java
blob: afed3d2236bfa18e521b208f0e1db784f74540a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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<String, Integer> columns = new HashMap<String, Integer>();

    public EnvironmentRow(TableRow row, List<String> 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());
        }
    }
}