private static void addProps(Hashtable index, Map props) { IDictionaryEnumerator en = props.pairsIterator(); while (en.MoveNext()) { string key = (string)en.Key; List val = (List)en.Value; List master = (List)index[key]; if (master == null) index[key] = val; else master.addAll(val); } }
// This is mostly for testing right. // java.util.TimeZone java() // { // return java.util.TimeZone.getTimeZone(name.val); // } ////////////////////////////////////////////////////////////////////////// // Aliases ////////////////////////////////////////////////////////////////////////// private static void loadAliases() { Hashtable map = new Hashtable(); try { // read as props file //String sep = java.io.File.separator; //Map props = Env.cur().props(Sys.sysPod, Uri.fromStr("timezone-aliases.props"), Duration.Zero); Map props = Sys.m_sysPod.props(Uri.fromStr("timezone-aliases.props"), Duration.Zero); System.Diagnostics.Debug.WriteLine(props.size()); System.Console.WriteLine(props.size()); // map both simple name and full names to aliases map IDictionaryEnumerator it = props.pairsIterator(); while (it.MoveNext()) { string key = (string)it.Key; string val = (string)it.Value; // map by fullName map[key] = val; // map by simple name int slash = key.LastIndexOf('/'); if (slash > 0) { map[key.Substring(slash + 1)] = val; } } } catch (Exception e) { Err.dumpStack(e); Console.WriteLine("ERROR: Cannot read timezone-aliases.props"); } // save to field and force memory barrier sync TimeZone.aliases = map; lock (TimeZone.aliases) {} //synchronized(TimeZone.aliases) {} }
////////////////////////////////////////////////////////////////////////// // Complex ////////////////////////////////////////////////////////////////////////// /// <summary> /// complex := type [fields] /// fields := "{" field (eos field)* "}" /// field := name "=" obj /// </summary> private object readComplex(int line, Type t, bool root) { Map toSet = new Map(Sys.FieldType, Sys.ObjType.toNullable()); List toAdd = new List(Sys.ObjType.toNullable()); // read fields/collection into toSet/toAdd readComplexFields(t, toSet, toAdd); // get the make constructor Method makeCtor = t.method("make", false); if (makeCtor == null || !makeCtor.isPublic()) throw err("Missing public constructor " + t.qname() + ".make", line); // get argument lists List args = null; if (root && options != null) args = (List)options.get("makeArgs"); // construct object object obj = null; bool setAfterCtor = true; try { // if first parameter is an function then pass toSet // as an it-block for setting the fields Param p = (Param)makeCtor.@params().first(); if (args == null && p != null && p.type().fits(Sys.FuncType)) { args = new List(Sys.ObjType).add(Field.makeSetFunc(toSet)); setAfterCtor = false; } // invoke make to construct object obj = makeCtor.callList(args); } catch (System.Exception e) { throw err("Cannot make " + t + ": " + e, line, e); } // set fields (if not passed to ctor as it-block) if (setAfterCtor && toSet.size() > 0) { IDictionaryEnumerator en = toSet.pairsIterator(); while (en.MoveNext()) { complexSet(obj, (Field)en.Key, en.Value, line); } } // add if (toAdd.size() > 0) { Method addMethod = t.method("add", false); if (addMethod == null) throw err("Method not found: " + t.qname() + ".add", line); for (int i=0; i<toAdd.sz(); ++i) complexAdd(t, obj, addMethod, toAdd.get(i), line); } return obj; }
////////////////////////////////////////////////////////////////////////// // Map ////////////////////////////////////////////////////////////////////////// public void writeMap(Map map) { // get k,v type MapType t = (MapType)map.@typeof(); // decide if we're going output as single or multi-line format bool nl = isMultiLine(t.m_k) || isMultiLine(t.m_v); // figure out if we can use an inferred type bool inferred = false; if (curFieldType != null && curFieldType.fits(Sys.MapType)) { inferred = true; } // clear field type, so it doesn't get used for inference again curFieldType = null; // if we don't have an inferred type, then prefix of type if (!inferred) wType(t); // handle empty map if (map.isEmpty()) { w("[:]"); return; } // items level++; w('['); bool first = true; IDictionaryEnumerator en = map.pairsIterator(); while (en.MoveNext()) { if (first) first = false; else w(','); if (nl) w('\n').wIndent(); object key = en.Key; object val = en.Value; writeObj(key); w(':'); writeObj(val); } w(']'); level--; }