Exemplo n.º 1
0
        private Factor.Opcode parseFactorOperator()
        {
            Char op = nextChar();

            if ((op.CompareTo('#') == 0) || ((op.CompareTo('/') != 0) && (op.CompareTo('*') != 0)))
            {
                return(Factor.Opcode.none);
            }
            op = skipNextChar();
            Char nextChar1 = nextChar();

            if ((nextChar1.CompareTo('#') != 0) && (nextChar1.CompareTo('=') == 0))
            {
                pos--;
                return(Factor.Opcode.none);
            }
            if (op.CompareTo('/') == 0)
            {
                return(Factor.Opcode.devided);
            }
            if (op.CompareTo('*') == 0)
            {
                return(Factor.Opcode.times);
            }
            return(Factor.Opcode.none);
        }
Exemplo n.º 2
0
        public void TestCompareTo()
        {
            Char c1 = 'a';
            Char c2 = 'b';
            Char c3 = 'b';

            Assert.IsTrue(c1.CompareTo(c2) == -1, "Less than");
            Assert.IsTrue(c2.CompareTo(c1) == 1, "Greater than");
            Assert.IsTrue(c2.CompareTo(c3) == 0, "Equal 1");
            Assert.IsTrue(c1.CompareTo(c1) == 0, "Equal 2");
        }
Exemplo n.º 3
0
        private void AddRecursion(ref TreeNode node, String val)
        {
            if (val.Length == 0)
            {
                return;
            }
            Char elem = val[0];

            if (elem.CompareTo('0') == 0) // есть такой уже элемент уже;
            {
                if (node.Left == null)
                {
                    isExist   = false;
                    node.Left = new TreeNode();
                }
                AddRecursion(ref node.Left, val.Remove(0, 1));
            }
            else
            {
                if (node.Right == null)
                {
                    isExist    = false;
                    node.Right = new TreeNode();
                }
                AddRecursion(ref node.Right, val.Remove(0, 1));
            }
        }
Exemplo n.º 4
0
        private Relation.Opcode parseRelOperator()


        {
            StringBuilder oper = new StringBuilder();
            Char          op   = nextChar();

            if ((op.CompareTo('#') == 0) || ((op.CompareTo('>') != 0) && (op.CompareTo('<') != 0) && (op.CompareTo('=') != 0) && (op.CompareTo('/') != 0)))
            {
                return(Relation.Opcode.none);
            }
            op = skipNextChar();
            oper.Append(op);
            op = nextChar();
            if ((op.CompareTo('#') != 0) && (op.CompareTo('=') == 0))
            {
                op = skipNextChar();
                oper.Append(op);
            }
            String oper_complete = oper.ToString();

            if (oper_complete.CompareTo("=") == 0)
            {
                return(Relation.Opcode.equal);
            }
            if (oper_complete.CompareTo("<=") == 0)
            {
                return(Relation.Opcode.less_eq);
            }
            if (oper_complete.CompareTo("<") == 0)
            {
                return(Relation.Opcode.less);
            }
            if (oper_complete.CompareTo("/=") == 0)
            {
                return(Relation.Opcode.not_equal);
            }
            if (oper_complete.CompareTo("=>") == 0)
            {
                return(Relation.Opcode.greater_eq);
            }
            if (oper_complete.CompareTo(">") == 0)
            {
                return(Relation.Opcode.greater);
            }
            return(Relation.Opcode.none);
        }
Exemplo n.º 5
0
        private Term.Opcode parseTermOperator()
        {
            Char op = nextChar();

            if ((op.CompareTo('#') == 0) || ((op.CompareTo('+') != 0) && (op.CompareTo('-') != 0)))
            {
                return(Term.Opcode.none);
            }
            op = skipNextChar();
            if (op.CompareTo('+') == 0)
            {
                return(Term.Opcode.plus);
            }
            if (op.CompareTo('-') == 0)
            {
                return(Term.Opcode.minus);
            }
            return(Term.Opcode.none);
        }
Exemplo n.º 6
0
                public int CompareTo(Entry other)
                {
                    if (Freq < other.Freq)
                    {
                        return(-1);
                    }
                    if (Freq > other.Freq)
                    {
                        return(1);
                    }

                    return(Char.CompareTo(other.Char));
                }
