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

Last change on this file since 6988 was 6988, checked in by Leif-Jöran, 8 years ago

Completing the translation configuration test from provided file by printing the annotation tables instead of trying to find CGN tables to test if there are no CGN translation types provided.

File size: 3.7 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;
10import java.util.List;
11
12/**
13 *
14 * @author petbei
15 */
16public class TranslationTables {
17    private ArrayList<TranslationTable> translationTableArray = null;
18    private HashMap<String, Integer> translationTableMap = null;
19   
20    public TranslationTables() {
21        //System.err.println("--- LOG --- created \"TranslationTables\" object");
22        translationTableArray = new ArrayList<TranslationTable>();
23        translationTableMap = new HashMap<String, Integer>();
24    }
25   
26    TranslationTable addTranslationTable(ResourceLayer fromRL, ResourceLayer toRL, TranslationType transType) throws ATException {
27        //--- check validity of parameters
28        if (fromRL == null) {
29            System.out.println("*** ERROR *** TranslationTables: attempt to add NULL 'from' ResourceLayer name - skipped");
30            throw new ATException("definition of TranslationTable: null 'from' ResourceLayer");
31        }
32        if (toRL == null) {
33            System.out.println("*** ERROR *** TranslationTables: attempt to add NULL 'to' ResourceLayer name - skipped");
34            throw new ATException("definition of TranslationTable: null 'to' ResourceLayer");
35        }
36        if (transType == null) {
37            System.out.println("*** ERROR *** TranslationTables: attempt to add NULL or empty translation type object - skipped");
38            throw new ATException("definition of translationTable: null translation type");
39        }
40       
41        //--- check if Resource/Layer combination is already defined
42        if (fromRL.getName().equals(toRL.getName())) {
43            System.out.println("*** ERROR *** new TranslationTable: 'from' and 'to' Resource/Layers are the same - ignored");
44            throw new ATException("definition of translationTable: 'from' and 'to' Resource/Layers are the same");
45        }
46        String transTabKey = fromRL.getName() + "-" + toRL.getName() + "=" + transType.getId();
47        if (translationTableMap.containsKey(transTabKey)) {
48            System.out.println("*** ERROR *** TranslationTable \"" + transTabKey + "\" was already defined - ignored");
49            throw new ATException("definition of translationTable: '" + transTabKey + "' was already defined");           
50        }
51        //--- not defined; create new one
52        TranslationTable nw = new TranslationTable(transTabKey, fromRL, toRL, transType);
53        translationTableArray.add(nw);
54        translationTableMap.put(transTabKey, translationTableArray.size() - 1);
55        return nw;
56    }
57
58    public List<TranslationTable> getList() {
59        return translationTableArray;
60    }
61   
62    TranslationTable find(String fromRes, String fromLay, String toRes, String toLay, TranslationType ty) {
63        String fromResLayId = fromRes + "/" + fromLay;
64        String toResLayId = toRes + "/" + toLay;
65        String tableId = fromResLayId + "-" + toResLayId + "=" + ty.getId();
66        if (translationTableMap.containsKey(tableId)) {
67            return translationTableArray.get(translationTableMap.get(tableId));
68        }
69        else {
70            System.err.println("*** ERROR *** failed to find translation table " + tableId);
71            return null;
72        }
73    }
74   
75    void display() {
76        System.out.println("========== START list of TranslationTables ==========");
77        for (TranslationTable tt: translationTableArray) {
78            tt.display();
79        }
80        System.out.println("========== END list of TranslationTables ==========\n");
81    }
82}
Note: See TracBrowser for help on using the repository browser.