1 | // LableMapping.java |
---|
2 | // |
---|
3 | // (c) 1999-2001 PAL Development Core Team |
---|
4 | // |
---|
5 | // This package may be distributed under the |
---|
6 | // terms of the Lesser GNU General Public License (LGPL) |
---|
7 | |
---|
8 | package de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc; |
---|
9 | |
---|
10 | /** |
---|
11 | * Title: LabelMapping |
---|
12 | * Description: Allows for the substitution of one label for another |
---|
13 | * @author Matthew Goode |
---|
14 | * @version 1.0 |
---|
15 | */ |
---|
16 | import java.util.*; |
---|
17 | public class LabelMapping implements java.io.Serializable { |
---|
18 | Hashtable mappings_ = new Hashtable(); |
---|
19 | public LabelMapping() { } |
---|
20 | |
---|
21 | public void addMapping(String id, String label) { |
---|
22 | mappings_.put(id,label); |
---|
23 | } |
---|
24 | public void addMapping(Identifier id, String label) { |
---|
25 | if(id!=null&&id.getName()!=null) { |
---|
26 | mappings_.put(id.getName(),label); |
---|
27 | } |
---|
28 | } |
---|
29 | /** |
---|
30 | * @param names Names |
---|
31 | * @param colours associated colours |
---|
32 | * @note assumes parallel arrays |
---|
33 | */ |
---|
34 | public void addMappings(String[] ids, String[] labels) { |
---|
35 | for(int i = 0 ; i < ids.length ; i++) { |
---|
36 | mappings_.put(ids[i],labels[i]); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | public String getLabel(String id, String defaultLabel) { |
---|
41 | if(id==null||!mappings_.containsKey(id)) { |
---|
42 | return defaultLabel; |
---|
43 | } |
---|
44 | return mappings_.get(id).toString(); |
---|
45 | } |
---|
46 | public String getLabel(Identifier id, String defaultLabel) { |
---|
47 | if(id==null) { |
---|
48 | return defaultLabel; |
---|
49 | } |
---|
50 | return getLabel(id.getName(),defaultLabel); |
---|
51 | } |
---|
52 | public String getLabel(Identifier id) { |
---|
53 | return getLabel(id.getName(),id.getName()); |
---|
54 | } |
---|
55 | public Identifier getLabelIdentifier(Identifier id) { |
---|
56 | if(id==null) { |
---|
57 | return null; |
---|
58 | } |
---|
59 | return new Identifier(getLabel(id.getName(),id.getName())); |
---|
60 | } |
---|
61 | } |
---|