예제 #1
0
        public void Ctor_SortKeys(bool critical)
        {
            SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) };
            var       control  = new SortRequestControl(sortKeys);

            Assert.True(control.IsCritical);
            Assert.True(control.ServerSide);
            Assert.Equal("1.2.840.113556.1.4.473", control.Type);

            Assert.NotSame(sortKeys, control.SortKeys);
            for (int i = 0; i < sortKeys.Length; i++)
            {
                Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName);
                Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule);
                Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder);
            }

            control.IsCritical = critical;
            var expected = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ?
                           // WLDAP formatted ASN.1
                           new byte[] { 48, 132, 0, 0, 0, 43, 48, 132, 0, 0, 0, 17, 4, 5, 110,
                                        97, 109, 101, 49, 128, 5, 114, 117, 108, 101, 49, 129,
                                        1, 255, 48, 132, 0, 0, 0, 14, 4, 5, 110, 97, 109, 101,
                                        50, 128, 5, 114, 117, 108, 101, 50 } :
            // OpenLdap formatted ASN.1
            new byte[] { 48, 35, 48, 17, 4, 5, 110, 97, 109, 101, 49, 128, 5,
                         114, 117, 108, 101, 49, 129, 1, 255, 48, 14, 4, 5, 110, 97, 109,
                         101, 50, 128, 5, 114, 117, 108, 101, 50 };

            Assert.Equal(expected, control.GetValue());
        }
예제 #2
0
        public void Compare_secondnull_throws()
        {
            byte[]  keyData = new byte[] { 0xae, 0x1, 0x20, 0x1 };
            SortKey sortKey = Collator.CreateSortKey("heo", keyData);

            Assert.Throws <ArgumentNullException>(() => SortKey.Compare(sortKey, null));
        }
예제 #3
0
        public SortKey GetResultAndReset()
        {
            SortKey ret = GetResult();

            Reset();
            return(ret);
        }
예제 #4
0
        private protected void DrawSortableHeaders()
        {
            var     anyClicked  = false;
            SortKey previousKey = _sortKey;

            if (SettingsHelper.DrawTableHeader(NameHeaderRect, NameHeaderTextRect, _nameHeaderText))
            {
                _sortKey   = SortKey.Name;
                anyClicked = true;
            }

            if (SettingsHelper.DrawTableHeader(PriceHeaderRect, PriceHeaderTextRect, _priceHeaderText))
            {
                _sortKey   = SortKey.Price;
                anyClicked = true;
            }

            if (SettingsHelper.DrawTableHeader(CategoryHeaderRect, CategoryHeaderTextRect, _categoryHeaderText))
            {
                _sortKey   = SortKey.Category;
                anyClicked = true;
            }

            if (_sortKey != previousKey)
            {
                _sortOrder = SortOrder.Descending;
                NotifySortRequested();
            }
            else if (anyClicked)
            {
                InvertSortOrder();
                NotifySortRequested();
            }
        }