Exemplo n.º 7
0
        override public int Compare(int recordNo1, int recordNo2)
        {
            Char valueNo1 = values[recordNo1];
            Char valueNo2 = values[recordNo2];

            if (valueNo1 == defaultValue || valueNo2 == defaultValue)
            {
                int bitCheck = CompareBits(recordNo1, recordNo2);
                if (0 != bitCheck)
                {
                    return(bitCheck);
                }
            }
            return(valueNo1.CompareTo(valueNo2));
            //return (valueNo1-valueNo2); // copied from Char.CompareTo(Char)
        }
Exemplo n.º 8
0
        public override int CompareValueTo(int recordNo, object value)
        {
            System.Diagnostics.Debug.Assert(0 <= recordNo, "Invalid record");
            System.Diagnostics.Debug.Assert(null != value, "null value");

            if (NullValue == value)
            {
                if (IsNull(recordNo))
                {
                    return(0);
                }
                return(1);
            }

            Char valueNo1 = values[recordNo];

            if ((defaultValue == valueNo1) && IsNull(recordNo))
            {
                return(-1);
            }
            return(valueNo1.CompareTo((Char)value));
            //return (valueNo1-valueNo2); // copied from Char.CompareTo(Char)
        }
Exemplo n.º 9
0
 public int CompareTo(object iOther)
 {
     if (iOther is RoyalGazetteIssue)
     {
         Int32             retval = 0;
         RoyalGazetteIssue lOther = (RoyalGazetteIssue)iOther;
         retval = IssueBook.CompareTo(lOther.IssueBook);
         if (retval == 0)
         {
             retval = IssueNumber.CompareTo(lOther.IssueNumber);
             if (retval == 0)
             {
                 retval = String.Compare(IssuePrefix, lOther.IssuePrefix);
                 if (retval == 0)
                 {
                     retval = String.Compare(IssuePostfix, lOther.IssuePostfix);
                 }
             }
         }
         return(retval);
     }
     throw new InvalidCastException("Not a RoyalGazetteIssue");
 }
Exemplo n.º 10
0
        private Logical.Opcode parseLogOperator()
        {
            Char op = nextChar();

            if ((op.CompareTo('#') == 0) || ((op.CompareTo('|') != 0) && (op.CompareTo('^') != 0) && (op.CompareTo('&') != 0)))
            {
                return(Logical.Opcode.none);
            }
            op = skipNextChar();
            if (op.CompareTo('|') == 0)
            {
                return(Logical.Opcode.or);
            }
            if (op.CompareTo('^') == 0)
            {
                return(Logical.Opcode.xor);
            }
            if (op.CompareTo('&') == 0)
            {
                return(Logical.Opcode.and);
            }
            return(Logical.Opcode.none);
        }
Exemplo n.º 11
0
 private static void Compare_Char(Char a, Char b) =>
 AssertEquals(a.CompareTo(b), Comparer <Char> .Default.Compare(a, b));
