/******************************************************************************* * 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 map, PropertyStore store, Enum key) { storeToArrayMap(map, store.getPropertyStore(key.name())); } public static void loadMap(Map map, PropertyStore store, Enum key) { storeToMap(map, store.getPropertyStore(key.name())); } public static void loadMapLong(Map map, PropertyStore store, Enum key) { storeToMapLong(map, store.getPropertyStore(key.name())); } public static void putMap(PropertyStore store, Enum key, Map map) { store.put(key.name(), mapToStore(map)); } public static void putMapLong(PropertyStore store, Enum key, Map map) { store.put(key.name(), mapToStoreLong(map)); } public static void putArrayMap(PropertyStore store, Enum key, Map map) { store.put(key.name(), arrayMapToStore(map)); } public static void loadTripletList(List> data, PropertyStore store, Enum key) { storeToStringTripletList(data, store.getPropertyStore(key.name())); } public static void loadTripletListForMergeBranches(List> data, PropertyStore store, Enum key) { storeToStringTripletListForMergeBranches(data, store.getPropertyStore(key.name())); } public static void loadTripletLongList(List> data, PropertyStore store, Enum key) { storeToTripletList(data, store.getPropertyStore(key.name())); } public static void putTripletList(PropertyStore store, Enum key, List> list) { store.put(key.name(), tripletListToStore(list)); } public static void putTripletLongList(PropertyStore store, Enum key, List> list) { store.put(key.name(), tripletLongListToStore(list)); } private static PropertyStore arrayMapToStore(Map map) { PropertyStore innerStore = new PropertyStore(); for (Entry entry : map.entrySet()) { innerStore.put(String.valueOf(entry.getKey()), entry.getValue()); } return innerStore; } private static PropertyStore longArrayMapToStore(Map map) { PropertyStore innerStore = new PropertyStore(); for (Entry 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 map) { PropertyStore innerStore = new PropertyStore(); for (Entry entry : map.entrySet()) { innerStore.put(String.valueOf(entry.getKey()), entry.getValue()); } return innerStore; } private static PropertyStore mapToStoreLong(Map map) { PropertyStore innerStore = new PropertyStore(); for (Entry entry : map.entrySet()) { innerStore.put(String.valueOf(entry.getKey()), entry.getValue()); } return innerStore; } private static void storeToMap(Map 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 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 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 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> data, PropertyStore innerStore) { for (String strKey : innerStore.arrayKeySet()) { String[] value = innerStore.getArray(strKey); data.add(new Triplet(Long.valueOf(value[0]), Long.valueOf(value[1]), Long.valueOf(value[2]))); } } private static void storeToStringTripletList(List> data, PropertyStore innerStore) { for (String strKey : innerStore.arrayKeySet()) { String[] value = innerStore.getArray(strKey); data.add(new Triplet(Long.valueOf(value[0]), Long.valueOf(value[1]), Long.valueOf(value[2]))); } } private static void storeToStringTripletListForMergeBranches(List> data, PropertyStore innerStore) { for (String strKey : innerStore.arrayKeySet()) { String[] value = innerStore.getArray(strKey); data.add(new Triplet(Long.valueOf(value[0]), Long.valueOf(value[1]), Long.valueOf(value[2]))); } } private static PropertyStore tripletListToStore(List> list) { PropertyStore innerStore = new PropertyStore(); int index = 0; for (Triplet 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> list) { PropertyStore innerStore = new PropertyStore(); int index = 0; for (Triplet 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 map, PropertyStore store, Enum key) { storeToLongArrayMap(map, store.getPropertyStore(key.name())); } public static void putLongArrayMap(PropertyStore store, Enum key, Map map) { store.put(key.name(), longArrayMapToStore(map)); } public static String createKey(Enum prefix, int index) { return prefix.name() + "_" + index; } }