public string toCode() { int size = (int)this.size(); StringBuilder s = new StringBuilder(32 + size * 32); s.Append(@typeof().signature()); s.Append('['); if (size == 0) { s.Append(':'); } bool first = true; IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (first) { first = false; } else { s.Append(',').Append(' '); } s.Append(FanObj.trap(key, "toCode", null)) .Append(':') .Append(FanObj.trap(val, "toCode", null)); } s.Append(']'); return(s.ToString()); }
public override long hash() { long hash = 33; for (int i = 0; i < m_size; i++) { object obj = m_values[i]; hash = (31 * hash) + (obj == null ? 0 : FanObj.hash(obj)); } return(hash); }
public static string plus(string self, object obj) { if (obj == null) { return(String.Concat(self, "null")); } string x = FanObj.toStr(obj); if (x == "") { return(self); } return(String.Concat(self, x)); }
/** * Make a thread-safe copy of the specified object. * If it is immutable, then just return it; otherwise * we make a serialized copy. */ public static object safe(object obj) { if (obj == null) { return(null); } if (FanObj.isImmutable(obj)) { return(obj); } Buf buf = new MemBuf(512); buf.writeObj(obj); buf.flip(); return(buf.readObj()); }
////////////////////////////////////////////////////////////////////////// // Lifecycle ////////////////////////////////////////////////////////////////////////// public static Service install(Service self) { try { List types = FanObj.@typeof(self).inheritance(); lock (m_lock) { // if already installed, short circuit if (self.isInstalled()) { return(self); } // add to byService map byService[self] = new State(self); // add to map for each type service implements for (int i = 0; i < types.sz(); ++i) { Type t = (Type)types.get(i); if (!isServiceType(t)) { continue; } Node node = new Node(self); Node x = (Node)byType[t.qname()]; if (x == null) { byType[t.qname()] = node; } else { while (x.next != null) { x = x.next; } x.next = node; } } } } catch (System.Exception e) { Err.dumpStack(e); } return(self); }
public string toCode() { StringBuilder s = new StringBuilder(32 + m_size * 32); s.Append(m_of.signature()); s.Append('['); if (m_size == 0) { s.Append(','); } for (int i = 0; i < m_size; ++i) { if (i > 0) { s.Append(',').Append(' '); } s.Append(FanObj.trap(m_values[i], "toCode", null)); } s.Append(']'); return(s.ToString()); }
public static Service uninstall(Service self) { try { List types = FanObj.@typeof(self).inheritance(); lock (m_lock) { // ensure service is stopped stop(self); // remove from byService map, it not installed short circuit if (byService[self] == null) { return(self); } byService.Remove(self); // remove from map for each type implemented by service for (int i = 0; i < types.sz(); ++i) { // get next type in inheritance and check if service type Type t = (Type)types.get(i); if (!isServiceType(t)) { continue; } // lookup linked list for that type Node node = (Node)byType[t.qname()]; if (node == null) { continue; } // find this thread in the linked list Node last = null; bool cont = false; while (node.service != self) { last = node; node = node.next; if (node == null) { cont = true; break; } } if (cont) { continue; } // update the map or linked list if (last == null) { byType[t.qname()] = node.next; } else { last.next = node.next; } } } } catch (System.Exception e) { Err.dumpStack(e); } return(self); }
public override sealed long hash() { return(FanObj.hash(toStr())); }