예제 #5
0
        public void SortKeyTest(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expectedSign)
        {
            SortKey sk1 = compareInfo.GetSortKey(string1, options);
            SortKey sk2 = compareInfo.GetSortKey(string2, options);

            Assert.Equal(expectedSign, Math.Sign(SortKey.Compare(sk1, sk2)));
            Assert.Equal(expectedSign == 0, sk1.Equals(sk2));

            if (!WindowsVersionHasTheCompareStringRegression)
            {
                Assert.Equal(Math.Sign(compareInfo.Compare(string1, string2, options)), Math.Sign(SortKey.Compare(sk1, sk2)));
            }

            Assert.Equal(compareInfo.GetHashCode(string1, options), sk1.GetHashCode());
            Assert.Equal(compareInfo.GetHashCode(string2, options), sk2.GetHashCode());

            Assert.Equal(string1, sk1.OriginalString);
            Assert.Equal(string2, sk2.OriginalString);

            // Now try the span-based versions - use BoundedMemory to detect buffer overruns

            RunSpanSortKeyTest(compareInfo, string1, options, sk1.KeyData);
            RunSpanSortKeyTest(compareInfo, string2, options, sk2.KeyData);

            unsafe static void RunSpanSortKeyTest(CompareInfo compareInfo, ReadOnlySpan <char> source, CompareOptions options, byte[] expectedSortKey)
예제 #6
0
        public void SetParameters(
            AmazonDynamoDBClient client,
            SelectQueryInfo queryInfo,
            ExpressionAttributeName[] expressionAttributeNames,
            ExpressionAttributeValue[] expressionAttributeValues,
            HashKey hashKey,
            SortKey sortKey,
            string hashKeyName,
            string sortKeyName,
            string tableName,
            string indexName,
            string filterExpression
            )
        {
            Client    = client;
            QueryInfo = queryInfo;
            ExpressionAttributeNames  = expressionAttributeNames;
            ExpressionAttributeValues = expressionAttributeValues;
            HashKey          = hashKey;
            SortKey          = sortKey;
            HashKeyName      = hashKeyName;
            SortKeyName      = sortKeyName;
            TableName        = tableName;
            IndexName        = indexName;
            FilterExpression = filterExpression;

            Initialize();
        }
예제 #7
0
 private void ChangeSortKey(SortKey sortKey)
 {
     CurrentSortKey = sortKey;
     InitializeSortIcon(sortKey);
     ShipModel[] sortedModels = DeckUtil.GetSortedList(new List <ShipModel>(mShipModels), sortKey).ToArray();
     OnSortedShips(sortedModels);
 }
예제 #8
0
    private void InitializeSortIcon(SortKey sortKey)
    {
        switch (sortKey)
        {
        case SortKey.LEVEL_LOCK:
        case SortKey.LOCK_LEVEL:
            break;

        case SortKey.DAMAGE:
            mSpriteStatus.spriteName = "sort_crane";
            break;

        case SortKey.LEVEL:
            mSpriteStatus.spriteName = "sort_lv";
            break;

        case SortKey.NEW:
            mSpriteStatus.spriteName = "sort_new";
            break;

        case SortKey.SHIPTYPE:
            mSpriteStatus.spriteName = "sort_ship";
            break;

        case SortKey.UNORGANIZED:
            mSpriteStatus.spriteName = "sort_flag";
            break;
        }
    }
예제 #9
0
        public void SortKeyMiscTest()
        {
            CompareInfo ci = new CultureInfo("en-US").CompareInfo;
            string      s1 = "abc";
            string      s2 = "ABC";

            SortKey sk1 = ci.GetSortKey(s1);
            SortKey sk2 = ci.GetSortKey(s1);

            SortKey sk3 = ci.GetSortKey(s2);
            SortKey sk4 = ci.GetSortKey(s2, CompareOptions.IgnoreCase);
            SortKey sk5 = ci.GetSortKey(s1, CompareOptions.IgnoreCase);

            Assert.Equal(sk2, sk1);
            Assert.Equal(sk2.GetHashCode(), sk1.GetHashCode());
            Assert.Equal(sk2.KeyData, sk1.KeyData);

            Assert.NotEqual(sk3, sk1);
            Assert.NotEqual(sk3.GetHashCode(), sk1.GetHashCode());
            Assert.NotEqual(sk3.KeyData, sk1.KeyData);

            Assert.NotEqual(sk4, sk3);
            Assert.NotEqual(sk4.GetHashCode(), sk3.GetHashCode());
            Assert.NotEqual(sk4.KeyData, sk3.KeyData);

            Assert.Equal(sk4, sk5);
            Assert.Equal(sk4.GetHashCode(), sk5.GetHashCode());
            Assert.Equal(sk4.KeyData, sk5.KeyData);

            Assert.False(sk1.Equals(null));
            Assert.True(sk1.Equals(sk1));

            AssertExtensions.Throws <ArgumentNullException>("source", () => ci.GetSortKey(null));
            AssertExtensions.Throws <ArgumentException>("options", () => ci.GetSortKey(s1, CompareOptions.Ordinal));
        }
예제 #10
0
        /// <summary>
        /// Creates a SortKey with the given string and keyData
        /// </summary>
        /// <param name="originalString">String to use</param>
        /// <param name="keyData">Data of the SortKey</param>
        /// <param name="keyDataLength">Length to use from keyData</param>
        static public SortKey CreateSortKey(string originalString, byte[] keyData, int keyDataLength)
        {
            if (originalString == null)
            {
                throw new ArgumentNullException("originalString");
            }
            if (keyData == null)
            {
                throw new ArgumentNullException("keyData");
            }
            if (0 > keyDataLength || keyDataLength > keyData.Length)
            {
                throw new ArgumentOutOfRangeException("keyDataLength");
            }

            CompareOptions options = CompareOptions.None;

#if NETSTANDARD1_6
            SortKey sortKey = new SortKey(CultureInfo.InvariantCulture.Name, originalString, options, keyData);
#else
            SortKey sortKey = CultureInfo.InvariantCulture.CompareInfo.GetSortKey(string.Empty, options);
            SetInternalOriginalStringField(sortKey, originalString);
            SetInternalKeyDataField(sortKey, keyData, keyDataLength);
#endif

            return(sortKey);
        }
예제 #11
0
        //https://docs.microsoft.com/en-us/globalization/locale/sorting-and-string-comparison
        public static bool IsInAlphabeticalOrder(IList <string> list, string cultureCode, out string message)
        {
            var compareInfo = CultureInfo.GetCultureInfo(cultureCode).CompareInfo;

            message = null;
            var current = list.First();

            foreach (var item in list.Skip(1))
            {
                var next   = item;
                var sc1    = compareInfo.GetSortKey(current);
                var sc2    = compareInfo.GetSortKey(next);
                var result = SortKey.Compare(sc1, sc2);

                if (result > 0)
                {
                    message = $"Alphabetical order problem: '{next}' is before than '{current}'";
                    return(false);
                }

                current = next;
            }

            return(true);
        }
예제 #12
0
    public static void Main()
    {
        CompareInfo cmpi       = null;
        SortKey     sk1        = null;
        SortKey     sk2        = null;
        string      s          = "ABC";
        string      ignoreCase = "Ignore case";
        string      useCase    = "Use case   ";

// Get a CompareInfo object for the English-Great Britain culture.
        cmpi = CompareInfo.GetCompareInfo("en-GB");

// Get a sort key that ignores case for the specified string.
        sk1 = cmpi.GetSortKey(s, CompareOptions.IgnoreCase);
// Get a sort key with no compare option for the specified string.
        sk2 = cmpi.GetSortKey(s);

// Display the original string.
        Console.WriteLine("Original string: \"{0}\"", sk1.OriginalString);
        Console.WriteLine();

// Display the the string equivalent of the two sort keys.
        Console.WriteLine("CompareInfo (culture) name: {0}", cmpi.Name);
        Console.WriteLine("ToString - {0}: \"{1}\"", ignoreCase, sk1.ToString());
        Console.WriteLine("ToString - {0}: \"{1}\"", useCase, sk2.ToString());
        Console.WriteLine();

// Display the key data of the two sort keys.
        DisplayKeyData(sk1, ignoreCase);
        DisplayKeyData(sk2, useCase);
    }
예제 #13
0
        public void Compare_secondnull_throws()
        {
            byte[]  keyData = new byte[] { 0xae, 0x1, 0x20, 0x1 };
            SortKey sortKey = Collator.CreateSortKey("heo", keyData);

            SortKey.Compare(sortKey, null);
        }
예제 #14
0
        public SortKey GetResultAndReset()
        {
            SortKey result = this.GetResult();

            this.Reset();
            return(result);
        }
예제 #15
0
        internal void SortNewNodeSet(Processor proc, ArrayList sortarray)
        {
            Debug.Assert(0 < sortarray.Count);
            int numSorts = sortarray.Count;
            XPathSortComparer comparer = new XPathSortComparer(numSorts);

            for (int i = 0; i < numSorts; i++)
            {
                Sort  sort = (Sort)sortarray[i];
                Query expr = proc.GetCompiledQuery(sort.select);

                comparer.AddSort(expr, new XPathComparerHelper(sort.order, sort.caseOrder, sort.lang, sort.dataType));
            }
            List <SortKey> results = new List <SortKey>();

            Debug.Assert(proc.ActionStack.Peek() == this, "the trick we are doing with proc.Current will work only if this is topmost frame");

            while (NewNextNode(proc))
            {
                XPathNodeIterator savedNodeset = _nodeSet;
                _nodeSet = _newNodeSet;              // trick proc.Current node

                SortKey key = new SortKey(numSorts, /*originalPosition:*/ results.Count, _newNodeSet.Current.Clone());

                for (int j = 0; j < numSorts; j++)
                {
                    key[j] = comparer.Expression(j).Evaluate(_newNodeSet);
                }
                results.Add(key);

                _nodeSet = savedNodeset;                 // restore proc.Current node
            }
            results.Sort(comparer);
            _newNodeSet = new XPathSortArrayIterator(results);
        }
예제 #16
0
        public void Compare_firstnull_throws()
        {
            byte[]  keyData = new byte[] { 0xae, 0x1, 0x20, 0x1 };
            SortKey sortKey = Collator.CreateSortKey("heo", keyData);

            SortKey.Compare(null, sortKey);
        }
예제 #17
0
        public SortKey GetSortKey(string source)
        {
#if NET461
            return(_collator.GetSortKey(source));
#elif NETSTANDARD2_0
            Icu.SortKey icuSortKey = _collator.GetSortKey(source);
            SortKey     sortKey = CultureInfo.InvariantCulture.CompareInfo.GetSortKey(string.Empty, CompareOptions.None);
            string      keyDataFieldName, origStringFieldName;
            if (Platform.IsDotNetFramework)
            {
                keyDataFieldName    = "m_KeyData";
                origStringFieldName = "m_String";
            }
            else if (Platform.IsDotNetCore)
            {
                keyDataFieldName    = "_keyData";
                origStringFieldName = "_string";
            }
            else if (Platform.IsMono)
            {
                keyDataFieldName    = "key";
                origStringFieldName = "source";
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            SetInternalFieldForPublicProperty(sortKey, "SortKey.KeyData", keyDataFieldName, icuSortKey.KeyData);
            SetInternalFieldForPublicProperty(sortKey, "SortKey.OriginalString", origStringFieldName,
                                              icuSortKey.OriginalString);
            return(sortKey);
#endif
        }
예제 #18
0
파일: XmlSortKey.cs 프로젝트: z77ma/runtime
        public override int CompareTo(object obj)
        {
            XmlStringSortKey that = obj as XmlStringSortKey;
            int idx, cntCmp, result;

            if (that == null)
            {
                return(CompareToEmpty(obj));
            }

            // Compare either using SortKey.Compare or byte arrays
            if (_sortKey != null)
            {
                Debug.Assert(that._sortKey != null, "Both keys must have non-null sortKey field");
                result = SortKey.Compare(_sortKey, that._sortKey);
            }
            else
            {
                Debug.Assert(_sortKeyBytes != null && that._sortKeyBytes != null, "Both keys must have non-null sortKeyBytes field");

                cntCmp = (_sortKeyBytes.Length < that._sortKeyBytes.Length) ? _sortKeyBytes.Length : that._sortKeyBytes.Length;
                for (idx = 0; idx < cntCmp; idx++)
                {
                    if (_sortKeyBytes[idx] < that._sortKeyBytes[idx])
                    {
                        result = -1;
                        goto Done;
                    }

                    if (_sortKeyBytes[idx] > that._sortKeyBytes[idx])
                    {
                        result = 1;
                        goto Done;
                    }
                }

                // So far, keys are equal, so now test length of each key
                if (_sortKeyBytes.Length < that._sortKeyBytes.Length)
                {
                    result = -1;
                }
                else if (_sortKeyBytes.Length > that._sortKeyBytes.Length)
                {
                    result = 1;
                }
                else
                {
                    result = 0;
                }
            }

Done:
            // Use document order to break sorting tie
            if (result == 0)
            {
                return(BreakSortingTie(that));
            }

            return(_descendingOrder ? -result : result);
        }
 public override void SetStringValue(string value)
 {
     key          = collator.GetSortKey(value);
     bytes.Bytes  = key.KeyData;
     bytes.Offset = 0;
     bytes.Length = key.KeyData.Length;
 }
예제 #20
0
        public void Ctor_SortKeys(bool critical)
        {
            SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) };
            var       control  = new SortRequestControl(sortKeys);

            Assert.True(control.IsCritical);
            Assert.True(control.ServerSide);
            Assert.Equal("1.2.840.113556.1.4.473", control.Type);

            Assert.NotSame(sortKeys, control.SortKeys);
            for (int i = 0; i < sortKeys.Length; i++)
            {
                Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName);
                Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule);
                Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder);
            }

            control.IsCritical = critical;
            Assert.Equal(new byte[]
            {
                0x30, 0x23, 0x30, 0x11, 0x04, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x31, 0x80, 0x05, 0x72, 0x75,
                0x6C, 0x65, 0x31, 0x81, 0x01, 0xFF, 0x30, 0x0E, 0x04, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32,
                0x80, 0x05, 0x72, 0x75, 0x6C, 0x65, 0x32
            }, control.GetValue());
        }
