/** * Private constructor. */ private Unit(List ids, Dimension dim, double scale, double offset) { this.m_ids = checkIds(ids); this.m_dim = dim; this.m_scale = scale; this.m_offset = offset; }
public static void addHandler(Func func) { if (!func.isImmutable()) throw NotImmutableErr.make("handler must be immutable").val; lock (lockObj) { List temp = new List(Sys.FuncType, m_handlers).add(func); m_handlers = (Func[])temp.toArray(new Func[temp.sz()]); } }
////////////////////////////////////////////////////////////////////////// // Construction ////////////////////////////////////////////////////////////////////////// public BootEnv() { this.m_args = initArgs(); this.m_vars = initVars(); this.m_host = initHost(); this.m_user = initUser(); this.m_in = new SysInStream(Console.OpenStandardInput()); this.m_out = new SysOutStream(Console.OpenStandardOutput()); this.m_err = new SysOutStream(Console.OpenStandardError()); this.m_homeDir = new LocalFile(new DirectoryInfo(Sys.m_homeDir), true).normalize(); this.m_tempDir = m_homeDir.plus(Uri.fromStr("temp/"), false); }
static Map read(Map defProps, Key key, List files) { if (files.isEmpty()) return defProps; Map acc = defProps.dup(); for (int i=files.sz()-1; i>=0; --i) { InStream input = ((File)files.get(i)).@in(); try { acc.setAll(input.readProps()); } finally { input.close(); } } return (Map)acc.toImmutable(); }
public static List findAll(Type t) { string qname = t.qname(); List list = new List(Sys.ServiceType); lock (m_lock) { Node node = (Node)byType[qname]; while (node != null) { list.add(node.service); node = node.next; } } return list.ro(); }
/// <summary> /// Constructor used by GenericType and we are given the generic /// method that is being parameterized. /// </summary> public Method(Type parent, string name, int flags, Facets facets, int lineNum, Type returns, Type inheritedReturns, List pars, Method generic) : base(parent, name, flags, facets, lineNum) { List fparams = pars.ro(); if ((flags & (FConst.Static|FConst.Ctor)) == 0) { object[] temp = new object[pars.sz()+1]; temp[0] = new Param("this", parent, 0); pars.copyInto(temp, 1, pars.sz()); fparams = new List(Sys.ParamType, temp); } this.m_func = new MethodFunc(this, returns, fparams); this.m_params = pars; this.m_inheritedReturns = inheritedReturns; this.m_mask = (generic != null) ? 0 : toMask(parent, returns, pars); this.m_generic = generic; }
public static Version fromStr(string s, bool check) { List segments = new List(Sys.IntType, 4); int seg = -1; bool valid = true; int len = s.Length; for (int i=0; i<len; ++i) { int c = s[i]; if (c == '.') { if (seg < 0 || i+1>=len) { valid = false; break; } segments.add(Long.valueOf(seg)); seg = -1; } else { if ('0' <= c && c <= '9') { if (seg < 0) seg = c-'0'; else seg = seg*10 + (c-'0'); } else { valid = false; break; } } } if (seg >= 0) segments.add(Long.valueOf(seg)); if (!valid || segments.sz() == 0) { if (check) throw ParseErr.make("Version", s).val; else return null; } return new Version(segments); }
public Map setList(List list, Func f) { modify(); if (f == null) { for (int i=0; i<list.sz(); ++i) set(list.get(i), list.get(i)); } else if (f.@params().sz() == 1) { for (int i=0; i<list.sz(); ++i) set(f.call(list.get(i)), list.get(i)); } else { for (int i=0; i<list.sz(); ++i) set(f.call(list.get(i), i), list.get(i)); } return this; }
public Map addList(List list) { return addList(list, null); }
public override object trap(string name, List args) { if (name == "dump") { m_threadPool.dump(args); return null; } return base.trap(name, args); }
public List rw() { if (!m_isReadonly) return this; object[] temp = new object[m_size]; Array.Copy(m_values, temp, m_size); List rw = new List(m_of); rw.m_values = temp; rw.m_size = m_size; rw.m_isReadonly = false; rw.m_readonlyList = this; return rw; }
public List removeAll(List toRemove) { // optimize special cases modify(); if (toRemove.sz() == 0) { return this; } if (toRemove.sz() == 1) { remove(toRemove.get(0)); return this; } // rebuild the backing store array, implementation // assumes that this list is bigger than toRemove list object[] newValues = new object[m_values.Length]; int newSize = 0; for (int i=0; i<m_size; ++i) { object val = m_values[i]; if (!toRemove.contains(val)) newValues[newSize++] = val; } this.m_values = newValues; this.m_size = newSize; return this; }
private List insertAll(int i, List list) { modify(); if (list.m_size == 0) return this; if (m_values.Length < m_size+list.m_size) grow(m_size+list.m_size); if (i < m_size) Array.Copy(m_values, i, m_values, i+list.m_size, m_size-i); Array.Copy(list.m_values, 0, m_values, i, list.m_size); m_size += list.m_size; return this; }
public List addAll(List list) { // modify in insertAll(int, List) return insertAll(m_size, list); }
private void doFlatten(List acc) { for (int i=0; i<m_size; ++i) { object item = m_values[i]; if (item is List) ((List)item).doFlatten(acc); else acc.add(item); } }
public List intersection(List that) { // put other list into map Hashtable dups = new Hashtable(that.m_size*3); bool hasNull = false; for (int i=0; i<that.m_size; ++i) { object v = that.m_values[i]; if (v == null) hasNull = true; else dups[v] = this; } // now walk this list and accumulate // everything found in the dups map List acc = new List(m_of, m_size); for (int i=0; i<m_size; i++) { object v = m_values[i]; if (v == null && hasNull) { acc.add(v); hasNull = false; } else if (v != null && dups[v] != null) { acc.add(v); dups.Remove(v); } } return acc; }
public List map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) r = Sys.ObjType.toNullable(); List acc = new List(r, (int)size()); for (int i=0; i<m_size; i++) acc.add(f.call(m_values[i], i)); return acc; }
private void modify() { // if readonly then throw readonly exception if (m_isReadonly) throw ReadonlyErr.make("List is readonly").val; // if we have a cached readonlyList, then detach // it so it remains immutable if (m_readonlyList != null) { object[] temp = new object[m_size]; Array.Copy(m_values, temp, m_size); m_readonlyList.m_values = temp; m_readonlyList = null; } }
public List ro() { if (m_isReadonly) return this; if (m_readonlyList == null) { List ro = new List(m_of); ro.m_values = m_values; ro.m_size = m_size; ro.m_isReadonly = true; m_readonlyList = ro; } return m_readonlyList; }
public bool containsAny(List list) { for (int i=0; i<list.sz(); i++) if (index(list.get(i)) != null) return true; return false; }
public override List list() { int len = 0; FileSystemInfo[] list = null; if (m_file is DirectoryInfo) { list = (m_file as DirectoryInfo).GetFileSystemInfos(); len = list.Length; } List acc = new List(Sys.FileType, len); for (int i=0; i<len; i++) { FileSystemInfo f = list[i]; string name = fileNameToUriName(f.Name); acc.add(new LocalFile(m_uri.plusName(name, f is DirectoryInfo), f)); } return acc; }
public List findAll(Func f) { List acc = new List(m_of, m_size); for (int i=0; i<m_size; i++) if (f.call(m_values[i], i) == Boolean.True) acc.add(m_values[i]); return acc; }
////////////////////////////////////////////////////////////////////////// // BootEnv ////////////////////////////////////////////////////////////////////////// public void setArgs(string[] args) { this.m_args = (List)new List(Sys.StrType, args).toImmutable(); }
public List findType(Type t) { List acc = new List(t, m_size); for (int i=0; i<m_size; i++) { object item = m_values[i]; if (item != null && @typeof(item).@is(t)) acc.add(item); } return acc; }
public static List listFullNames() { List list = new List(Sys.StrType); for (int i=0; i<indexNames.Length; ++i) { string prefix = prefixes[indexPrefixes[i] & 0xff]; string name = indexNames[i]; if (prefix.Length != 0) name = prefix + "/" + name; list.add(name); } return list.ro(); }
public List flatten() { List acc = new List(Sys.ObjType.toNullable(), m_size*2); doFlatten(acc); return acc; }
public Map setList(List list) { return setList(list, null); }
public List getRange(Range r) { try { int s = r.start(m_size); int e = r.end(m_size); int n = e - s + 1; if (n < 0) throw IndexErr.make(r).val; List acc = new List(m_of, n); acc.m_size = n; Array.Copy(m_values, s, acc.m_values, 0, n); return acc; } catch (ArgumentOutOfRangeException) { throw IndexErr.make(r).val; } }
public List split(string s, long limit) { int l = (limit < 0) ? 0 : (int)limit; List result = new List(m_pattern.Split(s, l)); // to match java we need to discard any trailing // emptys strings (use limit, not l) if (limit == 0) while (result.sz() > 0 && (result.last() as string).Length == 0) result.pop(); return result; }
public List insertAll(long index, List list) { // modify in insertAll(int, List) int i = (int)index; if (i < 0) i = m_size + i; if (i > m_size || i < 0) throw IndexErr.make(index).val; return insertAll(i, list); }