Exemplo n.º 12
0
    public static void Main()
    {
        string nl  = Environment.NewLine;
        string msg = "{0}The following is the result of using the generic and non-generic{0}" +
                     "versions of the CompareTo method for several base types:{0}";

        DateTime now = DateTime.Now;
// Time span = 11 days, 22 hours, 33 minutes, 44 seconds
        TimeSpan tsX = new TimeSpan(11, 22, 33, 44);
// Version = 1.2.333.4
        Version versX = new Version("1.2.333.4");
// Guid = CA761232-ED42-11CE-BACD-00AA0057B223
        Guid guidX = new Guid("{CA761232-ED42-11CE-BACD-00AA0057B223}");

        Boolean  a1 = true, a2 = true;
        Byte     b1 = 1, b2 = 1;
        Int16    c1 = -2, c2 = 2;
        Int32    d1 = 3, d2 = 3;
        Int64    e1 = 4, e2 = -4;
        Decimal  f1 = -5.5m, f2 = 5.5m;
        Single   g1 = 6.6f, g2 = 6.6f;
        Double   h1 = 7.7d, h2 = -7.7d;
        Char     i1 = 'A', i2 = 'A';
        String   j1 = "abc", j2 = "abc";
        DateTime k1 = now, k2 = now;
        TimeSpan l1 = tsX, l2 = tsX;
        Version  m1 = versX, m2 = new Version("2.0");
        Guid     n1 = guidX, n2 = guidX;

// The following types are not CLS-compliant.
        SByte  w1 = 8, w2 = 8;
        UInt16 x1 = 9, x2 = 9;
        UInt32 y1 = 10, y2 = 10;
        UInt64 z1 = 11, z2 = 11;

//
        Console.WriteLine(msg, nl);
        try
        {
// The second and third Show method call parameters are automatically boxed because
// the second and third Show method declaration arguments expect type Object.

            Show("Boolean:  ", a1, a2, a1.CompareTo(a2), a1.CompareTo((Object)a2));
            Show("Byte:     ", b1, b2, b1.CompareTo(b2), b1.CompareTo((Object)b2));
            Show("Int16:    ", c1, c2, c1.CompareTo(c2), c1.CompareTo((Object)c2));
            Show("Int32:    ", d1, d2, d1.CompareTo(d2), d1.CompareTo((Object)d2));
            Show("Int64:    ", e1, e2, e1.CompareTo(e2), e1.CompareTo((Object)e2));
            Show("Decimal:  ", f1, f2, f1.CompareTo(f2), f1.CompareTo((Object)f2));
            Show("Single:   ", g1, g2, g1.CompareTo(g2), g1.CompareTo((Object)g2));
            Show("Double:   ", h1, h2, h1.CompareTo(h2), h1.CompareTo((Object)h2));
            Show("Char:     ", i1, i2, i1.CompareTo(i2), i1.CompareTo((Object)i2));
            Show("String:   ", j1, j2, j1.CompareTo(j2), j1.CompareTo((Object)j2));
            Show("DateTime: ", k1, k2, k1.CompareTo(k2), k1.CompareTo((Object)k2));
            Show("TimeSpan: ", l1, l2, l1.CompareTo(l2), l1.CompareTo((Object)l2));
            Show("Version:  ", m1, m2, m1.CompareTo(m2), m1.CompareTo((Object)m2));
            Show("Guid:     ", n1, n2, n1.CompareTo(n2), n1.CompareTo((Object)n2));
//
            Console.WriteLine("{0}The following types are not CLS-compliant:", nl);
            Show("SByte:    ", w1, w2, w1.CompareTo(w2), w1.CompareTo((Object)w2));
            Show("UInt16:   ", x1, x2, x1.CompareTo(x2), x1.CompareTo((Object)x2));
            Show("UInt32:   ", y1, y2, y1.CompareTo(y2), y1.CompareTo((Object)y2));
            Show("UInt64:   ", z1, z2, z1.CompareTo(z2), z1.CompareTo((Object)z2));
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
Exemplo n.º 13
0
 public static Char of(Char left, Char right)
 {
     return(left.CompareTo(right) < 0 ? right : left);
 }
Exemplo n.º 14
0
        private void MethodTests()
        {
            featureTest.FailureMessage = "\tFailed Char Method Test";
            featureTest.Send("Char Method Test");
            String str1   = "123aBc\t\n. ";
            Char   value1 = 'A';
            Char   value2 = 'B';
            Char   value3 = 'C';
            Object obj1   = value1;
            Object obj2   = value2;
            Object obj3   = value3;

            featureTest.AssertTrue(value2.CompareTo(value1) > 0);
            featureTest.AssertTrue(value2.CompareTo(value3) < 0);
            featureTest.AssertTrue(value2.CompareTo(value2) == 0);
            featureTest.AssertTrue(value2.CompareTo(obj1) > 0);
            featureTest.AssertTrue(value2.CompareTo(obj3) < 0);
            featureTest.AssertTrue(value2.CompareTo(obj2) == 0);
            featureTest.AssertTrue(!value2.Equals(value1));
            featureTest.AssertTrue(!value2.Equals(value3));
            featureTest.AssertTrue(value2.Equals(value2));
            Object ob = (Object)value1;

            featureTest.AssertTrue('A'.Equals((Char)ob));
            featureTest.AssertTrue('A'.Equals(ob));
            featureTest.AssertTrue(ob.ToString() == "A");
            featureTest.AssertTrue(!value2.Equals(obj1));
            featureTest.AssertTrue(!value2.Equals(obj3));
            featureTest.AssertTrue(value2.Equals(obj2));
            featureTest.AssertTrue('A'.CompareTo(value1) == 0);
            featureTest.AssertTrue(Char.GetNumericValue('5') == 5);
            featureTest.AssertTrue(Char.GetNumericValue(str1, 2) == 3);
            featureTest.AssertTrue(Char.IsControl('\t'));
            featureTest.AssertTrue(!Char.IsControl('A'));
            featureTest.AssertTrue(Char.IsControl(str1, 7));
            featureTest.AssertTrue(!Char.IsControl(str1, 0));
            featureTest.AssertTrue(Char.IsDigit('1'));
            featureTest.AssertTrue(!Char.IsDigit('A'));
            featureTest.AssertTrue(Char.IsDigit(str1, 2));
            featureTest.AssertTrue(!Char.IsDigit(str1, 7));
            featureTest.AssertTrue(Char.IsLetter('a'));
            featureTest.AssertTrue(!Char.IsLetter('1'));
            featureTest.AssertTrue(Char.IsLetter(str1, 3));
            featureTest.AssertTrue(!Char.IsLetter(str1, 0));
            featureTest.AssertTrue(Char.IsLetterOrDigit('a'));
            featureTest.AssertTrue(Char.IsLetterOrDigit('1'));
            featureTest.AssertTrue(!Char.IsLetterOrDigit('\t'));
            featureTest.AssertTrue(Char.IsLetterOrDigit(str1, 3));
            featureTest.AssertTrue(Char.IsLetterOrDigit(str1, 0));
            featureTest.AssertTrue(!Char.IsLetterOrDigit(str1, 7));
            featureTest.AssertTrue(Char.IsLower('a'));
            featureTest.AssertTrue(!Char.IsLower('A'));
            featureTest.AssertTrue(Char.IsLower(str1, 3));
            featureTest.AssertTrue(!Char.IsLower(str1, 4));
            featureTest.AssertTrue(Char.IsNumber('1'));
            featureTest.AssertTrue(!Char.IsNumber('A'));
            featureTest.AssertTrue(Char.IsNumber(str1, 2));
            featureTest.AssertTrue(!Char.IsNumber(str1, 3));
            featureTest.AssertTrue(Char.IsPunctuation(','));
            featureTest.AssertTrue(!Char.IsPunctuation('A'));
            featureTest.AssertTrue(Char.IsPunctuation(str1, 8));
            featureTest.AssertTrue(!Char.IsPunctuation(str1, 0));
            featureTest.AssertTrue(Char.IsSeparator(' '));
            featureTest.AssertTrue(!Char.IsSeparator('A'));
            featureTest.AssertTrue(Char.IsSeparator(str1, 9));
            featureTest.AssertTrue(!Char.IsSeparator(str1, 0));
            featureTest.AssertTrue(Char.IsUpper('B'));
            featureTest.AssertTrue(!Char.IsUpper('b'));
            featureTest.AssertTrue(Char.IsUpper(str1, 4));
            featureTest.AssertTrue(!Char.IsUpper(str1, 3));
            featureTest.AssertTrue(Char.IsWhiteSpace(' '));
            featureTest.AssertTrue(!Char.IsWhiteSpace('A'));
            featureTest.AssertTrue(Char.IsWhiteSpace(str1, 9));
            featureTest.AssertTrue(!Char.IsWhiteSpace(str1, 0));
            featureTest.AssertTrue(Char.ToLower('A') == 'a');
            featureTest.AssertTrue(Char.ToLower('a') == 'a');
            featureTest.AssertTrue(Char.ToUpper('a') == 'A');
            featureTest.AssertTrue(Char.ToUpper('A') == 'A');
            featureTest.AssertTrue("a".Equals('a'.ToString()));
            featureTest.AssertTrue("a".Equals(Char.ToString('a')));
            featureTest.AssertTrue('a'.Equals(Char.Parse("a")));
            Char result;

            featureTest.AssertTrue(Char.TryParse("A", out result));
            featureTest.AssertTrue(result == 'A');
        }
Exemplo n.º 15
0
 /// <summary>
 /// Compares the current object with another object of the same type.
 /// </summary>
 /// <returns>
 /// A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter.Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public int CompareTo(TrieNode other)
 {
     return(Char.CompareTo(other.Char));
 }