예제 #21
0
        public override unsafe void GenerateSortKey(RenderView renderView, RenderViewStage renderViewStage, SortKey* sortKeys)
        {
            Matrix viewInverse = renderView.View;
            viewInverse.Invert();
            var plane = new Plane(viewInverse.Forward, Vector3.Dot(viewInverse.TranslationVector, viewInverse.Forward)); // TODO: Point-normal-constructor seems wrong. Check.

            var renderNodes = renderViewStage.RenderNodes;

            int distanceShift = 32 - distancePrecision;
            int stateShift = 32 - statePrecision;

            for (int i = 0; i < renderNodes.Count; ++i)
            {
                var renderNode = renderNodes[i];

                var renderObject = renderNode.RenderObject;
                var distance = CollisionHelper.DistancePlanePoint(ref plane, ref renderObject.BoundingBox.Center);
                var distanceI = ComputeDistance(distance);
                if (reverseDistance)
                    distanceI = ~distanceI;

                // Compute sort key
                sortKeys[i] = new SortKey { Value = ((ulong)renderNode.RootRenderFeature.SortKey << 56) | ((ulong)(distanceI >> distanceShift) << distancePosition) | ((ulong)(renderObject.StateSortKey >> stateShift) << statePosition), Index = i };
            }
        }
예제 #22
0
 public void AddSort(string attributeName, bool descending)
 {
     _sortKey = new SortKey {
         AttributeName = attributeName, ReverseOrder = descending
     };
     _sortKeys.Add(_sortKey);
 }
