You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2015/06/07 18:10:00 UTC

[1/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails

Repository: flex-sdk
Updated Branches:
  refs/heads/develop 11489c6e7 -> 94dd74615


FLEX-34852
Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7cd1b3bc
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7cd1b3bc
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7cd1b3bc

Branch: refs/heads/develop
Commit: 7cd1b3bc69f11c6c9d88a65e0df9eae39a17afa3
Parents: 11489c6
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 12:53:06 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 12:53:06 2015 +0200

----------------------------------------------------------------------
 .../framework/tests/FLEX_34852_Tests.as         | 129 +++++++++++++++++++
 .../ListCollectionView_FLEX_34837_Tests.as      |  18 ---
 2 files changed, 129 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/FLEX_34852_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
new file mode 100644
index 0000000..3a66221
--- /dev/null
+++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
@@ -0,0 +1,129 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package {
+    import mx.collections.ArrayList;
+    import mx.collections.IList;
+    import mx.collections.ListCollectionView;
+    import mx.collections.Sort;
+    import mx.collections.SortField;
+
+    import org.flexunit.asserts.assertEquals;
+
+    public class FLEX_34852_Tests {
+        private var _sut:ListCollectionView;
+
+        [Before]
+        public function setUp():void
+        {
+            _sut = new ListCollectionView(new ArrayList());
+        }
+
+        [After]
+        public function tearDown():void
+        {
+            _sut = null;
+        }
+
+        [Test]
+        public function test_simple_ascending_sort_by_complex_fields():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
+
+            const sortByIndexAscending:Sort = new Sort();
+            sortByIndexAscending.fields = [new SortField("address.street", false, false, false)];
+            _sut.sort = sortByIndexAscending;
+
+            //when
+            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+
+
+        private function assertIndexesAre(indexes:Array):void
+        {
+            assertEquals(indexes.length, _sut.length);
+
+            for(var i:int = 0; i < _sut.length; i++)
+            {
+                assertEquals(FLEX_34852_VO(_sut.getItemAt(i)).index, indexes[i]);
+            }
+        }
+
+
+        private static function generateVOs(no:int, reverse:Boolean = false):IList
+        {
+            return generateObjects(no, reverse, generateOneObject);
+        }
+
+        private static function generateObjects(no:int, reverse:Boolean, generator:Function):IList
+        {
+            var result:Array = [];
+            for(var i:int = 0; i < no; i++)
+            {
+                result.push(generator(i));
+            }
+
+            if(reverse)
+                result.reverse();
+
+            return new ArrayList(result);
+        }
+
+        private static function generateOneObject(i:Number):FLEX_34852_VO
+        {
+            return new FLEX_34852_VO(i, "Object"+i, "Street"+i);
+        }
+    }
+}
+
+class FLEX_34852_VO
+{
+    [Bindable]
+    public var name:String;
+
+    [Bindable]
+    public var address:FLEX_34852_AddressVO;
+
+    [Bindable]
+    public var index:Number;
+
+    public function FLEX_34852_VO(index:Number, namePrefix:String, streetPrefix:String)
+    {
+        this.index = index;
+        this.name = namePrefix + index;
+        this.address = new FLEX_34852_AddressVO(streetPrefix + index);
+    }
+}
+
+class FLEX_34852_AddressVO
+{
+    [Bindable]
+    public var street:String;
+
+    public function FLEX_34852_AddressVO(street:String)
+    {
+        this.street = street;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
index f11e906..ae8f746 100644
--- a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
+++ b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
@@ -43,24 +43,6 @@ package {
         }
 
         [Test]
-        public function test_simple_ascending_sort_by_complex_fields():void
-        {
-            //given
-            var from4To0:IList = generateVOs(5, true);
-            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
-
-            const sortByIndexAscending:Sort = new Sort();
-            sortByIndexAscending.fields = [new SortField("address.street", false, false, false)];
-            _sut.sort = sortByIndexAscending;
-
-            //when
-            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
-
-            //then
-            assertIndexesAre([0, 1, 2, 3, 4]);
-        }
-
-        [Test]
         public function test_simple_sort_by_complex_fields_with_custom_compare_function_for_sort():void
         {
             function compareByStreet(a:ListCollectionView_FLEX_34837_VO, b:ListCollectionView_FLEX_34837_VO, fields:Array):int


[5/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Removing unused local variables.

Posted by mi...@apache.org.
FLEX-34852
Removing unused local variables.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/5a27cc80
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/5a27cc80
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/5a27cc80

Branch: refs/heads/develop
Commit: 5a27cc8044e4e7a8e22cb2c75037bb9356d6d128
Parents: fe87d2f
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 13:13:41 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 13:13:41 2015 +0200

----------------------------------------------------------------------
 frameworks/projects/framework/src/mx/collections/Sort.as | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/5a27cc80/frameworks/projects/framework/src/mx/collections/Sort.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/Sort.as b/frameworks/projects/framework/src/mx/collections/Sort.as
index a1c7333..db0f704 100644
--- a/frameworks/projects/framework/src/mx/collections/Sort.as
+++ b/frameworks/projects/framework/src/mx/collections/Sort.as
@@ -244,8 +244,8 @@ public class Sort extends EventDispatcher implements ISort
      */
     public function set compareFunction(value:Function):void
     {
-        _compareFunction = value;
-        usingCustomCompareFunction = _compareFunction != null;
+            _compareFunction = value;
+            usingCustomCompareFunction = _compareFunction != null;
     }
 
     //----------------------------------
@@ -334,7 +334,7 @@ public class Sort extends EventDispatcher implements ISort
      */
     public function set unique(value:Boolean):void
     {
-        _unique = value;
+            _unique = value;
     }
 
     //--------------------------------------------------------------------------
@@ -650,10 +650,8 @@ public class Sort extends EventDispatcher implements ISort
         }
         else
         {
-            var fields:Array = this.fields;
             if (fields && fields.length > 0)
             {
-                var i:int;
                 //doing the init value each time may be a little inefficient
                 //but allows for the data to change and the comparators
                 //to update correctly


[4/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 ComplexSortField is now able to retrieve the value of a complex property using the newly introduced ObjectUtil.getValue. This is achieved by extracting SortField's sort field (currently inlin

Posted by mi...@apache.org.
FLEX-34852
ComplexSortField is now able to retrieve the value of a complex property using the newly introduced ObjectUtil.getValue. This is achieved by extracting SortField's sort field (currently inline) value retrievals into a protected function called getSortFieldValue() and overriding it in ComplexSortField.
Also, ComplexSortField.arraySortOnOptions returns -1 to specify that Array.sortOn should not be used by Sort (because it cannot sort by field chains).
Note that at this point FLEX_34852_Tests pass.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/fe87d2fe
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/fe87d2fe
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/fe87d2fe

Branch: refs/heads/develop
Commit: fe87d2feb353140c9319bb994cf2caa37eacbd43
Parents: 649d811
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 13:12:44 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 13:12:44 2015 +0200

----------------------------------------------------------------------
 .../src/mx/collections/ComplexSortField.as      |  10 ++
 .../framework/src/mx/collections/SortField.as   | 114 +++++--------------
 2 files changed, 41 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/fe87d2fe/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ComplexSortField.as b/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
index 6c9a27b..0736be3 100644
--- a/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
+++ b/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
@@ -33,5 +33,15 @@ package mx.collections {
             super(name, caseInsensitive, descending, numeric);
             _nameParts = name.split(".");
         }
+
+        override protected function getSortFieldValue(obj:Object):Object
+        {
+            return ObjectUtil.getValue(obj, _nameParts);
+        }
+
+        override public function get arraySortOnOptions():int
+        {
+            return -1;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/fe87d2fe/frameworks/projects/framework/src/mx/collections/SortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/SortField.as b/frameworks/projects/framework/src/mx/collections/SortField.as
index 0afb05f..270bea5 100644
--- a/frameworks/projects/framework/src/mx/collections/SortField.as
+++ b/frameworks/projects/framework/src/mx/collections/SortField.as
@@ -651,6 +651,27 @@ public class SortField extends EventDispatcher implements ISortField
 
     //--------------------------------------------------------------------------
     //
+    //  Protected Methods
+    //
+    //--------------------------------------------------------------------------
+
+    protected function getSortFieldValue(obj:Object):Object
+    {
+        var result:Object = null;
+
+        try
+        {
+            result = obj[_name];
+        }
+        catch(error:Error)
+        {
+        }
+
+        return result;
+    }
+
+    //--------------------------------------------------------------------------
+    //
     //  Private Methods
     //
     //--------------------------------------------------------------------------
@@ -671,21 +692,8 @@ public class SortField extends EventDispatcher implements ISortField
         // we need to introspect the data a little bit
         if (_name)
         {
-            try
-            {
-                left = a[_name];
-            }
-            catch(error:Error)
-            {
-            }
-
-            try
-            {
-                right = b[_name];
-            }
-            catch(error:Error)
-            {
-            }
+            left = getSortFieldValue(a);
+            right = getSortFieldValue(b);
         }
 
         // return 0 (ie equal) if both are null
@@ -750,23 +758,8 @@ public class SortField extends EventDispatcher implements ISortField
      */
     private function numericCompare(a:Object, b:Object):int
     {
-        var fa:Number;
-        try
-        {
-            fa = _name == null ? Number(a) : Number(a[_name]);
-        }
-        catch(error:Error)
-        {
-        }
-
-        var fb:Number;
-        try
-        {
-            fb = _name == null ? Number(b) : Number(b[_name]);
-        }
-        catch(error:Error)
-        {
-        }
+        var fa:Number = _name == null ? Number(a) : Number(getSortFieldValue(a));
+        var fb:Number = _name == null ? Number(b) : Number(getSortFieldValue(b));
 
         return ObjectUtil.numericCompare(fa, fb);
     }
@@ -781,23 +774,8 @@ public class SortField extends EventDispatcher implements ISortField
      */
     private function dateCompare(a:Object, b:Object):int
     {
-        var fa:Date;
-        try
-        {
-            fa = _name == null ? a as Date : a[_name] as Date;
-        }
-        catch(error:Error)
-        {
-        }
-
-        var fb:Date;
-        try
-        {
-            fb = _name == null ? b as Date : b[_name] as Date;
-        }
-        catch(error:Error)
-        {
-        }
+        var fa:Date = _name == null ? a as Date : getSortFieldValue(a) as Date;
+        var fb:Date = _name == null ? b as Date : getSortFieldValue(b) as Date;
 
         return ObjectUtil.dateCompare(fa, fb);
     }
@@ -812,23 +790,8 @@ public class SortField extends EventDispatcher implements ISortField
      */
     private function stringCompare(a:Object, b:Object):int
     {
-        var fa:String;
-        try
-        {
-            fa = _name == null ? String(a) : String(a[_name]);
-        }
-        catch(error:Error)
-        {
-        }
-
-        var fb:String;
-        try
-        {
-            fb = _name == null ? String(b) : String(b[_name]);
-        }
-        catch(error:Error)
-        {
-        }
+        var fa:String = _name == null ? String(a) : String(getSortFieldValue(a));
+        var fb:String = _name == null ? String(b) : String(getSortFieldValue(b));
 
         return ObjectUtil.stringCompare(fa, fb, _caseInsensitive);
     }
@@ -845,23 +808,8 @@ public class SortField extends EventDispatcher implements ISortField
      */
     private function xmlCompare(a:Object, b:Object):int
     {
-        var sa:String;
-        try
-        {
-            sa = _name == null ? a.toString() : a[_name].toString();
-        }
-        catch(error:Error)
-        {
-        }
-
-        var sb:String;
-        try
-        {
-            sb = _name == null ? b.toString() : b[_name].toString();
-        }
-        catch(error:Error)
-        {
-        }
+        var sa:String = _name == null ? a.toString() : getSortFieldValue(a).toString();
+        var sb:String = _name == null ? b.toString() : getSortFieldValue(b).toString();
 
         if (numeric == true)
         {


[8/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34853, FLEX-34879 CAUSE: ListCollectionView.getItemIndex() uses findItem() which, along with findFirst(), findAny() and findLast(), always use the Sort to do the searching if the collection is alre

Posted by mi...@apache.org.
FLEX-34853, FLEX-34879
CAUSE:
ListCollectionView.getItemIndex() uses findItem() which, along with findFirst(), findAny() and findLast(), always use the Sort to do the searching if the collection is already sorted. However, this assumes that all the current properties of Sort (including the properties of its SortFields) accurately represent the current sorting order in the collection, which is not the case. The reason is that one can change any property of Sort and SortField without the collection noticing. This leads to the error.

SOLUTION:
After discussing it with Alex H, I decided to implement a step-by-step transformation of SortField and Sort into true (i.e. immutable) value objects. They are suited to this design pattern because they have no identity, and the fact that they are now mutable has allowed this bug to exist. This way, no property will be changeable on SortField and Sort without recreating an object (and potentially cloning an existing one).
This first step (FLEX-34879) is to mark the setters and the reverse() functions as deprecated for the next release, and to ensure that users can specify all the state fields directly in the constructors.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/94dd7461
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/94dd7461
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/94dd7461

Branch: refs/heads/develop
Commit: 94dd74615f96bea5dd7ead274810d8548d4506fc
Parents: 8dae0da
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 17:51:08 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 17:51:08 2015 +0200

----------------------------------------------------------------------
 .../framework/src/mx/collections/ISort.as       | 22 +++++++-
 .../framework/src/mx/collections/ISortField.as  | 34 +++++++++++-
 .../framework/src/mx/collections/Sort.as        | 33 ++++++-----
 .../framework/src/mx/collections/SortField.as   | 57 ++++++++++++-------
 .../spark/src/spark/collections/Sort.as         | 50 +++++++++--------
 .../spark/src/spark/collections/SortField.as    | 58 +++++++++++---------
 6 files changed, 171 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/94dd7461/frameworks/projects/framework/src/mx/collections/ISort.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ISort.as b/frameworks/projects/framework/src/mx/collections/ISort.as
index 14e3b74..640b49a 100644
--- a/frameworks/projects/framework/src/mx/collections/ISort.as
+++ b/frameworks/projects/framework/src/mx/collections/ISort.as
@@ -128,10 +128,16 @@ public interface ISort
      *  @productversion Flex 4.5
      */
     function get compareFunction():Function;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set compareFunction(value:Function):void;
 
     /**
-     *  An <code>Array</code> of <code>ISortField</code> objects that specifies the fields to compare.
+     *  An <code>Array</code> of <code>ISortField</code> objects that
+     *  specifies the fields to compare.
      *  The order of the ISortField objects in the array determines
      *  field priority order when sorting.
      *  The default sort comparator checks the sort fields in array
@@ -148,6 +154,11 @@ public interface ISort
      *  @productversion Flex 4.5
      */
     function get fields():Array;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set fields(value:Array):void;
 
     /**
@@ -169,6 +180,11 @@ public interface ISort
      *  @productversion Flex 4.5
      */
     function get unique():Boolean;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set unique(value:Boolean):void;
 
     //--------------------------------------------------------------------------
@@ -305,6 +321,10 @@ public interface ISort
      *  update when the objects in the <code>fields</code> array are modified; 
      *  call its <code>refresh()</code> method to update the view.</p>
      *
+     *  <p>Note: a future release of Apache Flex SDK will change the signature
+     *  of this function to return a reversed clone of this Sort instance. See
+     *  FLEX-34853.</p>
+     *
      *  @langversion 3.0
      *  @playerversion Flash 9
      *  @playerversion AIR 1.1

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/94dd7461/frameworks/projects/framework/src/mx/collections/ISortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ISortField.as b/frameworks/projects/framework/src/mx/collections/ISortField.as
index be4bdc8..8ce3228 100644
--- a/frameworks/projects/framework/src/mx/collections/ISortField.as
+++ b/frameworks/projects/framework/src/mx/collections/ISortField.as
@@ -42,7 +42,7 @@ public interface ISortField
      *  and <code>sort()</code> methods. Other uses of this property are not 
      *  supported.
      *  Returns -1 if this ISortField shouldn't be used by the <code>Sort</code>
-     *  class to sort the field (there is no compareFunction or no name). Otherwise, returns a bitmask of sort options..
+     *  class to sort the field (there is no compareFunction or no name). Otherwise, returns a bitmask of sort options.
      * 
      *  @langversion 3.0
      *  @playerversion Flash 9
@@ -77,6 +77,11 @@ public interface ISortField
      *  @productversion Flex 4.5
      */
     function get compareFunction():Function;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set compareFunction(c:Function):void;
 
     /**
@@ -91,6 +96,11 @@ public interface ISortField
      *  @productversion Flex 4.5
      */
     function get descending():Boolean;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set descending(value:Boolean):void;
 
     /**
@@ -102,6 +112,11 @@ public interface ISortField
      *  @productversion Flex 4.5
      */
     function get name():String;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set name(n:String):void;
 
     /**
@@ -137,6 +152,11 @@ public interface ISortField
      *  @productversion Flex 4.5
      */
     function get numeric():Object;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set numeric(value:Object):void;
 
 
@@ -152,6 +172,11 @@ public interface ISortField
      *  @productversion Flex 4.11
      */
     function get sortCompareType():String;
+
+    /**
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
+     */
     function set sortCompareType(value:String):void;
 
 
@@ -202,6 +227,10 @@ public interface ISortField
      *  update when the <code>ISortFields</code> are modified; call its 
      *  <code>refresh()</code> method to update the view.</p>
      *
+     *  <p>Note: a future release of Apache Flex SDK will change the signature
+     *  of this function to return a reversed clone of this SortField instance.
+     *  See FLEX-34853 for more details.</p>
+     *
      *  @langversion 3.0
      *  @playerversion Flash 9
      *  @playerversion AIR 1.1
@@ -213,6 +242,9 @@ public interface ISortField
     /**
      *  This changes the internal compare function used by the <code>SortField</code> based
      *  on the value of <code>sortCompareType</code>.
+     *
+     *  @deprecated A future release of Apache Flex SDK will remove this function in favour of
+     *  making ISortField instances immutable.
      * 
      *  @return true for successfully matched or false for failure to match the <code>sortCompareType</code>.
      * 

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/94dd7461/frameworks/projects/framework/src/mx/collections/Sort.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/Sort.as b/frameworks/projects/framework/src/mx/collections/Sort.as
index 14f1d64..fa52f2f 100644
--- a/frameworks/projects/framework/src/mx/collections/Sort.as
+++ b/frameworks/projects/framework/src/mx/collections/Sort.as
@@ -20,18 +20,15 @@
 package mx.collections
 {
 
-import flash.events.Event;
-import flash.events.EventDispatcher;
-import mx.collections.ISort;
-import mx.collections.ISortField;
-import mx.collections.errors.SortError;
-import mx.managers.ISystemManager;
-import mx.managers.SystemManager;
-import mx.resources.IResourceManager;
-import mx.resources.ResourceManager;
-import mx.utils.ObjectUtil;
-
-[DefaultProperty("fields")]
+    import flash.events.Event;
+    import flash.events.EventDispatcher;
+
+    import mx.collections.errors.SortError;
+    import mx.resources.IResourceManager;
+    import mx.resources.ResourceManager;
+    import mx.utils.ObjectUtil;
+
+    [DefaultProperty("fields")]
 [ResourceBundle("collections")]
 [Alternative(replacement="spark.collections.Sort", since="4.5")]
 
@@ -180,14 +177,24 @@ public class Sort extends EventDispatcher implements ISort
      *
      *  <p>Creates a new Sort with no fields set and no custom comparator.</p>
      *
+     *  @param fields An <code>Array</code> of <code>ISortField</code> objects that
+     *  specifies the fields to compare.
+     *  @param customCompareFunction Use a custom function to compare the
+     *  objects in the collection to which this sort will be applied.
+     *  @param unique Indicates if the sort should be unique.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 9
      *  @playerversion AIR 1.1
      *  @productversion Flex 3
      */
-    public function Sort()
+    public function Sort(fields:Array = null, customCompareFunction:Function = null, unique:Boolean = false)
     {
         super();
+
+        this.fields = fields;
+        this.compareFunction = customCompareFunction;
+        this.unique = unique;
     }
 
     //--------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/94dd7461/frameworks/projects/framework/src/mx/collections/SortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/SortField.as b/frameworks/projects/framework/src/mx/collections/SortField.as
index d8780f1..71712ea 100644
--- a/frameworks/projects/framework/src/mx/collections/SortField.as
+++ b/frameworks/projects/framework/src/mx/collections/SortField.as
@@ -24,6 +24,7 @@ package mx.collections
     import flash.events.EventDispatcher;
 
     import mx.collections.errors.SortError;
+    import mx.core.mx_internal;
     import mx.resources.IResourceManager;
     import mx.resources.ResourceManager;
     import mx.utils.ObjectUtil;
@@ -67,10 +68,10 @@ package mx.collections
  *
  *  <p>By default the comparison provided by the SortField class does
  *  not provide correct language specific
- *  sorting for strings.  For this type of sorting please see the 
- *  <code>spark.collections.Sort</code> and 
+ *  sorting for strings.  For this type of sorting please see the
+ *  <code>spark.collections.Sort</code> and
  *  <code>spark.collections.SortField</code> classes.</p>
- * 
+ *
  *  @mxml
  *
  *  <p>The <code>&lt;mx:SortField&gt;</code> tag has the following attributes:</p>
@@ -118,6 +119,10 @@ public class SortField extends EventDispatcher implements ISortField
      *              descending order.
      *  @param numeric Tells the comparator whether to compare sort items as
      *              numbers, instead of alphabetically.
+     *  @param sortCompareType Gives an indication to SortField which of the
+     *              default compare functions to use.
+     *  @param customCompareFunction Use a custom function to compare the
+     *              objects based on this SortField.
      *
      *  @langversion 3.0
      *  @playerversion Flash 9
@@ -127,7 +132,9 @@ public class SortField extends EventDispatcher implements ISortField
     public function SortField(name:String = null,
                               caseInsensitive:Boolean = false,
                               descending:Boolean = false,
-                              numeric:Object = null)
+                              numeric:Object = null,
+                              sortCompareType:String = null,
+                              customCompareFunction:Function = null)
     {
         super();
 
@@ -135,8 +142,13 @@ public class SortField extends EventDispatcher implements ISortField
         _caseInsensitive = caseInsensitive;
         _descending = descending;
         _numeric = numeric;
+        _sortCompareType = sortCompareType;
 
-        if (updateSortCompareType() == false)
+        if(customCompareFunction != null)
+        {
+            compareFunction = customCompareFunction;
+        }
+        else if (updateSortCompareType() == false)
         {
             _compareFunction = stringCompare;
         }
@@ -218,9 +230,10 @@ public class SortField extends EventDispatcher implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
-    public function set caseInsensitive(value:Boolean):void
+    mx_internal function setCaseInsensitive(value:Boolean):void
     {
         if (value != _caseInsensitive)
         {
@@ -244,7 +257,7 @@ public class SortField extends EventDispatcher implements ISortField
     /**
      *  The function that compares two items during a sort of items for the
      *  associated collection. If you specify a <code>compareFunction</code>
-     *  property in an ISort object, Flex ignores any 
+     *  property in an ISort object, Flex ignores any
      *  <code>compareFunction</code> properties of the ISort's SortField
      *  objects.
      *  <p>The compare function must have the following signature:</p>
@@ -260,19 +273,19 @@ public class SortField extends EventDispatcher implements ISortField
      *        <li>1, if <code>a</code> should appear after <code>b</code> in the
      *        sorted sequence</li>
      *  </ul>
-     * 
+     *
      *  <p>The default value is an internal compare function that can perform
      *  a string, numeric, or date comparison in ascending or descending order,
      *  with case-sensitive or case-insensitive string comparisons.
      *  Specify your own function only if you need a need a custom comparison
      *  algorithm. This is normally only the case if a calculated field is
      *  used in a display.</p>
-     *  
-     *  Note if you need, language specific sorting then consider using the
+     *
+     *  Note if you need language-specific sorting then consider using the
      *  <code>spark.collections.SortField</code> class.
-     * 
+     *
      *  @see spark.collections.SortField
-     * 
+     *
      *  @langversion 3.0
      *  @playerversion Flash 9
      *  @playerversion AIR 1.1
@@ -284,7 +297,8 @@ public class SortField extends EventDispatcher implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set compareFunction(c:Function):void
     {
@@ -319,7 +333,8 @@ public class SortField extends EventDispatcher implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set descending(value:Boolean):void
     {
@@ -359,7 +374,8 @@ public class SortField extends EventDispatcher implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set name(n:String):void
     {
@@ -396,7 +412,8 @@ public class SortField extends EventDispatcher implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set numeric(value:Object):void
     {
@@ -432,7 +449,8 @@ public class SortField extends EventDispatcher implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set sortCompareType(value:String):void
     {
@@ -442,7 +460,6 @@ public class SortField extends EventDispatcher implements ISortField
             dispatchEvent(new Event("sortCompareTypeChanged"));
         }
 
-
         updateSortCompareType();
     }
 
@@ -585,7 +602,7 @@ public class SortField extends EventDispatcher implements ISortField
 
     /**
      *  @inheritDoc
-     * 
+     *
      *  @langversion 3.0
      *  @playerversion Flash 11.8
      *  @playerversion AIR 3.8

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/94dd7461/frameworks/projects/spark/src/spark/collections/Sort.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/collections/Sort.as b/frameworks/projects/spark/src/spark/collections/Sort.as
index ec85d67..a01ebf6 100644
--- a/frameworks/projects/spark/src/spark/collections/Sort.as
+++ b/frameworks/projects/spark/src/spark/collections/Sort.as
@@ -20,24 +20,18 @@
 package spark.collections
 {
 
-import flash.errors.IllegalOperationError;
-import flash.events.Event;
-import flash.events.EventDispatcher;
-
-import mx.collections.ISort;
-import mx.collections.ISortField;
-import mx.collections.errors.SortError;
-import mx.core.FlexGlobals;
-import mx.core.UIComponent;
-import mx.managers.ISystemManager;
-import mx.managers.SystemManager;
-import mx.resources.IResourceManager;
-import mx.resources.ResourceManager;
-import mx.styles.AdvancedStyleClient;
-import mx.styles.IAdvancedStyleClient;
-import mx.utils.ObjectUtil;
-
-[DefaultProperty("fields")]
+    import flash.events.Event;
+
+    import mx.collections.ISort;
+    import mx.collections.ISortField;
+    import mx.collections.errors.SortError;
+    import mx.core.FlexGlobals;
+    import mx.resources.IResourceManager;
+    import mx.resources.ResourceManager;
+    import mx.styles.AdvancedStyleClient;
+    import mx.utils.ObjectUtil;
+
+    [DefaultProperty("fields")]
 [ResourceBundle("collections")]
 
 //--------------------------------------
@@ -250,14 +244,24 @@ public class Sort extends AdvancedStyleClient implements ISort
      *
      *  <p>Creates a new Sort with no fields set and no custom comparator.</p>
      *
+     *  @param fields An <code>Array</code> of <code>ISortField</code> objects that
+     *  specifies the fields to compare.
+     *  @param customCompareFunction Use a custom function to compare the
+     *  objects in the collection to which this sort will be applied.
+     *  @param unique Indicates if the sort should be unique.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.1
      *  @playerversion AIR 2.5
      *  @productversion Flex 4.5
      */
-    public function Sort()
+    public function Sort(fields:Array = null, customCompareFunction:Function = null, unique:Boolean = false)
     {
         super();
+
+        this.fields = fields;
+        this.compareFunction = customCompareFunction;
+        this.unique = unique;
     }
 
     //--------------------------------------------------------------------------
@@ -342,7 +346,7 @@ public class Sort extends AdvancedStyleClient implements ISort
      */
     private var fieldList:Array = [];
 
-    [Inspectable(category="General", arrayType="spark.globalization.ISortField")]
+    [Inspectable(category="General", arrayType="mx.collections.ISortField")]
     [Bindable("fieldsChanged")]
 
     /**
@@ -992,12 +996,12 @@ public class Sort extends AdvancedStyleClient implements ISort
      */
     private function localeChanged():void
     {
-        const newlocaleStyle:* = super.getStyle("locale");
+        const newLocaleStyle:* = super.getStyle("locale");
 
-        if (localeStyle === newlocaleStyle)
+        if (localeStyle === newLocaleStyle)
             return;
 
-        localeStyle = newlocaleStyle;
+        localeStyle = newLocaleStyle;
         if (defaultEmptyField)
             defaultEmptyField.setStyle("locale", localeStyle);
 

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/94dd7461/frameworks/projects/spark/src/spark/collections/SortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/collections/SortField.as b/frameworks/projects/spark/src/spark/collections/SortField.as
index 38d81e6..44e8fec 100644
--- a/frameworks/projects/spark/src/spark/collections/SortField.as
+++ b/frameworks/projects/spark/src/spark/collections/SortField.as
@@ -20,26 +20,19 @@
 package spark.collections
 {
 
-import flash.errors.IllegalOperationError;
-import flash.events.Event;
-import flash.events.EventDispatcher;
+    import flash.events.Event;
 
-import mx.collections.ISortField;
-import mx.collections.errors.SortError;
-import mx.core.FlexGlobals;
-import mx.core.UIComponent;
-import mx.managers.ISystemManager;
-import mx.managers.SystemManager;
-import mx.resources.IResourceManager;
-import mx.resources.ResourceManager;
-import mx.styles.AdvancedStyleClient;
-import mx.utils.ObjectUtil;
+    import mx.collections.ISortField;
+    import mx.collections.errors.SortError;
+    import mx.core.FlexGlobals;
+    import mx.resources.IResourceManager;
+    import mx.resources.ResourceManager;
+    import mx.styles.AdvancedStyleClient;
+    import mx.utils.ObjectUtil;
 
-import spark.globalization.SortingCollator;
-import spark.collections.SortFieldCompareTypes;
+    import spark.globalization.SortingCollator;
 
-
-[ResourceBundle("collections")]
+    [ResourceBundle("collections")]
 
 //--------------------------------------
 //  Styles
@@ -184,6 +177,10 @@ public class SortField extends AdvancedStyleClient implements ISortField
      *              descending order.
      *  @param numeric Tells the comparator whether to compare sort items as
      *              numbers, instead of alphabetically.
+     *  @param sortCompareType Gives an indication to SortField which of the
+     *              default compare functions to use.
+     *  @param customCompareFunction Use a custom function to compare the
+     *              objects based on this SortField.
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.1
@@ -192,15 +189,22 @@ public class SortField extends AdvancedStyleClient implements ISortField
      */
     public function SortField(name:String = null,
                               descending:Boolean = false,
-                              numeric:Object = null)
+                              numeric:Object = null,
+                              sortCompareType:String = null,
+                              customCompareFunction:Function = null)
     {
         super();
 
         _name = name;
         _descending = descending;
         _numeric = numeric;
+        _sortCompareType = sortCompareType;
 
-        if (updateSortCompareType() == false)
+        if(customCompareFunction != null)
+        {
+            compareFunction = customCompareFunction;
+        }
+        else if (updateSortCompareType() == false)
         {
             _compareFunction = stringCompare;
         }
@@ -312,7 +316,8 @@ public class SortField extends AdvancedStyleClient implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set compareFunction(c:Function):void
     {
@@ -347,7 +352,8 @@ public class SortField extends AdvancedStyleClient implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set descending(value:Boolean):void
     {
@@ -387,7 +393,8 @@ public class SortField extends AdvancedStyleClient implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set name(n:String):void
     {
@@ -424,7 +431,8 @@ public class SortField extends AdvancedStyleClient implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set numeric(value:Object):void
     {
@@ -461,7 +469,8 @@ public class SortField extends AdvancedStyleClient implements ISortField
     }
 
     /**
-     *  @private
+     *  @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor
+     *  argument instead.
      */
     public function set sortCompareType(value:String):void
     {
@@ -822,7 +831,6 @@ public class SortField extends AdvancedStyleClient implements ISortField
 
     private function nullCompare(a:Object, b:Object):int
     {
-        var value:Object;
         var left:Object;
         var right:Object;
 


[7/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added more unit tests to check for edge cases, and for Sort.unique variations. Also replaced the last inline sort field value retrieval in SortField (in initializeDefaultCompareFunction()).

Posted by mi...@apache.org.
FLEX-34852
Added more unit tests to check for edge cases, and for Sort.unique variations.
Also replaced the last inline sort field value retrieval in SortField (in initializeDefaultCompareFunction()).


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/8dae0daa
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/8dae0daa
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/8dae0daa

Branch: refs/heads/develop
Commit: 8dae0daab1d779ee17a23477159bef33524d4cb3
Parents: c4f20ee
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 14:57:22 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 14:57:22 2015 +0200

----------------------------------------------------------------------
 .../framework/src/mx/collections/Sort.as        |  3 +-
 .../framework/src/mx/collections/SortField.as   |  8 +--
 .../framework/tests/FLEX_34852_Tests.as         | 76 ++++++++++++++++++++
 3 files changed, 78 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/8dae0daa/frameworks/projects/framework/src/mx/collections/Sort.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/Sort.as b/frameworks/projects/framework/src/mx/collections/Sort.as
index db0f704..14f1d64 100644
--- a/frameworks/projects/framework/src/mx/collections/Sort.as
+++ b/frameworks/projects/framework/src/mx/collections/Sort.as
@@ -672,8 +672,7 @@ public class Sort extends EventDispatcher implements ISort
                     }
                     else
                     {
-                        uniqueRet2 = items.sort(internalCompare,
-                                                Array.UNIQUESORT);
+                        uniqueRet2 = items.sort(internalCompare, Array.UNIQUESORT);
                     }
                     if (uniqueRet2 == 0)
                     {

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/8dae0daa/frameworks/projects/framework/src/mx/collections/SortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/SortField.as b/frameworks/projects/framework/src/mx/collections/SortField.as
index 270bea5..d8780f1 100644
--- a/frameworks/projects/framework/src/mx/collections/SortField.as
+++ b/frameworks/projects/framework/src/mx/collections/SortField.as
@@ -520,13 +520,7 @@ public class SortField extends EventDispatcher implements ISortField
                 var value:Object;
                 if (_name)
                 {
-                    try
-                    {
-                        value = obj[_name];
-                    }
-                    catch(error:Error)
-                    {
-                    }
+                    value = getSortFieldValue(obj);
                 }
                 //this needs to be an == null check because !value will return true
                 //where value == 0 or value == false

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/8dae0daa/frameworks/projects/framework/tests/FLEX_34852_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
index 50836b9..dcb1bc9 100644
--- a/frameworks/projects/framework/tests/FLEX_34852_Tests.as
+++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
@@ -26,6 +26,7 @@ package {
     import mx.collections.SortFieldCompareTypes;
 
     import org.flexunit.asserts.assertEquals;
+    import org.flexunit.asserts.assertTrue;
 
     public class FLEX_34852_Tests {
         private var _sut:ListCollectionView;
@@ -79,6 +80,42 @@ package {
         }
 
         [Test]
+        public function test_simple_ascending_sort_by_complex_string_fields_with_unique_field():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
+
+            const sortByStreetAscending:Sort = new Sort();
+            sortByStreetAscending.fields = [new ComplexSortField("address.street", false, false, false)];
+            sortByStreetAscending.unique = true;
+            _sut.sort = sortByStreetAscending;
+
+            //when
+            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        [Test(expects="Error")]
+        public function test_simple_ascending_sort_by_complex_string_fields_with_unique_flag_and_duplicating_field_throws_error():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
+            FLEX_34852_VO(_sut.getItemAt(0)).address.street = "Street0"; //making sure there's a duplicate
+
+            const sortByStreetAscending:Sort = new Sort();
+            sortByStreetAscending.fields = [new ComplexSortField("address.street", false, false, false)];
+            sortByStreetAscending.unique = true;
+            _sut.sort = sortByStreetAscending;
+
+            //when
+            _sut.refresh(); //should throw an error about there being a duplicate value
+        }
+
+        [Test]
         public function test_simple_ascending_sort_by_complex_date_fields():void
         {
             //given
@@ -154,6 +191,45 @@ package {
             assertIndexesAre([4, 3, 2, 1, 0]);
         }
 
+        [Test]
+        public function test_simple_ascending_sort_with_empty_field_name_should_not_throw_error():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["index"]: 4, 3, 2, 1, 0
+
+            const sortByNothingAscending:Sort = new Sort();
+            sortByNothingAscending.fields = [new ComplexSortField("", false, false)];
+            _sut.sort = sortByNothingAscending;
+
+            //when
+            _sut.refresh(); //just make sure it doesn't throw an error.
+
+            //then - we cannot guarantee the order of the items because SortField.nullCompare returns 0 in this
+            // situation, so we just make sure there's no error
+            assertTrue(true);
+        }
+
+        [Test]
+        public function test_simple_ascending_sort_with_erroneous_field_name_should_not_throw_error():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["index"]: 4, 3, 2, 1, 0
+
+            const sortByNothingAscending:Sort = new Sort();
+            sortByNothingAscending.fields = [new ComplexSortField("aFieldThatDoesntExist", false, false)];
+            _sut.sort = sortByNothingAscending;
+
+            //when
+            _sut.refresh(); //just make sure it doesn't throw an error.
+
+            //then - we cannot guarantee the order of the items because SortField.nullCompare returns 0 in this
+            // situation, so we just make sure there's no error
+            assertTrue(true);
+        }
+
+
 
 
         private function assertIndexesAre(indexes:Array):void


[6/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added unit tests for numeric and date types.

Posted by mi...@apache.org.
FLEX-34852
Added unit tests for numeric and date types.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/c4f20ee2
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/c4f20ee2
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/c4f20ee2

Branch: refs/heads/develop
Commit: c4f20ee28d40f79274c3a2413847a7462cd5b59f
Parents: 5a27cc8
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 14:14:43 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 14:14:43 2015 +0200

----------------------------------------------------------------------
 .../framework/tests/FLEX_34852_Tests.as         | 117 +++++++++++++++++--
 1 file changed, 110 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/c4f20ee2/frameworks/projects/framework/tests/FLEX_34852_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
index 4a9b1ee..50836b9 100644
--- a/frameworks/projects/framework/tests/FLEX_34852_Tests.as
+++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
@@ -23,6 +23,7 @@ package {
     import mx.collections.IList;
     import mx.collections.ListCollectionView;
     import mx.collections.Sort;
+    import mx.collections.SortFieldCompareTypes;
 
     import org.flexunit.asserts.assertEquals;
 
@@ -42,15 +43,15 @@ package {
         }
 
         [Test]
-        public function test_simple_ascending_sort_by_complex_fields():void
+        public function test_simple_ascending_sort_by_complex_string_fields():void
         {
             //given
             var from4To0:IList = generateVOs(5, true);
             _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
 
-            const sortByIndexAscending:Sort = new Sort();
-            sortByIndexAscending.fields = [new ComplexSortField("address.street", false, false, false)];
-            _sut.sort = sortByIndexAscending;
+            const sortByStreetAscending:Sort = new Sort();
+            sortByStreetAscending.fields = [new ComplexSortField("address.street", false, false, false)];
+            _sut.sort = sortByStreetAscending;
 
             //when
             _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
@@ -59,6 +60,100 @@ package {
             assertIndexesAre([0, 1, 2, 3, 4]);
         }
 
+        [Test]
+        public function test_simple_descending_sort_by_complex_string_fields():void
+        {
+            //given
+            var from0To4:IList = generateVOs(5);
+            _sut.addAll(from0To4); //values["address.street"]: Street0, Street1, Street2, Street3, Street4
+
+            const sortByStreetDescending:Sort = new Sort();
+            sortByStreetDescending.fields = [new ComplexSortField("address.street", false, true, false)];
+            _sut.sort = sortByStreetDescending;
+
+            //when
+            _sut.refresh(); //should be: Street4, Street3, Street2, Street1, Street0
+
+            //then
+            assertIndexesAre([4, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_simple_ascending_sort_by_complex_date_fields():void
+        {
+            //given
+            var from2004To2000:IList = generateVOs(5, true);
+            _sut.addAll(from2004To2000); //values["address.dateMovedIn"].getYear(): 2004, 2003, 2002, 2001, 2000
+
+            const sortByDateMovedInAscending:Sort = new Sort();
+            var complexSortField:ComplexSortField = new ComplexSortField("address.dateMovedIn", false, false, false);
+            complexSortField.sortCompareType = SortFieldCompareTypes.DATE;
+            sortByDateMovedInAscending.fields = [complexSortField];
+            _sut.sort = sortByDateMovedInAscending;
+
+            //when
+            _sut.refresh(); //should be: 2000, 2001, 2002, 2003, 2004
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        [Test]
+        public function test_simple_descending_sort_by_complex_date_fields():void
+        {
+            //given
+            var from2000To2004:IList = generateVOs(5);
+            _sut.addAll(from2000To2004); //values["address.dateMovedIn"].getYear(): 2000, 2001, 2002, 2003, 2004
+
+            const sortByDateMovedInDescending:Sort = new Sort();
+            var complexSortField:ComplexSortField = new ComplexSortField("address.dateMovedIn", false, true, false);
+            complexSortField.sortCompareType = SortFieldCompareTypes.DATE;
+            sortByDateMovedInDescending.fields = [complexSortField];
+            _sut.sort = sortByDateMovedInDescending;
+
+            //when
+            _sut.refresh(); //should be: 2004, 2003, 2002, 2001, 2000
+
+            //then
+            assertIndexesAre([4, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_simple_ascending_sort_by_complex_number_fields():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.houseNumber"]: 4, 3, 2, 1, 0
+
+            const sortByHouseNumberAscending:Sort = new Sort();
+            sortByHouseNumberAscending.fields = [new ComplexSortField("address.houseNumber", false, false, true)];
+            _sut.sort = sortByHouseNumberAscending;
+
+            //when
+            _sut.refresh(); //should be: 0, 1, 2, 3, 4
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        [Test]
+        public function test_simple_descending_sort_by_complex_number_fields():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5);
+            _sut.addAll(from4To0); //values["address.houseNumber"]: 0, 1, 2, 3, 4
+
+            const sortByHouseNumberDescending:Sort = new Sort();
+            sortByHouseNumberDescending.fields = [new ComplexSortField("address.houseNumber", false, true, true)];
+            _sut.sort = sortByHouseNumberDescending;
+
+            //when
+            _sut.refresh(); //should be: 4, 3, 2, 1, 0
+
+            //then
+            assertIndexesAre([4, 3, 2, 1, 0]);
+        }
+
 
 
         private function assertIndexesAre(indexes:Array):void
@@ -93,7 +188,7 @@ package {
 
         private static function generateOneObject(i:Number):FLEX_34852_VO
         {
-            return new FLEX_34852_VO(i, "Object"+i, "Street"+i);
+            return new FLEX_34852_VO(i, "Object", "Street");
         }
     }
 }
@@ -113,7 +208,7 @@ class FLEX_34852_VO
     {
         this.index = index;
         this.name = namePrefix + index;
-        this.address = new FLEX_34852_AddressVO(streetPrefix + index);
+        this.address = new FLEX_34852_AddressVO(streetPrefix + index, Math.floor(index), new Date(2000 + Math.floor(index), 0, 0, 0, 0, 0, 1));
     }
 }
 
@@ -122,8 +217,16 @@ class FLEX_34852_AddressVO
     [Bindable]
     public var street:String;
 
-    public function FLEX_34852_AddressVO(street:String)
+    [Bindable]
+    public var houseNumber:int;
+
+    [Bindable]
+    public var dateMovedIn:Date;
+
+    public function FLEX_34852_AddressVO(street:String, houseNumber:int, dateMovedIn:Date)
     {
         this.street = street;
+        this.houseNumber = houseNumber;
+        this.dateMovedIn = dateMovedIn;
     }
 }
\ No newline at end of file


[2/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Introducing ComplexSortField to specify that a sort field name is actually a chain of properties separated by a dot (e.g. "address.name"). This was necessary because, as Alex H pointed out, o

Posted by mi...@apache.org.
FLEX-34852
Introducing ComplexSortField to specify that a sort field name is actually a chain of properties separated by a dot (e.g. "address.name"). This was necessary because, as Alex H pointed out, one can add a property with a dot onto a dynamic object, and developers should still be able to sort by it using the existing algorithm.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/bf6d0693
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/bf6d0693
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/bf6d0693

Branch: refs/heads/develop
Commit: bf6d0693c842091a3e8f97c267e6ddad5ab7d940
Parents: 7cd1b3b
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 12:58:11 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 12:58:11 2015 +0200

----------------------------------------------------------------------
 .../src/mx/collections/ComplexSortField.as      | 37 ++++++++++++++++++++
 .../framework/tests/FLEX_34852_Tests.as         |  4 +--
 2 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/bf6d0693/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ComplexSortField.as b/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
new file mode 100644
index 0000000..6c9a27b
--- /dev/null
+++ b/frameworks/projects/framework/src/mx/collections/ComplexSortField.as
@@ -0,0 +1,37 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package mx.collections {
+    import mx.utils.ObjectUtil;
+
+    public class ComplexSortField extends SortField
+    {
+
+        private var _nameParts:Array;
+
+        public function ComplexSortField(name:String = null,
+                                         caseInsensitive:Boolean = false,
+                                         descending:Boolean = false,
+                                         numeric:Object = null)
+        {
+            super(name, caseInsensitive, descending, numeric);
+            _nameParts = name.split(".");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/bf6d0693/frameworks/projects/framework/tests/FLEX_34852_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
index 3a66221..4a9b1ee 100644
--- a/frameworks/projects/framework/tests/FLEX_34852_Tests.as
+++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
@@ -19,10 +19,10 @@
 
 package {
     import mx.collections.ArrayList;
+    import mx.collections.ComplexSortField;
     import mx.collections.IList;
     import mx.collections.ListCollectionView;
     import mx.collections.Sort;
-    import mx.collections.SortField;
 
     import org.flexunit.asserts.assertEquals;
 
@@ -49,7 +49,7 @@ package {
             _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
 
             const sortByIndexAscending:Sort = new Sort();
-            sortByIndexAscending.fields = [new SortField("address.street", false, false, false)];
+            sortByIndexAscending.fields = [new ComplexSortField("address.street", false, false, false)];
             _sut.sort = sortByIndexAscending;
 
             //when


[3/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Adding a (unit tested) method to ObjectUtil which will be used by ComplexSortField to retrieve the value of the property at the end of the specified property chain, which will then be used fo

Posted by mi...@apache.org.
FLEX-34852
Adding a (unit tested) method to ObjectUtil which will be used by ComplexSortField to retrieve the value of the property at the end of the specified property chain, which will then be used for sorting. If the value cannot be reached, the function returns undefined, so as to differentiate from a valid "null" value.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/649d811e
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/649d811e
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/649d811e

Branch: refs/heads/develop
Commit: 649d811e7930bdd0b11ad1d9b645f944d2b844d1
Parents: bf6d069
Author: Mihai Chira <mi...@apache.org>
Authored: Sun Jun 7 13:08:31 2015 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sun Jun 7 13:08:31 2015 +0200

----------------------------------------------------------------------
 .../framework/src/mx/utils/ObjectUtil.as        |  34 ++++-
 .../tests/ObjectUtil_FLEX_34852_Tests.as        | 127 +++++++++++++++++++
 2 files changed, 160 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/649d811e/frameworks/projects/framework/src/mx/utils/ObjectUtil.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/utils/ObjectUtil.as b/frameworks/projects/framework/src/mx/utils/ObjectUtil.as
index 2d6e7c2..791bbce 100644
--- a/frameworks/projects/framework/src/mx/utils/ObjectUtil.as
+++ b/frameworks/projects/framework/src/mx/utils/ObjectUtil.as
@@ -1199,7 +1199,39 @@ public class ObjectUtil
         }
         return true;
     }
-    
+
+    /**
+     *  Returns the value at the end of the property chain <code>path</code>.
+     *  If the value cannot be reached due to null links on the chain,
+     *  <code>undefined</code>  is returned.
+     *
+     *  @param obj The object at the beginning of the property chain
+     *  @param path The path to inspect (e.g. "address.street")
+     *
+     *  @return the value at the end of the property chain, <code>undefined</code>
+     *  if it cannot be reached, or the object itself when <code>path</code> is empty.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public static function getValue(obj:Object, path:Array):*
+    {
+        if(!obj)
+            return undefined;
+
+        if(!path || !path.length)
+            return obj;
+
+        var result:* = obj;
+        var i:int = -1;
+        while(++i < path.length && result)
+            result = result.hasOwnProperty(path[i]) ? result[path[i]] : undefined;
+
+        return result;
+    }
+
     /**
      *  @private
      */

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/649d811e/frameworks/projects/framework/tests/ObjectUtil_FLEX_34852_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/ObjectUtil_FLEX_34852_Tests.as b/frameworks/projects/framework/tests/ObjectUtil_FLEX_34852_Tests.as
new file mode 100644
index 0000000..13820ae
--- /dev/null
+++ b/frameworks/projects/framework/tests/ObjectUtil_FLEX_34852_Tests.as
@@ -0,0 +1,127 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package {
+    import mx.utils.ObjectUtil;
+
+    import org.flexunit.assertThat;
+
+    import org.flexunit.asserts.assertEquals;
+
+    public class ObjectUtil_FLEX_34852_Tests {
+        [Test]
+        public function test_getValue_for_two_field_path():void
+        {
+            //given
+            const streetPrefix:String = "Street no. ";
+            const index:int = 1;
+            var obj:ObjectUtil_FLEX_34852_VO = new ObjectUtil_FLEX_34852_VO(index, "SomeObject", streetPrefix);
+
+            //when
+            var streetName:String = ObjectUtil.getValue(obj, ["address", "street"]) as String;
+
+            //then
+            assertEquals(streetPrefix + index, streetName);
+        }
+
+        [Test]
+        public function test_getValue_for_one_field_path():void
+        {
+            //given
+            const streetPrefix:String = "Street no. ";
+            const index:int = 1;
+            var obj:ObjectUtil_FLEX_34852_VO = new ObjectUtil_FLEX_34852_VO(index, "SomeObject", streetPrefix);
+
+            //when
+            var result:* = ObjectUtil.getValue(obj, ["address"]);
+
+            //then
+            assertEquals(obj.address, result);
+        }
+
+        [Test]
+        public function test_getValue_for_zero_field_path_returns_parameter():void
+        {
+            //given
+            var obj:ObjectUtil_FLEX_34852_VO = new ObjectUtil_FLEX_34852_VO(1, "SomeObject", "Street no. ");
+
+            //when
+            var result:* = ObjectUtil.getValue(obj, null);
+
+            //then
+            assertEquals(obj, result);
+        }
+
+        [Test]
+        public function test_getValue_for_null_object_returns_undefined():void
+        {
+            //given
+            var obj:ObjectUtil_FLEX_34852_VO = null;
+
+            //when
+            var result:* = ObjectUtil.getValue(obj, ["address", "street"]);
+
+            //then
+            assertThat(result === undefined);
+        }
+
+        [Test]
+        public function test_getValue_for_wrong_path_returns_undefined():void
+        {
+            //given
+            var obj:ObjectUtil_FLEX_34852_VO = new ObjectUtil_FLEX_34852_VO(1, "SomeObject", "Street no. ");
+
+            //when
+            var result:* = ObjectUtil.getValue(obj, ["address", "name"]);
+
+            //then
+            assertThat(result === undefined);
+        }
+    }
+}
+
+class ObjectUtil_FLEX_34852_VO
+{
+    [Bindable]
+    public var name:String;
+
+    [Bindable]
+    public var address:ObjectUtil_FLEX_34852_AddressVO;
+
+    [Bindable]
+    public var index:Number;
+
+    public function ObjectUtil_FLEX_34852_VO(index:Number, namePrefix:String, streetPrefix:String)
+    {
+        this.index = index;
+        this.name = namePrefix + index;
+        this.address = new ObjectUtil_FLEX_34852_AddressVO(streetPrefix + index);
+    }
+}
+
+class ObjectUtil_FLEX_34852_AddressVO
+{
+    [Bindable]
+    public var street:String;
+
+    public function ObjectUtil_FLEX_34852_AddressVO(street:String)
+    {
+        this.street = street;
+    }
+}
\ No newline at end of file


Re: [1/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails

Posted by Mihai Chira <mi...@gmail.com>.
Great, thank you.

On 8 June 2015 at 05:44, piotrz <pi...@gmail.com> wrote:
> Done. :)
> From my experience 90% of VO objects which I have created was Bindable in
> 100%. Although if for some reason some at least one property wasn't bindable
> I was going that grained path as you Mihai. :)
>
> Thanks,
> Piotr
>
>
>
> -----
> Apache Flex PMC
> piotrzarzycki21@gmail.com
> --
> View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Re-1-8-git-commit-flex-sdk-refs-heads-develop-FLEX-34852-Added-unit-test-actually-moved-the-first-fus-tp47515p47520.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [1/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails

Posted by piotrz <pi...@gmail.com>.
Done. :)
>From my experience 90% of VO objects which I have created was Bindable in
100%. Although if for some reason some at least one property wasn't bindable
I was going that grained path as you Mihai. :)

Thanks,
Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Re-1-8-git-commit-flex-sdk-refs-heads-develop-FLEX-34852-Added-unit-test-actually-moved-the-first-fus-tp47515p47520.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [1/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails

Posted by Mihai Chira <mi...@gmail.com>.
Thanks for that, good idea. I think I usually like the fine-grained
choice of which property becomes bindable and which one doesn't, but
in this case, for a unit test, you might be right that it's more
expedient. Feel free to make the change if you wish. Cheers.

On 7 June 2015 at 18:33, Piotr Zarzycki <pi...@gmail.com> wrote:
> Hi Mihai,
>
> You could mark VO classes as Bindable and all properties will be
> automatically bindable.
>
> Piotr
>
> W dniu 2015-06-07 o 18:10, mihaic@apache.org pisze:
>
>> Repository: flex-sdk
>> Updated Branches:
>>    refs/heads/develop 11489c6e7 -> 94dd74615
>>
>>
>> FLEX-34852
>> Added unit test (actually moved the first function from
>> ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket).
>> Because the feature is not implemented, it currently fails.
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7cd1b3bc
>> Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7cd1b3bc
>> Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7cd1b3bc
>>
>> Branch: refs/heads/develop
>> Commit: 7cd1b3bc69f11c6c9d88a65e0df9eae39a17afa3
>> Parents: 11489c6
>> Author: Mihai Chira <mi...@apache.org>
>> Authored: Sun Jun 7 12:53:06 2015 +0200
>> Committer: Mihai Chira <mi...@apache.org>
>> Committed: Sun Jun 7 12:53:06 2015 +0200
>>
>> ----------------------------------------------------------------------
>>   .../framework/tests/FLEX_34852_Tests.as         | 129
>> +++++++++++++++++++
>>   .../ListCollectionView_FLEX_34837_Tests.as      |  18 ---
>>   2 files changed, 129 insertions(+), 18 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/FLEX_34852_Tests.as
>> ----------------------------------------------------------------------
>> diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as
>> b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
>> new file mode 100644
>> index 0000000..3a66221
>> --- /dev/null
>> +++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
>> @@ -0,0 +1,129 @@
>>
>> +////////////////////////////////////////////////////////////////////////////////
>> +//
>> +//  Licensed to the Apache Software Foundation (ASF) under one or more
>> +//  contributor license agreements.  See the NOTICE file distributed with
>> +//  this work for additional information regarding copyright ownership.
>> +//  The ASF licenses this file to You under the Apache License, Version
>> 2.0
>> +//  (the "License"); you may not use this file except in compliance with
>> +//  the License.  You may obtain a copy of the License at
>> +//
>> +//      http://www.apache.org/licenses/LICENSE-2.0
>> +//
>> +//  Unless required by applicable law or agreed to in writing, software
>> +//  distributed under the License is distributed on an "AS IS" BASIS,
>> +//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>> implied.
>> +//  See the License for the specific language governing permissions and
>> +//  limitations under the License.
>> +//
>>
>> +////////////////////////////////////////////////////////////////////////////////
>> +
>> +package {
>> +    import mx.collections.ArrayList;
>> +    import mx.collections.IList;
>> +    import mx.collections.ListCollectionView;
>> +    import mx.collections.Sort;
>> +    import mx.collections.SortField;
>> +
>> +    import org.flexunit.asserts.assertEquals;
>> +
>> +    public class FLEX_34852_Tests {
>> +        private var _sut:ListCollectionView;
>> +
>> +        [Before]
>> +        public function setUp():void
>> +        {
>> +            _sut = new ListCollectionView(new ArrayList());
>> +        }
>> +
>> +        [After]
>> +        public function tearDown():void
>> +        {
>> +            _sut = null;
>> +        }
>> +
>> +        [Test]
>> +        public function
>> test_simple_ascending_sort_by_complex_fields():void
>> +        {
>> +            //given
>> +            var from4To0:IList = generateVOs(5, true);
>> +            _sut.addAll(from4To0); //values["address.street"]: Street4,
>> Street3, Street2, Street1, Street0
>> +
>> +            const sortByIndexAscending:Sort = new Sort();
>> +            sortByIndexAscending.fields = [new
>> SortField("address.street", false, false, false)];
>> +            _sut.sort = sortByIndexAscending;
>> +
>> +            //when
>> +            _sut.refresh(); //should be: Street0, Street1, Street2,
>> Street3, Street4
>> +
>> +            //then
>> +            assertIndexesAre([0, 1, 2, 3, 4]);
>> +        }
>> +
>> +
>> +
>> +        private function assertIndexesAre(indexes:Array):void
>> +        {
>> +            assertEquals(indexes.length, _sut.length);
>> +
>> +            for(var i:int = 0; i < _sut.length; i++)
>> +            {
>> +                assertEquals(FLEX_34852_VO(_sut.getItemAt(i)).index,
>> indexes[i]);
>> +            }
>> +        }
>> +
>> +
>> +        private static function generateVOs(no:int, reverse:Boolean =
>> false):IList
>> +        {
>> +            return generateObjects(no, reverse, generateOneObject);
>> +        }
>> +
>> +        private static function generateObjects(no:int, reverse:Boolean,
>> generator:Function):IList
>> +        {
>> +            var result:Array = [];
>> +            for(var i:int = 0; i < no; i++)
>> +            {
>> +                result.push(generator(i));
>> +            }
>> +
>> +            if(reverse)
>> +                result.reverse();
>> +
>> +            return new ArrayList(result);
>> +        }
>> +
>> +        private static function generateOneObject(i:Number):FLEX_34852_VO
>> +        {
>> +            return new FLEX_34852_VO(i, "Object"+i, "Street"+i);
>> +        }
>> +    }
>> +}
>> +
>> +class FLEX_34852_VO
>> +{
>> +    [Bindable]
>> +    public var name:String;
>> +
>> +    [Bindable]
>> +    public var address:FLEX_34852_AddressVO;
>> +
>> +    [Bindable]
>> +    public var index:Number;
>> +
>> +    public function FLEX_34852_VO(index:Number, namePrefix:String,
>> streetPrefix:String)
>> +    {
>> +        this.index = index;
>> +        this.name = namePrefix + index;
>> +        this.address = new FLEX_34852_AddressVO(streetPrefix + index);
>> +    }
>> +}
>> +
>> +class FLEX_34852_AddressVO
>> +{
>> +    [Bindable]
>> +    public var street:String;
>> +
>> +    public function FLEX_34852_AddressVO(street:String)
>> +    {
>> +        this.street = street;
>> +    }
>> +}
>> \ No newline at end of file
>>
>>
>> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
>> ----------------------------------------------------------------------
>> diff --git
>> a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
>> b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
>> index f11e906..ae8f746 100644
>> ---
>> a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
>> +++
>> b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
>> @@ -43,24 +43,6 @@ package {
>>           }
>>             [Test]
>> -        public function
>> test_simple_ascending_sort_by_complex_fields():void
>> -        {
>> -            //given
>> -            var from4To0:IList = generateVOs(5, true);
>> -            _sut.addAll(from4To0); //values["address.street"]: Street4,
>> Street3, Street2, Street1, Street0
>> -
>> -            const sortByIndexAscending:Sort = new Sort();
>> -            sortByIndexAscending.fields = [new
>> SortField("address.street", false, false, false)];
>> -            _sut.sort = sortByIndexAscending;
>> -
>> -            //when
>> -            _sut.refresh(); //should be: Street0, Street1, Street2,
>> Street3, Street4
>> -
>> -            //then
>> -            assertIndexesAre([0, 1, 2, 3, 4]);
>> -        }
>> -
>> -        [Test]
>>           public function
>> test_simple_sort_by_complex_fields_with_custom_compare_function_for_sort():void
>>           {
>>               function compareByStreet(a:ListCollectionView_FLEX_34837_VO,
>> b:ListCollectionView_FLEX_34837_VO, fields:Array):int
>>
>

Re: [1/8] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails

Posted by Piotr Zarzycki <pi...@gmail.com>.
Hi Mihai,

You could mark VO classes as Bindable and all properties will be 
automatically bindable.

Piotr

W dniu 2015-06-07 o 18:10, mihaic@apache.org pisze:
> Repository: flex-sdk
> Updated Branches:
>    refs/heads/develop 11489c6e7 -> 94dd74615
>
>
> FLEX-34852
> Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7cd1b3bc
> Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7cd1b3bc
> Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7cd1b3bc
>
> Branch: refs/heads/develop
> Commit: 7cd1b3bc69f11c6c9d88a65e0df9eae39a17afa3
> Parents: 11489c6
> Author: Mihai Chira <mi...@apache.org>
> Authored: Sun Jun 7 12:53:06 2015 +0200
> Committer: Mihai Chira <mi...@apache.org>
> Committed: Sun Jun 7 12:53:06 2015 +0200
>
> ----------------------------------------------------------------------
>   .../framework/tests/FLEX_34852_Tests.as         | 129 +++++++++++++++++++
>   .../ListCollectionView_FLEX_34837_Tests.as      |  18 ---
>   2 files changed, 129 insertions(+), 18 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/FLEX_34852_Tests.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
> new file mode 100644
> index 0000000..3a66221
> --- /dev/null
> +++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as
> @@ -0,0 +1,129 @@
> +////////////////////////////////////////////////////////////////////////////////
> +//
> +//  Licensed to the Apache Software Foundation (ASF) under one or more
> +//  contributor license agreements.  See the NOTICE file distributed with
> +//  this work for additional information regarding copyright ownership.
> +//  The ASF licenses this file to You under the Apache License, Version 2.0
> +//  (the "License"); you may not use this file except in compliance with
> +//  the License.  You may obtain a copy of the License at
> +//
> +//      http://www.apache.org/licenses/LICENSE-2.0
> +//
> +//  Unless required by applicable law or agreed to in writing, software
> +//  distributed under the License is distributed on an "AS IS" BASIS,
> +//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +//  See the License for the specific language governing permissions and
> +//  limitations under the License.
> +//
> +////////////////////////////////////////////////////////////////////////////////
> +
> +package {
> +    import mx.collections.ArrayList;
> +    import mx.collections.IList;
> +    import mx.collections.ListCollectionView;
> +    import mx.collections.Sort;
> +    import mx.collections.SortField;
> +
> +    import org.flexunit.asserts.assertEquals;
> +
> +    public class FLEX_34852_Tests {
> +        private var _sut:ListCollectionView;
> +
> +        [Before]
> +        public function setUp():void
> +        {
> +            _sut = new ListCollectionView(new ArrayList());
> +        }
> +
> +        [After]
> +        public function tearDown():void
> +        {
> +            _sut = null;
> +        }
> +
> +        [Test]
> +        public function test_simple_ascending_sort_by_complex_fields():void
> +        {
> +            //given
> +            var from4To0:IList = generateVOs(5, true);
> +            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
> +
> +            const sortByIndexAscending:Sort = new Sort();
> +            sortByIndexAscending.fields = [new SortField("address.street", false, false, false)];
> +            _sut.sort = sortByIndexAscending;
> +
> +            //when
> +            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
> +
> +            //then
> +            assertIndexesAre([0, 1, 2, 3, 4]);
> +        }
> +
> +
> +
> +        private function assertIndexesAre(indexes:Array):void
> +        {
> +            assertEquals(indexes.length, _sut.length);
> +
> +            for(var i:int = 0; i < _sut.length; i++)
> +            {
> +                assertEquals(FLEX_34852_VO(_sut.getItemAt(i)).index, indexes[i]);
> +            }
> +        }
> +
> +
> +        private static function generateVOs(no:int, reverse:Boolean = false):IList
> +        {
> +            return generateObjects(no, reverse, generateOneObject);
> +        }
> +
> +        private static function generateObjects(no:int, reverse:Boolean, generator:Function):IList
> +        {
> +            var result:Array = [];
> +            for(var i:int = 0; i < no; i++)
> +            {
> +                result.push(generator(i));
> +            }
> +
> +            if(reverse)
> +                result.reverse();
> +
> +            return new ArrayList(result);
> +        }
> +
> +        private static function generateOneObject(i:Number):FLEX_34852_VO
> +        {
> +            return new FLEX_34852_VO(i, "Object"+i, "Street"+i);
> +        }
> +    }
> +}
> +
> +class FLEX_34852_VO
> +{
> +    [Bindable]
> +    public var name:String;
> +
> +    [Bindable]
> +    public var address:FLEX_34852_AddressVO;
> +
> +    [Bindable]
> +    public var index:Number;
> +
> +    public function FLEX_34852_VO(index:Number, namePrefix:String, streetPrefix:String)
> +    {
> +        this.index = index;
> +        this.name = namePrefix + index;
> +        this.address = new FLEX_34852_AddressVO(streetPrefix + index);
> +    }
> +}
> +
> +class FLEX_34852_AddressVO
> +{
> +    [Bindable]
> +    public var street:String;
> +
> +    public function FLEX_34852_AddressVO(street:String)
> +    {
> +        this.street = street;
> +    }
> +}
> \ No newline at end of file
>
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
> index f11e906..ae8f746 100644
> --- a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
> +++ b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
> @@ -43,24 +43,6 @@ package {
>           }
>   
>           [Test]
> -        public function test_simple_ascending_sort_by_complex_fields():void
> -        {
> -            //given
> -            var from4To0:IList = generateVOs(5, true);
> -            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2, Street1, Street0
> -
> -            const sortByIndexAscending:Sort = new Sort();
> -            sortByIndexAscending.fields = [new SortField("address.street", false, false, false)];
> -            _sut.sort = sortByIndexAscending;
> -
> -            //when
> -            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
> -
> -            //then
> -            assertIndexesAre([0, 1, 2, 3, 4]);
> -        }
> -
> -        [Test]
>           public function test_simple_sort_by_complex_fields_with_custom_compare_function_for_sort():void
>           {
>               function compareByStreet(a:ListCollectionView_FLEX_34837_VO, b:ListCollectionView_FLEX_34837_VO, fields:Array):int
>