Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab93c73816c2f8900ae08c5418e76dc1aca17455 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*******************************************************************************
 * 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<Long, String[]> map, PropertyStore store, Enum<?> key) {
      storeToArrayMap(map, store.getPropertyStore(key.name()));
   }

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

   public static void loadMapLong(Map<Long, Long> map, PropertyStore store, Enum<?> key) {
      storeToMapLong(map, store.getPropertyStore(key.name()));
   }

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

   public static void putMapLong(PropertyStore store, Enum<?> key, Map<Long, Long> map) {
      store.put(key.name(), mapToStoreLong(map));
   }

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

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

   public static void loadTripletListForMergeBranches(List<Triplet<Long, Long, Long>> data, PropertyStore store, Enum<?> key) {
      storeToStringTripletListForMergeBranches(data, store.getPropertyStore(key.name()));
   }

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

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

   public static void putTripletLongList(PropertyStore store, Enum<?> key, List<Triplet<Long, Long, Long>> list) {
      store.put(key.name(), tripletLongListToStore(list));
   }

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

   private static PropertyStore longArrayMapToStore(Map<Long, Long[]> map) {
      PropertyStore innerStore = new PropertyStore();
      for (Entry<Long, Long[]> entry : map.entrySet()) {
         Long[] 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<Long, Integer> map) {
      PropertyStore innerStore = new PropertyStore();
      for (Entry<Long, Integer> entry : map.entrySet()) {
         innerStore.put(String.valueOf(entry.getKey()), entry.getValue());
      }
      return innerStore;
   }

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

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

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

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

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

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

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

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

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

   private static String getStringBranchGuid(Long second) {
      return String.valueOf(second);
   }

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

   public static void loadLongArrayMap(Map<Long, Long[]> map, PropertyStore store, Enum<?> key) {
      storeToLongArrayMap(map, store.getPropertyStore(key.name()));
   }

   public static void putLongArrayMap(PropertyStore store, Enum<?> key, Map<Long, Long[]> map) {
      store.put(key.name(), longArrayMapToStore(map));
   }

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

}

Back to the top