summaryrefslogtreecommitdiff
path: root/boil/library/TypeFactory.java
blob: c84f64e268f761edada2665e0a557e85865ff32e (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
41
42
43
package boil.library;

import java.util.HashMap;
import st.TypeInstance;

public class TypeFactory {

    private int type_num;
    private HashMap<TypeInstance,String> map;

    public void reset() {
        this.type_num = 0;
        this.map = new HashMap<>();
    }

    public String alias(TypeInstance t) {
        /**
         * Given a TypeInstance, return the designated
         * vapor alias. If the alias does not exist, create it.
         */
        String alias;
        if ((alias = this.map.get(t)) == null) {
            alias = String.format("t.%d", this.type_num++);
            this.map.put(t, alias);
        }

        return alias;
    }

    public String retrieveRecentList(int x) {
        /**
         * Given int x, retrieve a space-delimited
         * list of the x most recent entries.
         */
        String rtn = "";
        for (int i = type_num-x; i < type_num; ++i) {
            rtn += String.format(" t.%d",
                                 i);
        }

        return rtn;
    }
}