Difference between revisions of "CompatibilityArray class"
Nguyenduyan (talk | contribs) |
|||
Line 91: | Line 91: | ||
DCS_use(15636575); | DCS_use(15636575); | ||
array axis = AxisSet_getAxis("Gender"); | array axis = AxisSet_getAxis("Gender"); | ||
+ | |||
print( axis[AXIS_OPTIONS]);//CompatibilityArray | print( axis[AXIS_OPTIONS]);//CompatibilityArray | ||
+ | //Skip | ||
x = axis[AXIS_OPTIONS].Skip(1); | x = axis[AXIS_OPTIONS].Skip(1); | ||
print(x);//{AxisOption} | print(x);//{AxisOption} | ||
+ | //Contains | ||
print(axis[AXIS_OPTIONS].Contains(axis[AXIS_OPTIONS][0]));// True | print(axis[AXIS_OPTIONS].Contains(axis[AXIS_OPTIONS][0]));// True | ||
+ | //First | ||
x = axis[AXIS_OPTIONS].First(function(AxisOption a){ | x = axis[AXIS_OPTIONS].First(function(AxisOption a){ | ||
a[AXIS_OPTION_NAME]== "Female"; | a[AXIS_OPTION_NAME]== "Female"; | ||
}); | }); | ||
print(x);//AxisOption | print(x);//AxisOption | ||
+ | //ToDictionary | ||
d = axis[AXIS_OPTIONS].ToDictionary(function(AxisOption a){ | d = axis[AXIS_OPTIONS].ToDictionary(function(AxisOption a){ | ||
a[AXIS_OPTION_NAME]; | a[AXIS_OPTION_NAME]; | ||
}); | }); | ||
print(d);//{"Female": AxisOption, "Male": AxisOption} | print(d);//{"Female": AxisOption, "Male": AxisOption} | ||
+ | //ToDictionary | ||
d = axis[AXIS_OPTIONS].ToDictionary(function(AxisOption a){a[AXIS_OPTION_NAME];}, function(AxisOption a){a[AXIS_OPTION_VALUE];}); | d = axis[AXIS_OPTIONS].ToDictionary(function(AxisOption a){a[AXIS_OPTION_NAME];}, function(AxisOption a){a[AXIS_OPTION_VALUE];}); | ||
print(d);//{"Female": Gender == [2], "Male": Gender == [1]} | print(d);//{"Female": Gender == [2], "Male": Gender == [1]} | ||
+ | //Select | ||
x = axis[AXIS_OPTIONS].Select(function (array a){a[AXIS_OPTION_VALUE];}); | x = axis[AXIS_OPTIONS].Select(function (array a){a[AXIS_OPTION_VALUE];}); | ||
print(x);//{Gender == [1],Gender == [2]} | print(x);//{Gender == [1],Gender == [2]} | ||
+ | //SelectMany | ||
+ | x = axis[AXIS_OPTIONS].SelectMany(function (AxisOption a){ | ||
+ | {a[AXIS_OPTION_NAME], a[AXIS_OPTION_VALUE] }; | ||
+ | }); | ||
+ | print(x);//{Male,Gender == [1],Female,Gender == [2]} | ||
+ | //Where | ||
x = axis[AXIS_OPTIONS].Where(function(AxisOption a){ | x = axis[AXIS_OPTIONS].Where(function(AxisOption a){ | ||
a[AXIS_OPTION_NAME]== "Female"; | a[AXIS_OPTION_NAME]== "Female"; | ||
}); | }); | ||
print(x);//{AxisOption} | print(x);//{AxisOption} | ||
+ | //Comnine Where and select | ||
x = axis[AXIS_OPTIONS].Where(function (array a){a[AXIS_OPTION_NAME]== "Female";}) | x = axis[AXIS_OPTIONS].Where(function (array a){a[AXIS_OPTION_NAME]== "Female";}) | ||
.Select(function (array a){a[AXIS_OPTION_VALUE];}); | .Select(function (array a){a[AXIS_OPTION_VALUE];}); | ||
print(x);//{Gender == [2]} | print(x);//{Gender == [2]} | ||
+ | //Except | ||
axis[AXIS_OPTIONS] = axis[AXIS_OPTIONS].Except({axis[AXIS_OPTIONS][0]}); | axis[AXIS_OPTIONS] = axis[AXIS_OPTIONS].Except({axis[AXIS_OPTIONS][0]}); | ||
AxisSet_save(); | AxisSet_save(); | ||
</source> | </source> |
Revision as of 06:05, 10 August 2018
CompatibilityArray
Maps cgs array to internal list for compatibility.
Methods
- Empty Add(object element "element to add") - Add a new element to the Array
- Empty AddRange(array source "Array to get elements from.") - Add all elements of another array to this array.
- bool Contains(object element "Element to check for") - Return true if the array contains the element using the normal equal operator.
- array Except(array elements "Elements to remove") - Return all elements that does not exist in the other collection.
- object First(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition.
- object FirstOrDefault(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition or empty if not found.
- int Frequency(number number "The number to search for") - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type Number
- object this[] { get; }(int index "Index") - Backward-compatible indexer
- bool IsCharacterArray() - check if array is an array of characters
- bool IsNumericArray() - check if array is an array of integer numbers
- bool IsStringArray() - check if array is an array of string
- array OrderBy(Function comparer "Function that compares two objects of the same type. Must return a signed integer that indicates the relative values of first param A and second param B. Value Less than 0 : A is less than B.Value 0 : A equals B.Value Greater than 0 : A is greater than B.It can also be a function that takes 1 parameter and returns a string or number.") - Sorts the elements of a sequence in ascending order by using a specified comparer.
- Empty Randomize() - Randomize the order of the elements in the current array.
- Empty RemoveItemAt(int index "The index to remove the object from") - Remove an element from the Array
- array Select(Function selector "A transform function to apply to each element.") - Projects each element of a sequence into a new form.
- array SelectMany(Function selector "A transform function to get each sub array.") - Projects each array element of a sequence into a new form.
- Empty this[] { set; }(int index "Index", object value "Value to set") - Backward-compatible indexer
- array Skip(int n "How many elements to skip") - Get all but the n first elements.
- array Take(int n "How many elements to take") - Get the n first elements.
- Dictionary ToDictionary(Function keySelector "A transform function to get the key of each element.") - Return a dictionary with the elements of the array.
- Dictionary ToDictionary(Function keySelector "A transform function to get the key of each element.", Function valueSelector "A transform function to get the value of each element.") - Return a dictionary with the elements of the array.
- string ToString() - The string representation of the object.
- array Where(Function predicate "A function that takes 1 parameter of the types in the array and return true/false") - Filters a sequence of values based on a predicate.
Properties
- number Average { get; } - Average of the objects in the Array object. Can only use if all the elements are of type Number
- int Count { get; } - Number of elements in Array
- number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number
- number Min { get; } - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number
- string ObjectTypeName { get; } - The name of the type of object.
- number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number
- TypeInformation TypeInformation { get; } - Get information about this class.
Examples
DataCacheSpecification dcs = new DataCacheSpecification (15636575);
Axis axis = new Axis (dcs, "Gender", "Gender");
axis.MathBase = "Gender";
axis.PctBase = "Gender != empty";
array options = axis.Options;
options.Add(new AxisOption(dcs,"Male","Gender == 1"));
options.AddRange({new AxisOption(dcs,"Male","Gender == 1"), new AxisOption(dcs,"Female","Gender == 2")});
options.RemoveItemAt(0);
axis.Options = options;
axis.AddOrUpdateAxisInAxisSet();
dcs.Save();
array x;
Dictionary d;
DCS_use(15636575);
array axis = AxisSet_getAxis("Gender");
print( axis[AXIS_OPTIONS]);//CompatibilityArray
//Skip
x = axis[AXIS_OPTIONS].Skip(1);
print(x);//{AxisOption}
//Contains
print(axis[AXIS_OPTIONS].Contains(axis[AXIS_OPTIONS][0]));// True
//First
x = axis[AXIS_OPTIONS].First(function(AxisOption a){
a[AXIS_OPTION_NAME]== "Female";
});
print(x);//AxisOption
//ToDictionary
d = axis[AXIS_OPTIONS].ToDictionary(function(AxisOption a){
a[AXIS_OPTION_NAME];
});
print(d);//{"Female": AxisOption, "Male": AxisOption}
//ToDictionary
d = axis[AXIS_OPTIONS].ToDictionary(function(AxisOption a){a[AXIS_OPTION_NAME];}, function(AxisOption a){a[AXIS_OPTION_VALUE];});
print(d);//{"Female": Gender == [2], "Male": Gender == [1]}
//Select
x = axis[AXIS_OPTIONS].Select(function (array a){a[AXIS_OPTION_VALUE];});
print(x);//{Gender == [1],Gender == [2]}
//SelectMany
x = axis[AXIS_OPTIONS].SelectMany(function (AxisOption a){
{a[AXIS_OPTION_NAME], a[AXIS_OPTION_VALUE] };
});
print(x);//{Male,Gender == [1],Female,Gender == [2]}
//Where
x = axis[AXIS_OPTIONS].Where(function(AxisOption a){
a[AXIS_OPTION_NAME]== "Female";
});
print(x);//{AxisOption}
//Comnine Where and select
x = axis[AXIS_OPTIONS].Where(function (array a){a[AXIS_OPTION_NAME]== "Female";})
.Select(function (array a){a[AXIS_OPTION_VALUE];});
print(x);//{Gender == [2]}
//Except
axis[AXIS_OPTIONS] = axis[AXIS_OPTIONS].Except({axis[AXIS_OPTIONS][0]});
AxisSet_save();