aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java
blob: acb6ef753c8842114d9fe34c0787481a5414aeb2 (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
29
30
31
32
33
34
35
36
37
38
39
40
package org.zwobble.couscous.interpreter.values;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.zwobble.couscous.values.PrimitiveValue;

public class ObjectInterpreterValue implements InterpreterValue {
    private final ConcreteType type;
    private final Map<String, InterpreterValue> fields;

    public ObjectInterpreterValue(ConcreteType type) {
        this.type = type;
        this.fields = new HashMap<>();
    }
    
    @Override
    public ConcreteType getType() {
        return type;
    }

    @Override
    public Optional<PrimitiveValue> toPrimitiveValue() {
        return Optional.empty();
    }

    @Override
    public InterpreterValue getField(String fieldName) {
        if (fields.containsKey(fieldName)) {
            return fields.get(fieldName);            
        } else {
            throw new UnsupportedOperationException();
        }
    }

    public void setField(String fieldName, InterpreterValue value) {
        fields.put(fieldName, value);
    }
}