Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2f62fc65a5e993118e6b51d1ebd50e5687a5950b (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*******************************************************************************
 * Copyright (c) 2009 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.message;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
import org.eclipse.osee.framework.jdk.core.type.Triplet;

/**
 * @author Roberto E. Escobar
 */
public final class TranslationUtil {

   private TranslationUtil() {
      //Utility Class
   }

   public static void loadArrayMap(Map<Integer, String[]> map, PropertyStore store, Enum<?> key) {
      storeToArrayMap(map, store.getPropertyStore(key.name()));
   }

   public static void loadMap(Map<Integer, Integer> map, PropertyStore store, Enum<?> key) {
      storeToMap(map, store.getPropertyStore(key.name()));
   }

   public static void putMap(PropertyStore store, Enum<?> key, Map<Integer, Integer> map) {
      store.put(key.name(), mapToStore(map));
   }

   public static void putArrayMap(PropertyStore store, Enum<?> key, Map<Integer, String[]> map) {
      store.put(key.name(), arrayMapToStore(map));
   }

   public static void loadTripletList(List<Triplet<String, String, String>> data, PropertyStore store, Enum<?> key) {
      storeToTripletList(data, store.getPropertyStore(key.name()));
   }

   public static void putTripletList(PropertyStore store, Enum<?> key, List<Triplet<String, String, String>> list) {
      store.put(key.name(), tripletListToStore(list));
   }

   private static PropertyStore arrayMapToStore(Map<Integer, String[]> map) {
      PropertyStore innerStore = new PropertyStore();
      for (Entry<Integer, String[]> entry : map.entrySet()) {
         innerStore.put(String.valueOf(entry.getKey()), entry.getValue());
      }
      return innerStore;
   }

   private static PropertyStore intArrayMapToStore(Map<Integer, Integer[]> map) {
      PropertyStore innerStore = new PropertyStore();
      for (Entry<Integer, Integer[]> entry : map.entrySet()) {
         Integer[] values = entry.getValue();
         String[] data = new String[values.length];
         for (int index = 0; index < values.length; index++) {
            data[index] = String.valueOf(values[index]);
         }
         innerStore.put(String.valueOf(entry.getKey()), data);
      }
      return innerStore;
   }

   private static PropertyStore mapToStore(Map<Integer, Integer> map) {
      PropertyStore innerStore = new PropertyStore();
      for (Entry<Integer, Integer> entry : map.entrySet()) {
         innerStore.put(String.valueOf(entry.getKey()), entry.getValue());
      }
      return innerStore;
   }

   private static void storeToMap(Map<Integer, Integer> map, PropertyStore innerStore) {
      for (String strkey : innerStore.keySet()) {
         Integer key = Integer.valueOf(strkey);
         Integer value = innerStore.getInt(strkey);
         map.put(key, value);
      }
   }

   private static void storeToArrayMap(Map<Integer, String[]> map, PropertyStore innerStore) {
      for (String strkey : innerStore.arrayKeySet()) {
         Integer key = Integer.valueOf(strkey);
         String[] value = innerStore.getArray(strkey);
         map.put(key, value);
      }
   }

   private static void storeToIntArrayMap(Map<Integer, Integer[]> map, PropertyStore innerStore) {
      for (String strkey : innerStore.arrayKeySet()) {
         Integer key = Integer.valueOf(strkey);
         String[] value = innerStore.getArray(strkey);
         Integer[] intValues = new Integer[value.length];
         for (int index = 0; index < value.length; index++) {
            intValues[index] = Integer.valueOf(value[index]);
         }
         map.put(key, intValues);
      }
   }

   private static void storeToTripletList(List<Triplet<String, String, String>> data, PropertyStore innerStore) {
      for (String strKey : innerStore.arrayKeySet()) {
         String[] value = innerStore.getArray(strKey);
         data.add(new Triplet<String, String, String>(value[0], value[1], value[2]));
      }
   }

   private static PropertyStore tripletListToStore(List<Triplet<String, String, String>> list) {
      PropertyStore innerStore = new PropertyStore();
      int index = 0;
      for (Triplet<String, String, String> entry : list) {
         innerStore.put(String.valueOf(index), new String[] {entry.getFirst(), entry.getSecond(), entry.getThird()});
         index++;
      }
      return innerStore;
   }

   public static void loadIntArrayMap(Map<Integer, Integer[]> map, PropertyStore store, Enum<?> key) {
      storeToIntArrayMap(map, store.getPropertyStore(key.name()));
   }

   public static void putIntArrayMap(PropertyStore store, Enum<?> key, Map<Integer, Integer[]> map) {
      store.put(key.name(), intArrayMapToStore(map));
   }

   public static String createKey(Enum<?> prefix, int index) {
      return prefix.name() + "_" + index;
   }
}

Back to the top