public override IBELObject Expose(ExecutionContext ctx) { BELArray a = new BELArray(); foreach (ExposableParseTreeNode each in _Array) a.Add(each.Expose(ctx)); return a; }
public BELArray Snip(int maxCount) { BELArray answer = new BELArray(); foreach (IBELObject each in Array) { answer.Add(each); if (answer.Count >= maxCount) return answer; } return answer; }
public BELArray Select(ExecutionContext ctx, Block block) { BELArray answer = new BELArray(); foreach (IBELObject each in Array) { ArrayList parms = new ArrayList(); parms.Add(each); IBELObject objValue = block.Value(ctx, parms); BELBoolean test = objValue as BELBoolean; if (test == null) throw new ExecutionException("Select block must evaluate to a boolean. Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead."); if (test.Value) answer.Add(each); } return answer; }
public BELArray Collect(ExecutionContext ctx, Block block) { BELArray answer = new BELArray(); foreach (IBELObject each in Array) { ArrayList parms = new ArrayList(); parms.Add(each); answer.Add(block.Value(ctx, parms)); } return answer; }
public BELArray SortBy(ExecutionContext ctx, Block block) { // This code formerly sorted the list by having the IComparer do the comparison. // This was resulting in lots of superficial comparisons, as the block was being // evaluated lots of extra times - for the left and the right item on every comparison. // Instead, I changed it to rip through the array, evaluate the block exaclty once // for each item, and then do the sort on just the values. List<BelArrayEntry> entries = new List<BelArrayEntry>(); try { foreach (IBELObject entry in Array) { ArrayList a1 = new ArrayList(); a1.Add(entry); IBELObject value = block.Value(ctx, a1); IComparable comparable = value as IComparable; if (comparable == null) { throw new ExecutionException(null, "Can not compare objects of type " + BELType.ExternalTypeNameForType(value.GetType())); } entries.Add(new BelArrayEntry(entry, comparable)); } entries.Sort(new BelArrayEntry.Comparer()); } catch (InvalidOperationException e) { throw e.InnerException; } BELArray results = new BELArray(); foreach (BelArrayEntry entry in entries) { results.Add(entry.Entry); } return results; }