예제 #23
0
        public void Ctor_SortKeys(bool critical)
        {
            SortKey[] sortKeys = new SortKey[] { new SortKey("name1", "rule1", true), new SortKey("name2", "rule2", false) };
            var       control  = new SortRequestControl(sortKeys);

            Assert.True(control.IsCritical);
            Assert.True(control.ServerSide);
            Assert.Equal("1.2.840.113556.1.4.473", control.Type);

            Assert.NotSame(sortKeys, control.SortKeys);
            for (int i = 0; i < sortKeys.Length; i++)
            {
                Assert.Equal(sortKeys[i].AttributeName, control.SortKeys[i].AttributeName);
                Assert.Equal(sortKeys[i].MatchingRule, control.SortKeys[i].MatchingRule);
                Assert.Equal(sortKeys[i].ReverseOrder, control.SortKeys[i].ReverseOrder);
            }

            control.IsCritical = critical;
            Assert.Equal(new byte[]
            {
                48, 132, 0, 0, 0, 43, 48, 132, 0, 0, 0, 17, 4, 5, 110,
                97, 109, 101, 49, 128, 5, 114, 117, 108, 101, 49, 129,
                1, 255, 48, 132, 0, 0, 0, 14, 4, 5, 110, 97, 109, 101,
                50, 128, 5, 114, 117, 108, 101, 50
            }, control.GetValue());
        }
