Difference between revisions of "CompatibilityArray class"

From Catglobe Wiki
Jump to: navigation, search
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
|Name=<nowiki>CompatibilityArray</nowiki>
 
|Name=<nowiki>CompatibilityArray</nowiki>
 
|Description=<nowiki>Maps cgs array to internal list for compatibility.</nowiki>
 
|Description=<nowiki>Maps cgs array to internal list for compatibility.</nowiki>
|Methods=
+
|InheritsFrom=array|Methods=
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Add</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Add</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=object|Name=<nowiki>element</nowiki>|Description=<nowiki>element to add</nowiki>}}
 
{{CGscriptParameters_Template|Type=object|Name=<nowiki>element</nowiki>|Description=<nowiki>element to add</nowiki>}}
Line 9: Line 9:
 
{{CGscriptParameters_Template|Type=array|Name=<nowiki>source</nowiki>|Description=<nowiki>Array to get elements from.</nowiki>}}
 
{{CGscriptParameters_Template|Type=array|Name=<nowiki>source</nowiki>|Description=<nowiki>Array to get elements from.</nowiki>}}
 
|Description=<nowiki>Add all elements of another array to this array.</nowiki>}}
 
|Description=<nowiki>Add all elements of another array to this array.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>Contains</nowiki>|Parameters=
+
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>Any</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>predicate</nowiki>|Description=<nowiki>A function that takes 1 parameter of the types in the array, and return true/false</nowiki>}}
 +
|Description=<nowiki>Return true if the array contains the element using the given function.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>Contains</nowiki>|Inherited=array|Parameters=
 
{{CGscriptParameters_Template|Type=object|Name=<nowiki>element</nowiki>|Description=<nowiki>Element to check for</nowiki>}}
 
{{CGscriptParameters_Template|Type=object|Name=<nowiki>element</nowiki>|Description=<nowiki>Element to check for</nowiki>}}
 
|Description=<nowiki>Return true if the array contains the element using the normal equal operator.</nowiki>}}
 
|Description=<nowiki>Return true if the array contains the element using the normal equal operator.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Except</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=array|Name=<nowiki>elements</nowiki>|Description=<nowiki>Elements to remove</nowiki>}}
 +
|Description=<nowiki>Return all elements that does not exist in the other collection.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>First</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A function to test each element for a condition.</nowiki>}}
 +
|Description=<nowiki>Returns the first element in a sequence that satisfies a specified condition.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>FirstOrDefault</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A function to test each element for a condition.</nowiki>}}
 +
|Description=<nowiki>Returns the first element in a sequence that satisfies a specified condition or empty if not found.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>Frequency</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=number|Name=<nowiki>number</nowiki>|Description=<nowiki>The number to search for</nowiki>}}
 +
|Description=<nowiki>Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type Number</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>}}
 
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>}}
 
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
 
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>IndexOf</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=object|Name=<nowiki>element</nowiki>|Description=<nowiki>Element to search for</nowiki>}}
 +
|Description=<nowiki>Return index of the given element, or -1.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsCharacterArray</nowiki>|Inherited=array|Description=<nowiki>check if array is an array of characters</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsNumericArray</nowiki>|Inherited=array|Description=<nowiki>check if array is an array of integer numbers</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>IsStringArray</nowiki>|Inherited=array|Description=<nowiki>check if array is an array of string</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>OrderBy</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>comparer</nowiki>|Description=<nowiki>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.</nowiki>}}
 +
|Description=<nowiki>Sorts the elements of a sequence in ascending order by using a specified comparer.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Randomize</nowiki>|Inherited=array|Description=<nowiki>Randomize the order of the elements in the current array.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>RemoveItemAt</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>RemoveItemAt</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>The index to remove the object from</nowiki>}}
 
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>The index to remove the object from</nowiki>}}
 
|Description=<nowiki>Remove an element from the Array</nowiki>}}
 
|Description=<nowiki>Remove an element from the Array</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Reverse</nowiki>|Inherited=array|Description=<nowiki>Returns an array with all the elements in the opposite order.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Select</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A transform function to apply to each element.</nowiki>}}
 +
|Description=<nowiki>Projects each element of a sequence into a new form.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>SelectMany</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A transform function to get each sub array.</nowiki>}}
 +
