source: FCSannotrans/trunk/src/main/java/nl/mpi/annot/translate/TranslationTypes.java @ 6988

Last change on this file since 6988 was 6979, checked in by peter.beinema@mpi.nl, 8 years ago

first upload

File size: 2.1 KB
Line 
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package nl.mpi.annot.translate;
7
8import java.util.ArrayList;
9import java.util.HashMap;
10
11/**
12 *
13 * @author petbei
14 */
15public class TranslationTypes {
16    private ArrayList<TranslationType> ttArray = new ArrayList<TranslationType>();
17    private HashMap<String, Integer> ttMap = new HashMap<String, Integer>();
18    private static int errorCount = 0;
19   
20    public TranslationType ErrorTranslationType;
21   
22    public TranslationTypes() {
23        ErrorTranslationType = new TranslationType("***_ERROR-AT-RESOURCE_***");
24    }
25   
26    TranslationType addTranslationType(String id) {
27        if (id == (String) null || id.length() <= 0) {
28            errorCount++;
29            System.out.println("*** ERROR *** TranslationTypes: attempt to define unique Formalism with illegal-value (null or empty) identifier");
30            return ErrorTranslationType;
31        }
32        if (ttMap.containsKey(id)) {
33            return ttArray.get(ttMap.get(id));
34        }
35        TranslationType nw = new TranslationType(id);
36        ttArray.add(nw);
37        ttMap.put(id, ttArray.size() - 1);
38        return nw;
39    }
40   
41    boolean haveTranslationType(String id) {
42        if (id == (String) null || id.length() <= 0) {
43            return false;
44        }
45        return (ttMap.containsKey(id));
46    }
47   
48    TranslationType getTranslationType(String id) {
49        if (id == (String) null || id.length() <= 0) {
50            return null;
51        }
52        if (ttMap.containsKey(id)) {
53            return ttArray.get(ttMap.get(id));
54        }
55        else {
56            return null;
57        }
58    }
59   
60    int getSize() {
61        return ttArray.size();
62    }
63   
64    void display() {
65        System.out.println("========== START TranslationTypes: " + ttArray.size() + " ==========");
66        for (TranslationType tt: ttArray) {
67            tt.display();
68        }
69        System.out.println("========== END TranslationTypes: " + ttArray.size() + " ==========\n");
70    } 
71}
Note: See TracBrowser for help on using the repository browser.