public bool TryGetRegisterName(Type type, out string name) { if (!_biMap.ContainsValue(type)) { name = null; return(false); } name = GetRegisterName(type); return(true); }
public static bool UpdateMapInternal(BiMap <int, string> map, string mapName, string command, string regex, IDictionary <int, int> staticMapping) { bool updated = false; BufferedReader br = null; try { SystemProcess process = Runtime.GetRuntime().Exec(new string[] { "bash", "-c", command }); br = new BufferedReader(new InputStreamReader(process.GetInputStream(), Encoding. Default)); string line = null; while ((line = br.ReadLine()) != null) { string[] nameId = line.Split(regex); if ((nameId == null) || (nameId.Length != 2)) { throw new IOException("Can't parse " + mapName + " list entry:" + line); } Log.Debug("add to " + mapName + "map:" + nameId[0] + " id:" + nameId[1]); // HDFS can't differentiate duplicate names with simple authentication int key = staticMapping[ParseId(nameId[1])]; string value = nameId[0]; if (map.Contains(key)) { string prevValue = map[key]; if (value.Equals(prevValue)) { // silently ignore equivalent entries continue; } ReportDuplicateEntry("Got multiple names associated with the same id: ", key, value , key, prevValue); continue; } if (map.ContainsValue(value)) { int prevKey = map.Inverse()[value]; ReportDuplicateEntry("Got multiple ids associated with the same name: ", key, value , prevKey, value); continue; } map[key] = value; updated = true; } Log.Debug("Updated " + mapName + " map size: " + map.Count); } catch (IOException e) { Log.Error("Can't update " + mapName + " map"); throw; } finally { if (br != null) { try { br.Close(); } catch (IOException e1) { Log.Error("Can't close BufferedReader of command result", e1); } } } return(updated); }