예제 #24
0
        public static List <ShipModel> GetSortedList(List <ShipModel> ships, SortKey sort_key)
        {
            List <ShipModel> range = ships.GetRange(0, ships.Count);

            switch (sort_key)
            {
            case SortKey.LEVEL:
                range.Sort((ShipModel a, ShipModel b) => _CompLevel(a, b));
                break;

            case SortKey.SHIPTYPE:
                range.Sort((ShipModel a, ShipModel b) => _CompSType(a, b));
                break;

            case SortKey.DAMAGE:
                range.Sort((ShipModel a, ShipModel b) => _CompDamage(a, b));
                break;

            case SortKey.NEW:
                range.Sort((ShipModel a, ShipModel b) => __CompGetNo(a, b) * -1);
                break;

            case SortKey.LEVEL_LOCK:
                range.Sort((ShipModel a, ShipModel b) => _CompLevelLock(a, b));
                break;

            case SortKey.LOCK_LEVEL:
                range.Sort((ShipModel a, ShipModel b) => _CompLockLevel(a, b));
                break;

            case SortKey.UNORGANIZED:
            {
                Dictionary <int, int> o_map = new Dictionary <int, int>();
                for (int i = 1; i <= 8; i++)
                {
                    if (Comm_UserDatas.Instance.User_deck.TryGetValue(i, out Mem_deck value))
                    {
                        for (int j = 0; j < value.Ship.Count(); j++)
                        {
                            o_map.Add(value.Ship[j], i * 10 + j);
                        }
                    }
                }
                for (int k = 1; k <= 17; k++)
                {
                    if (Comm_UserDatas.Instance.User_EscortDeck.TryGetValue(k, out Mem_esccort_deck value2))
                    {
                        for (int l = 0; l < value2.Ship.Count(); l++)
                        {
                            o_map.Add(value2.Ship[l], k * 100 + l);
                        }
                    }
                }
                range.Sort((ShipModel a, ShipModel b) => _CompUnOrganize(a, b, o_map));
                break;
            }
            }
            return(range);
        }