|Description=<nowiki>Projects each array element of a sequence into a new form.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to set</nowiki>}}
 
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to set</nowiki>}}
 
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
 
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Skip</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=int|Name=<nowiki>n</nowiki>|Description=<nowiki>How many elements to skip</nowiki>}}
 +
|Description=<nowiki>Get all but the n first elements.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Take</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=int|Name=<nowiki>n</nowiki>|Description=<nowiki>How many elements to take</nowiki>}}
 +
|Description=<nowiki>Get the n first elements.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>ToDictionary</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>keySelector</nowiki>|Description=<nowiki>A transform function to get the key of each element.</nowiki>}}
 +
|Description=<nowiki>Return a dictionary with the elements of the array.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>ToDictionary</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>keySelector</nowiki>|Description=<nowiki>A transform function to get the key of each element.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=Function|Name=<nowiki>valueSelector</nowiki>|Description=<nowiki>A transform function to get the value of each element.</nowiki>}}
 +
|Description=<nowiki>Return a dictionary with the elements of the array.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Where</nowiki>|Inherited=array|Parameters=
 +
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>predicate</nowiki>|Description=<nowiki>A function that takes 1 parameter of the types in the array, and an optional 2nd parameter that is the index and return true/false</nowiki>}}
 +
|Description=<nowiki>Filters a sequence of values based on a predicate.</nowiki>}}
 
|Properties=
 
|Properties=
 +
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Average</nowiki>|HasGetter=1|Inherited=array|Description=<nowiki>Average of the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Count</nowiki>|HasGetter=1|Description=<nowiki>Number of elements in Array</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Count</nowiki>|HasGetter=1|Description=<nowiki>Number of elements in Array</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Max</nowiki>|HasGetter=1|Inherited=array|Description=<nowiki>Largest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Min</nowiki>|HasGetter=1|Inherited=array|Description=<nowiki>Smallest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Sum</nowiki>|HasGetter=1|Inherited=array|Description=<nowiki>Sum of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 
}}
 
}}
 +
 
=== <span style="color:#DF8621">'''Examples'''</span> ===
 
=== <span style="color:#DF8621">'''Examples'''</span> ===
 
<source lang="javascript">
 
<source lang="javascript">
Line 40: Line 92:
 
axis.AddOrUpdateAxisInAxisSet();
 
axis.AddOrUpdateAxisInAxisSet();
 
dcs.Save();
 
dcs.Save();
 +
</source>
 +
 +
<source lang="javascript">
 +
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();
 
</source>
 
</source>

Latest revision as of 07:32, 2 July 2020

CompatibilityArray


Maps cgs array to internal list for compatibility.

Parent class

Inherits from array

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.
  • (From array) bool Any(Function predicate "A function that takes 1 parameter of the types in the array, and return true/false") - Return true if the array contains the element using the given function.
  • (From array) bool Contains(object element "Element to check for") - Return true if the array contains the element using the normal equal operator.
  • (From array) array Except(array elements "Elements to remove") - Return all elements that does not exist in the other collection.
  • (From array) 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.
  • (From array) 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.
  • (From array) 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
  • (From array) int IndexOf(object element "Element to search for") - Return index of the given element, or -1.
  • (From array) bool IsCharacterArray() - check if array is an array of characters
  • (From array) bool IsNumericArray() - check if array is an array of integer numbers
  • (From array) bool IsStringArray() - check if array is an array of string
  • (From array) 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.
  • (From array) 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
  • (From array) array Reverse() - Returns an array with all the elements in the opposite order.
  • (From array) array Select(Function selector "A transform function to apply to each element.") - Projects each element of a sequence into a new form.
  • (From array) 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
  • (From array) array Skip(int n "How many elements to skip") - Get all but the n first elements.
  • (From array) array Take(int n "How many elements to take") - Get the n first elements.
  • (From array) Dictionary ToDictionary(Function keySelector "A transform function to get the key of each element.") - Return a dictionary with the elements of the array.
  • (From 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.
  • (From array) array Where(Function predicate "A function that takes 1 parameter of the types in the array, and an optional 2nd parameter that is the index and return true/false") - Filters a sequence of values based on a predicate.

Properties

  • (From array) 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
  • (From array) number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number
  • (From array) 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.
  • (From array) number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number
  • (From object) 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();