public override void FinalizeEntry(IValuable <G> key, EntryValuePointer <G> entryValuePointer) { lock (this) { _valuesDictionary[key] = entryValuePointer; } }
public IValuable GetValuable(string id) { IValuable foundValuable = null; foreach (IValuable valuable in valuables) { if (valuable is Merchandise) { Merchandise merchandise = valuable as Merchandise; if (merchandise.ItemId == id) { foundValuable = merchandise; } } if (valuable is Course) { Course course = valuable as Course; if (course.Name == id) { foundValuable = course; } } } return(foundValuable); }
public IValuable GetValuable(string id) { IValuable obj = valuables[0]; valuables.ForEach(x => { if (x is Book book) { if (book.ItemId == id) { obj = book; } } else if (x is Amulet amulet) { if (amulet.ItemId == id) { obj = amulet; } } else if (x is Course course) { if (course.Name == id) { obj = course; } } }); return(obj); }
public void DefaultActionValue_Add(object otherVal, bool throwsException) { G groupState = Mock.Of <G>(); DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); DefaultActionValue <G> sut = new DefaultActionValue <G>(groupState, 10); IValuable <G> newValue = null; Action action = () => { newValue = sut.Add(valueProvider.GetAsValue(otherVal), valueProvider); }; if (throwsException) { Assert.Throws <EngineRuntimeException>(action); } else { action(); } if (!throwsException) { switch (otherVal) { case null: Assert.Equal(sut, newValue); break; } } }
public void DefaultCollectionValue_GetAt() { DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); IValuable <G> value = Mock.Of <IValuable <G> >(); Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >() { { new DefaultDoubleValue <G>(0), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(1), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultDoubleValue <G>(2), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(4), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(5), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(3), new ValuePointer <G> { Value = value } } }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); ValuePointer <G> result = sut.GetAt(new DefaultIntValue <G>(5), valueProvider); Assert.Equal(value, result.Value); }
public void DefaultCollectionValue_ContainsValue_Present() { DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); IValuable <G> value = Mock.Of <IValuable <G> >(); Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >() { { new DefaultDoubleValue <G>(0), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(1), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultDoubleValue <G>(2), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(4), new ValuePointer <G> { Value = value } }, { new DefaultIntValue <G>(5), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(3), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } } }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); bool result = sut.ContainsValue(value, valueProvider); Assert.True(result); }
public IValuable <G> Minus(IValuable <G> value, IValueProvider <G> valueProvider) { switch (value) { case IValue <G, string> stringValue: return(Minus(stringValue.Data, valueProvider)); case IValue <G, int> intValue: return(Minus(intValue.Data.ToString(), valueProvider)); case IValue <G, double> doubleValue: return(Minus(doubleValue.Data.ToString(), valueProvider)); case IValue <G, long> longValue: return(Minus(longValue.Data.ToString(), valueProvider)); case IValue <G, bool> booleanValue: return(Minus(booleanValue.Data.ToString(), valueProvider)); case INullValue <G> _: return(this); default: throw new EngineRuntimeException("Invalid values for subtraction"); } }
public IValuable <G> Add(IValuable <G> value, IValueProvider <G> valueProvider) { switch (value) { case IValue <G, string> stringValue: return(Add(stringValue.Data, valueProvider)); case IValue <G, int> intValue: return(Add(intValue.Data.ToString(), valueProvider)); case IValue <G, double> doubleValue: return(Add(doubleValue.Data.ToString(), valueProvider)); case IValue <G, long> longValue: return(Add(longValue.Data.ToString(), valueProvider)); case IValue <G, bool> booleanValue: return(Add(booleanValue.Data.ToString().ToLower(), valueProvider)); case ICollectionValue <G> collectionValue: return(Add(collectionValue, valueProvider)); case INullValue <G> _: return(this); default: throw new EngineRuntimeException("Invalid values for addition"); } }
private static string ToJsonString <G>(IValuable <G> input, int maxDepth = 30) where G : IGroupState <G>, new() { string jsonValue = null; if (input == null) { jsonValue = "null"; } else if (input is ICollectionValue <G> collectionValue) { jsonValue = maxDepth <= 0 ? "overflow" : collectionValue is DefaultCollectionValue <G> defaultCollectionValue && (defaultCollectionValue.IsMap || defaultCollectionValue == null) ? $"{{{string.Join(", ", collectionValue.GetEntries().Select(entry => $"{ToJsonString(entry.Key, 2)}: {ToJsonString(entry.Value.Value, maxDepth - 1)}"))}}}" : $"[{string.Join(", ", collectionValue.GetValues().Select(item => ToJsonString(item.Value, maxDepth - 1)))}]"; } else if (input is IActionValue <G> ) { jsonValue = "action pointer"; } else if (input is IGroupValue <G> groupValue) { jsonValue = $"{groupValue.State.Group.GroupName} pointer"; } else { IValue value = input as IValue; jsonValue = ToValueString(value?.GetData() ?? input?.ToString() ?? "undefined"); } return(jsonValue); }
public override void Remove(IValuable <G> key, IValueProvider <G> valueProvider) { lock (this) { if (IsMap) { if (_valuesDictionary.TryGetValue(key, out EntryValuePointer <G> pointer)) { int index = pointer.Index; _valuesDictionary.Remove(key); _valuesList.RemoveAt(index); for (int i = index; i < _valuesList.Count; i++) { _valuesList[i].Index = i; } } } else { int index = AsArrayIndex(key).Value; if (index >= 0 && index < _valuesList.Count) { _valuesList.RemoveAt(index); for (int i = index; i < _valuesList.Count; i++) { _valuesList[i].Index = i; _valuesList[i].Key = valueProvider.GetInt(i); } } } } }
public void DefaultCollectionValue_KeyOf_NotPresent() { DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); IValuable <G> value = Mock.Of <IValuable <G> >(); Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >() { { new DefaultDoubleValue <G>(0), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(1), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultDoubleValue <G>(2), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(4), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(5), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(3), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } } }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); IValuable <G> result = sut.KeyOf(value, valueProvider); Assert.Null(result); }
public void DefaultCollectionValue_Get_OnNonMapItemExists(bool create) { DefaultIntValue <G> key = new DefaultIntValue <G>(3); IValuable <G> value = Mock.Of <IValuable <G> >(); DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >() { { new DefaultIntValue <G>(0), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(1), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(2), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { key, new ValuePointer <G> { Value = value } }, { new DefaultIntValue <G>(4), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(5), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } } }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); EntryValuePointer <G> result = sut.Get(key, create, valueProvider) as EntryValuePointer <G>; Assert.False(sut.IsMap); Assert.Equal(key, result.Key); Assert.Equal(value, result.Value); Assert.Equal(3, result.Index); Assert.True(result.IsSet); }
public IValuable GetValuable(string id) { IValuable result = null; foreach (IValuable valueable in valueables) { if (valueable is Merchandise merchandise) { if (merchandise.ItemId.Equals(id)) { result = merchandise; } return(result); } else if (valueable is Course course) { if (course.Name.Equals(id)) { result = course; } return(result); } } return(result); }
public LSystemData(string axiom, IValuable angle, float depthFactor) { Rules = new List <ARule>(); Axiom = axiom; Angle = angle; DepthFactor = depthFactor; }
public EntryValuePointer(ICollectionValue <G> collection, IValuable <G> key, int index, IValueProvider <G> valueProvider, bool isSet = false) { Collection = collection; Key = key; IsSet = isSet; Index = index; ValueProvider = valueProvider; }
public ValuePointer <G> Get(IValuable <G> value, bool createNonExistent, IValueProvider <G> valueProvider) { IValue <G, int> index = (IValue <G, int>)value; return(new ValuePointer <G> { Value = valueProvider.GetString(Data[index.Data].ToString()) }); }
private Type GetOperandDeclareType(IValuable operand) { if (operand is LocalOperand) return ((LocalOperand)operand).Value.LocalType; if (operand is FieldOperand) return ((FieldOperand)operand).Value.FieldType; // TODO PropertyOperand 추가 해야함 throw new NotSupportedException(operand.ToString()); }
private static void ExecuteInstructionRPower(IInstructionExecutor <GroupState> executor, ExecutionState <GroupState> executionState, object[] payload, StackList <ValuePointer <GroupState> > stackRegister, StackList <StackValuePointer <GroupState> > stackPointers) { IValue <GroupState> secondValue = (IValue <GroupState>)stackRegister.TakeLast().Value; IValue <GroupState> firstValue = (IValue <GroupState>)stackRegister.Last().Value; IValuable <GroupState> result = executor.ValueProvider.GetReducedValue(Math.Pow(Convert.ToDouble(firstValue.GetData()), Convert.ToDouble(secondValue.GetData()))); stackRegister.SetLast(new ValuePointer <GroupState> { Value = result }); }
public override void Remove(IValuable <G> key, IValueProvider <G> valueProvider) { lock (this) { if (_valuesDictionary.TryGetValue(key, out EntryValuePointer <G> pointer)) { _valuesDictionary.Remove(key); } } }
public void Remove(IValuable valuable) { if (valuable is FacilityObject) { Remove((FacilityObject)valuable); } else { GetAll().OfType <ValuablesContainer>().ForEach(y => y.Remove(valuable)); } }
public IValuable <G> RightShift(IValuable <G> value, IValueProvider <G> valueProvider) { switch (value) { case IValue <G, int> intValue: return(RightShift(intValue.Data, valueProvider)); default: throw new EngineRuntimeException("Invalid values for right shift"); } }
public IValuable <G> IsNotEqualTo(IValuable <G> valuable, IValueProvider <G> valueProvider) { switch (valuable) { case IValue <G, bool> booleanValue: return(IsNotEqualTo(booleanValue, valueProvider)); default: return(valueProvider.True); } }
public IValuable <G> Or(IValuable <G> value, IValueProvider <G> valueProvider) { switch (value) { case IValue <G, bool> booleanValue: return(Or(booleanValue, valueProvider)); default: throw new EngineRuntimeException("Invalid values for or"); } }
public IValuable <G> IsNotEqualTo(IValuable <G> valuable, IValueProvider <G> valueProvider) { switch (valuable) { case IValue <G, string> stringValue: return(IsNotEqualTo(stringValue, valueProvider)); default: return(valueProvider.True); } }
public override int CompareTo(IValuable other) { var asQuadruple = other as Quadruple; if (asQuadruple != null) { return(CompareTo(asQuadruple)); } return(GlobVars.TypeToValue[this.GetType()] - GlobVars.TypeToValue[other.GetType()]); }
public void DefaultCollectionValue_GetValues() { DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); IValuable <G>[] values = new IValuable <G>[] { Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >() }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); List <ValuePointer <G> > result = sut.GetValues(); Assert.Equal(values, result.Select(p => p.Value)); }
public IValuable <G> Add(IValuable <G> value, IValueProvider <G> valueProvider) { switch (value) { case ICollectionValue <G> collectionValue: return(Add(collectionValue, valueProvider)); default: throw new EngineRuntimeException("Invalid values for addition"); } }
public IValuable <G> IsEqualTo(IValuable <G> value, IValueProvider <G> valueProvider) { switch (value) { case INullValue <G> _: return(valueProvider.True); default: return(valueProvider.False); } }
public override int CompareTo(IValuable other) { var asRoyalFlush = other as RoyalFlush; if (asRoyalFlush != null) { return(CompareTo(asRoyalFlush)); } return(GlobVars.TypeToValue[this.GetType()] - GlobVars.TypeToValue[other.GetType()]); }
public override int CompareTo(IValuable other) { var asPair = other as Pair; if (asPair != null) { return(CompareTo(asPair)); } return(GlobVars.TypeToValue[this.GetType()] - GlobVars.TypeToValue[other.GetType()]); }
public void DefaultCollectionValue_GetEntries_FromIValuablesListConstructor() { DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); IValuable <G>[] values = new IValuable <G>[] { Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >() }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); List <KeyValuePair <IValuable <G>, ValuePointer <G> > > result = sut.GetEntries(); Assert.Equal(Enumerable.Range(0, values.Length), result.Select(kv => kv.Key).Cast <IValue>().Select(v => Convert.ToInt32(v.GetData()))); Assert.Equal(values, result.Select(kv => kv.Value).Select(vp => vp.Value)); Assert.Equal(Enumerable.Range(0, 6), result.Select(e => e.Value).Cast <EntryValuePointer <G> >().Select(v => v.Index)); }
public SubstituteCaseAction(string columnName, IValuable oldText, IValuable newText) { ColumnName = columnName; OldText = oldText; NewText = newText; }