예제 #25
0
    public int Compare(string str1, string str2)
    {
        SortKey sk1, sk2;

        sk1 = CultureInfo.CurrentCulture.CompareInfo.GetSortKey(str1);
        sk2 = CultureInfo.CurrentCulture.CompareInfo.GetSortKey(str2);
        return(SortKey.Compare(sk1, sk2));
    }
예제 #26
0
        public void Compare_keyDataSame_same()
        {
            byte[]  keyData  = new byte[] { 0xae, 0x1, 0x20, 0x1 };
            SortKey sortKey1 = Collator.CreateSortKey("heo", keyData);
            SortKey sortKey2 = Collator.CreateSortKey("heol", keyData);

            Assert.AreEqual(Same, SortKey.Compare(sortKey1, sortKey2));
        }
예제 #27
0
        public void Ctor_Default()
        {
            var sortKey = new SortKey();

            Assert.Null(sortKey.AttributeName);
            Assert.Null(sortKey.MatchingRule);
            Assert.False(sortKey.ReverseOrder);
        }
예제 #28
0
        public void Ctor_AttributeName_MatchingRule_ReverseOrder(string attributeName, string matchingRule, bool reverseOrder)
        {
            var sortKey = new SortKey(attributeName, matchingRule, reverseOrder);

            Assert.Equal(attributeName, sortKey.AttributeName);
            Assert.Equal(matchingRule, sortKey.MatchingRule);
            Assert.Equal(reverseOrder, sortKey.ReverseOrder);
        }
예제 #29
0
        public void MatchingRule_Set_GetReturnsExpected()
        {
            var sortKey = new SortKey {
                MatchingRule = "MatchingRule"
            };

            Assert.Equal("MatchingRule", sortKey.MatchingRule);
        }
예제 #30
0
        public void ReverseOrder_Set_GetReturnsExpected()
        {
            var sortKey = new SortKey {
                ReverseOrder = true
            };

            Assert.True(sortKey.ReverseOrder);
        }
예제 #31
0
 public void SortOn(SortKey key)
 {
     if (_sortKeys.Remove(key))
     {
         _invertOrder[key] = _invertClassOrder = !_invertOrder[key];
     }
     _sortKeys.Insert(0, key);
 }
예제 #32
0
        public DerpAttack(double x, double y, int dir)
        {
            this.x = x;
            this.y = y;
            this.dir = dir;

            key = new SortKey(y);

            graphic = textures["small-close"];
            graphicInfo = textureInfo["small-close"];

            lastTick = DateTime.Now;
        }
 private void BuildResultsList()
 {
     XPathNavigator navigator;
     int numSorts = this.comparer.NumSorts;
     while ((navigator = this.qyInput.Advance()) != null)
     {
         SortKey item = new SortKey(numSorts, this.results.Count, navigator.Clone());
         for (int i = 0; i < numSorts; i++)
         {
             item[i] = this.comparer.Expression(i).Evaluate(this.qyInput);
         }
         this.results.Add(item);
     }
     this.results.Sort(this.comparer);
 }
