- Timestamp:
- 02/27/15 13:45:57 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs
r12091 r12096 151 151 case "todouble": Apply(stack, x => Convert.ToDouble(x)); break; 152 152 153 case "[]": Apply(stack, (a, i) => GetArrayValueAtIndex(a, Convert.ToInt32(i))); break; 154 153 155 case "==": Apply(stack, (x, y) => Equal(x, y)); break; 154 156 case "not": Apply(stack, x => !Convert.ToBoolean(x)); break; … … 181 183 var v = value as BoolValue; 182 184 if (v != null) return v.Value; 185 return null; 186 } 187 188 private static object GetArrayValue(IItem value) { 189 if (value is IntArray || value is DoubleArray || value is BoolArray || value is StringArray) 190 return value; 183 191 return null; 184 192 } … … 191 199 GetDoubleValue(item) ?? 192 200 GetBoolValue(item) ?? 201 GetArrayValue(item) ?? 193 202 item.ToString(); 194 203 } 195 204 return null; 196 205 } 206 207 private static object GetArrayValueAtIndex(object array, int index) { 208 if (array is IntArray) 209 return ((IntArray)array)[index]; 210 if (array is DoubleArray) 211 return ((DoubleArray)array)[index]; 212 if (array is BoolArray) 213 return ((BoolArray)array)[index]; 214 if (array is StringArray) 215 return ((StringArray)array)[index]; 216 throw new NotSupportedException(string.Format("Type {0} is not a supported array type", array.GetType().Name)); 217 } 197 218 #endregion 198 219 199 220 #region variadic equality 200 private static bool Equal(object a, object b) { return EqualNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; } 201 private static bool EqualNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; } 221 private static bool Equal(object a, object b) { return EqualIntegerNumber(a, b) || EqualFloatingNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; } 222 private static bool EqualIntegerNumber(object a, object b) { return a is int && b is int && (int)a == (int)b; } 223 private static bool EqualFloatingNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; } 202 224 private static bool EqualBool(object a, object b) { return a is bool && b is bool && (bool)a == (bool)b; } 203 225 private static bool EqualString(object a, object b) { return a is string && b is string && ((string)a).Equals((string)b); }
Note: See TracChangeset
for help on using the changeset viewer.