/// <summary> /// Writes the specified value string into a ConfigNode as a value named valueName. If any of /// the attributes are of Subsection, that value will be written into a subsection of the /// ConfigNode with name provided (will be created if necessary) /// </summary> /// <param name="node"></param> /// <param name="valueName"></param> /// <param name="value"></param> /// <param name="attrs"></param> private static void WriteValue(ConfigNode node, string valueName, string value, System.Object[] attrs) { if (attrs == null) { attrs = new System.Object[] { } } ; Subsection subsection = attrs.SingleOrDefault(attr => attr is Subsection) as Subsection; if (subsection != null) { //Log.Debug("valueName {0} with value '{1}' should be in a subsection called '{2}'", valueName, value, subsection.Section); if (node.HasNode(subsection.Section)) { //Log.Debug("Already has a section of that name"); node = node.GetNode(subsection.Section); } else { Log.Debug("Created a new section for " + subsection.Section); node = node.AddNode(subsection.Section); } } attrs.ToList().ForEach(attr => { if (attr is HelpDoc) { node.AddValue(string.Format("// {0}", valueName), ((HelpDoc)attr).Documentation); } }); node.AddValue(valueName, value); }
public object ParseDefaultValue(INamedParameterNode name) { string[] vals = name.GetDefaultInstanceAsStrings(); object[] ret = new Object[vals.Length]; for (int i = 0; i < vals.Length; i++) { string val = vals[i]; try { ret[i] = Parse(name, val); } catch (ParseException e) { throw new ClassHierarchyException("Could not parse default value", e); } } if (name.IsSet()) { return new HashSet<object>(ret.ToList<object>()); } else { if (ret.Length == 0) { return null; } else if (ret.Length == 1) { return ret[0]; } else { throw new IllegalStateException("Multiple defaults for non-set named parameter! " + name.GetFullName()); } } }
public object ParseDefaultValue(INamedParameterNode name) { string[] vals = name.GetDefaultInstanceAsStrings(); object[] ret = new Object[vals.Length]; for (int i = 0; i < vals.Length; i++) { string val = vals[i]; try { ret[i] = Parse(name, val); } catch (ParseException e) { Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER); var ex = new ClassHierarchyException("Could not parse default value " + val, e); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); } } if (name.IsSet()) { return new HashSet<object>(ret.ToList<object>()); } if (name.IsList()) { return new List<object>(ret.ToList<object>()); } if (ret.Length == 0) { return null; } if (ret.Length == 1) { return ret[0]; } var ec = new IllegalStateException("Multiple defaults for non-set named parameter! " + name.GetFullName()); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ec, LOGGER); return null; //this line would be never reached as Throw will throw an exception }
/// <summary> /// Splite and prepare data source for thread-workers /// </summary> protected void splitData() { //counters int toUse = 0, alreadyUsed = 0; int dataCount = m_data.Count; //split data for (int i = 0; i < m_workCounts; i++) { toUse = ((i + 1) * dataCount) / m_workCounts - alreadyUsed; Object[] workArr = new Object[toUse]; m_data.CopyTo(alreadyUsed, workArr, 0, toUse); m_workers[i].setImput(workArr.ToList<Object>()); alreadyUsed += toUse; } }