예제 #34
0
	// Compare two sort keys.
	public static int Compare(SortKey sortkey1, SortKey sortkey2)
			{
				if(sortkey1 == null)
				{
					throw new ArgumentNullException("sortkey1");
				}
				if(sortkey2 == null)
				{
					throw new ArgumentNullException("sortkey2");
				}
				byte[] data1 = sortkey1.keyData;
				byte[] data2 = sortkey2.keyData;
				int minlen = ((data1.Length < data2.Length) ?
									data1.Length : data2.Length);
				int posn;
				for(posn = 0; posn < minlen; ++posn)
				{
					if(data1[posn] < data2[posn])
					{
						return -1;
					}
					else if(data1[posn] > data2[posn])
					{
						return 1;
					}
				}
				if(data1.Length < data2.Length)
				{
					return -1;
				}
				else if(data1.Length > data2.Length)
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
예제 #35
0
파일: SortKey.cs 프로젝트: runefs/Marvin
		public static int Compare (SortKey sortkey1, SortKey sortkey2)
		{
			if (sortkey1 == null) {
				throw new ArgumentNullException ("sortkey1");
			}
			if (sortkey2 == null) {
				throw new ArgumentNullException ("sortkey2");
			}

			byte[] keydata1 = sortkey1.key;
			byte[] keydata2 = sortkey2.key;

			if (keydata1.Length == 0) {
				if (keydata2.Length == 0) {
					return 0;
				}
				return -1;
			}
			
			int min_len = (keydata1.Length < keydata2.Length) ? keydata1.Length : keydata2.Length;

			for (int i = 0; i < min_len; i++) {
				if (keydata1[i] > keydata2[i]) {
					return 1;
				} else if (keydata1[i] < keydata2[i]) {
					return -1;
				}
			}

			if (keydata1.Length < keydata2.Length) {
				return -1;
			} else if (keydata1.Length > keydata2.Length) {
				return 1;
			} else {
				return 0;
			}
		}
예제 #36
0
        internal void SortNewNodeSet(Processor proc, ArrayList sortarray) {
            Debug.Assert(0 < sortarray.Count);
            int numSorts = sortarray.Count;
            XPathSortComparer comparer = new XPathSortComparer(numSorts);
            for (int i = 0; i < numSorts; i++) {
                Sort sort = (Sort) sortarray[i];
                Query expr = proc.GetCompiledQuery(sort.select);
                
                comparer.AddSort(expr, new XPathComparerHelper(sort.order, sort.caseOrder, sort.lang, sort.dataType));
            }
            List<SortKey> results = new List<SortKey>();

            Debug.Assert(proc.ActionStack.Peek() == this, "the trick we are doing with proc.Current will work only if this is topmost frame");

            while (NewNextNode(proc)) {
                XPathNodeIterator savedNodeset = this.nodeSet;
                this.nodeSet = this.newNodeSet;              // trick proc.Current node

                SortKey key = new SortKey(numSorts, /*originalPosition:*/results.Count, this.newNodeSet.Current.Clone());

                for (int j = 0; j < numSorts; j ++) {
                    key[j] = comparer.Expression(j).Evaluate(this.newNodeSet);
                }
                results.Add(key);

                this.nodeSet = savedNodeset;                 // restore proc.Current node
            }
            results.Sort(comparer);
            this.newNodeSet = new XPathSortArrayIterator(results);
        }
 // Constructors
 public SortRequestControl(SortKey[] sortKeys)
 {
 }
예제 #38
0
파일: sortquery.cs 프로젝트: ArildF/masters
        private void BuildResultsList() {
            XPathNavigator eNext;
            SortKey key;
            Int32 numSorts = _sortExpressions.Count;

            System.Diagnostics.Debug.Assert(numSorts > 0, "Why was the sort query created?");

            while (true) {
                eNext = _qyInput.advance();

                if (eNext == null)
                    break;

                // if this is the first time i.e., the cache is empty
                // and if we an xslt context to work with
               /* if (_ResultCount == 0 && _context != null)
                    for (Int32 i=0; i<numSorts; i++)
                        ((IQuery)_sortExpressions[i]).SetXsltContext(_context);*/

                // create the special object that represent the composite key
                // This key object will act as a container for the primary key value,
                // secondary key value etc.
                key = new SortKey(numSorts);

                for (Int32 j=0; j<numSorts; j++) {
                    object keyval = ((IQuery)_sortExpressions[j]).getValue(_qyInput);
                    key.SetKeyValue(keyval, j);
                }

                _Results.Add(key, eNext.Clone());
                _ResultCount++;
            }
        }
예제 #39
0
파일: sortquery.cs 프로젝트: ArildF/masters
        public Int32 Compare(SortKey x, SortKey y) {
#if DEBUG
            System.Diagnostics.Debug.WriteLine("Comparing >>>>");
            x.Dump();
            y.Dump();
#endif
            int result = 0;
            for (Int32 i=0; i<x.NumKeyParts; i++) {
                result = ((IComparer)_comparers[i]).Compare(x[i], y[i]);
                if (result != 0)
                    break;
            }

#if DEBUG
            System.Diagnostics.Debug.WriteLine("result = " + result.ToString());
            System.Diagnostics.Debug.WriteLine("");
#endif
            // if after all comparisions, the two sort keys are still equal,
            // preserve the doc order
            return (result == 0) ? -1 : result;
        }
예제 #40
0
 /// <summary>
 ///     Creates a new sort key having the same field as the provided key, but in
 ///     reverse sort order.
 /// </summary>
 /// <param name="key">
 ///     The sort key to be reversed.
 /// </param>
 /// <returns> The reversed sort key. </returns>
 public static SortKey ReverseOrder(SortKey key)
 {
     return new SortKey(key._field, !key._isAscendingOrder);
 }
예제 #41
0
			public void Sort(SortKey sortKey)
			{
				((FolderListViewItemComparer) this.ListViewItemSorter).SortOn(sortKey);
				this.Sort();
			}
예제 #42
0
		public void SortBy(SortKey sortKey)
		{
			_folderListView.Sort(sortKey);
		}
예제 #43
0
				public void SortOn(SortKey key)
				{
					if (_sortKeys.Remove(key))
						_invertOrder[key] = _invertClassOrder = !_invertOrder[key];
					_sortKeys.Insert(0, key);
				}
예제 #44
0
 /// <summary>
 /// Creates an instance of <see cref="SortOrder"/> with
 /// the specified array of SortKeys and Order
 /// </summary>
 /// <param name="sortKeys">Array of SortKeys to be
 /// applied to the results that are returned</param>
 /// <param name="order">Order of sorting
 /// (ASC = Ascending and DESC = Descending)</param>
 public SortOrder(SortKey[] sortKeys, string order= "DESC")
 {
     Order = order;
     SortKeys = sortKeys;
 }
예제 #45
0
        /// <summary>
        ///     閣僚リストビューのカラムクリック時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnLeaderListViewColumnClick(object sender, ColumnClickEventArgs e)
        {
            switch (e.Column)
            {
                case 0: // 名前
                    if (_key == SortKey.Name)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Name;
                    }
                    break;

                case 1: // ID
                    if (_key == SortKey.Id)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Id;
                    }
                    break;

                case 2: // 海洋プロヴィンスかどうか
                    if (_key == SortKey.Sea)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Sea;
                    }
                    break;

                case 3: // 港の有無
                    if (_key == SortKey.Port)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Port;
                    }
                    break;

                case 4: // 砂浜の有無
                    if (_key == SortKey.Beach)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Beach;
                    }
                    break;

                case 5: // インフラ
                    if (_key == SortKey.Infrastructure)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Infrastructure;
                    }
                    break;

                case 6: // IC
                    if (_key == SortKey.Ic)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Ic;
                    }
                    break;

                case 7: // 労働力
                    if (_key == SortKey.Manpower)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Manpower;
                    }
                    break;

                case 8: // エネルギー
                    if (_key == SortKey.Energy)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Energy;
                    }
                    break;

                case 9: // 金属
                    if (_key == SortKey.Metal)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Metal;
                    }
                    break;

                case 10: // 希少資源
                    if (_key == SortKey.RareMaterials)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.RareMaterials;
                    }
                    break;

                case 11: // 石油
                    if (_key == SortKey.Oil)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Oil;
                    }
                    break;

                default:
                    // 項目のない列をクリックした時には何もしない
                    return;
            }

            // プロヴィンスリストをソートする
            SortProvinceList();

            // プロヴィンスリストを更新する
            UpdateProvinceList();
        }
예제 #46
0
        /// <summary>
        ///     指揮官リストビューのカラムクリック時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnLeaderListViewColumnClick(object sender, ColumnClickEventArgs e)
        {
            switch (e.Column)
            {
                case 0: // 国タグ
                    if (_key == SortKey.Tag)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Tag;
                    }
                    break;

                case 1: // ID
                    if (_key == SortKey.Id)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Id;
                    }
                    break;

                case 2: // 名前
                    if (_key == SortKey.Name)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Name;
                    }
                    break;

                case 3: // 兵科
                    if (_key == SortKey.Branch)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Branch;
                    }
                    break;

                case 4: // スキル
                    if (_key == SortKey.Skill)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Skill;
                    }
                    break;

                case 5: // 最大スキル
                    if (_key == SortKey.MaxSkill)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.MaxSkill;
                    }
                    break;

                case 6: // 開始年
                    if (_key == SortKey.StartYear)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.StartYear;
                    }
                    break;

                case 7: // 終了年
                    if (_key == SortKey.EndYear)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.EndYear;
                    }
                    break;

                case 8: // 特性
                    if (_key == SortKey.Traits)
                    {
                        _order = _order == SortOrder.Ascendant ? SortOrder.Decendant : SortOrder.Ascendant;
                    }
                    else
                    {
                        _key = SortKey.Traits;
                    }
                    break;

                default:
                    // 項目のない列をクリックした時には何もしない
                    return;
            }

            // 指揮官リストをソートする
            SortLeaderList();

            // 指揮官リストを更新する
            UpdateLeaderList();
        }
예제 #47
0
 public abstract unsafe void GenerateSortKey(RenderView renderView, RenderViewStage renderViewStage, SortKey* sortKeys);