示例#1
0
 // +=
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public void AddEqual(Kirikiri.Tjs2.Variant rhs)
 {
     if (mObject is string || rhs.mObject is string)
     {
         if (mObject is string && rhs.mObject is string)
         {
             // both are string
             mObject = (string)mObject + (string)rhs.mObject;
             return;
         }
         string s1 = AsString();
         string s2 = rhs.AsString();
         if (s1 != null && s2 != null)
         {
             StringBuilder builder = new StringBuilder(256);
             builder.Append(s1);
             builder.Append(s2);
             mObject = builder.ToString();
         }
         else
         {
             if (s1 != null)
             {
                 mObject = s1;
             }
             else
             {
                 mObject = s2;
             }
         }
         //mObject = s1 + s2;
         return;
     }
     if (mObject != null && rhs.mObject != null)
     {
         if (mObject.GetType().IsAssignableFrom(rhs.mObject.GetType()))
         {
             // 同じクラス
             if (mObject is ByteBuffer)
             {
                 ByteBuffer b1 = (ByteBuffer)mObject;
                 ByteBuffer b2 = (ByteBuffer)rhs.mObject;
                 ByteBuffer result = ByteBuffer.Allocate(b1.Capacity() + b2.Capacity());
                 b1.Position(0);
                 b2.Position(0);
                 result.Put(b1);
                 result.Put(b2);
                 result.Position(0);
                 mObject = result;
                 return;
             }
             if (mObject is int)
             {
                 int result = ((int)mObject) + ((int)rhs.mObject);
                 mObject = Sharpen.Extensions.ValueOf(result);
                 return;
             }
         }
     }
     if (mObject == null)
     {
         if (rhs.mObject != null)
         {
             if (rhs.mObject is int)
             {
                 mObject = Sharpen.Extensions.ValueOf(((int)rhs.mObject));
                 return;
             }
             else
             {
                 if (rhs.mObject is double)
                 {
                     mObject = (((double)rhs.mObject));
                     return;
                 }
             }
         }
     }
     if (rhs.mObject == null)
     {
         if (mObject != null)
         {
             if (mObject is int)
             {
                 return;
             }
             else
             {
                 if (mObject is double)
                 {
                     return;
                 }
             }
         }
     }
     mObject = (AsDouble() + rhs.AsDouble());
 }
示例#2
0
 // +
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public Kirikiri.Tjs2.Variant Add(Kirikiri.Tjs2.Variant val)
 {
     if (mObject is string || val.mObject is string)
     {
         string s1 = AsString();
         string s2 = val.AsString();
         if (s1 != null && s2 != null)
         {
             StringBuilder builder = new StringBuilder(256);
             builder.Append(s1);
             builder.Append(s2);
             return new Kirikiri.Tjs2.Variant(builder.ToString());
         }
         else
         {
             if (s1 != null)
             {
                 return new Kirikiri.Tjs2.Variant(s1);
             }
             else
             {
                 return new Kirikiri.Tjs2.Variant(s2);
             }
         }
     }
     if (mObject != null && val.mObject != null)
     {
         if (mObject.GetType().IsAssignableFrom(val.mObject.GetType()))
         {
             // 同じクラス
             if (mObject is ByteBuffer)
             {
                 ByteBuffer b1 = (ByteBuffer)mObject;
                 ByteBuffer b2 = (ByteBuffer)val.mObject;
                 ByteBuffer result = ByteBuffer.Allocate(b1.Capacity() + b2.Capacity());
                 b1.Position(0);
                 b2.Position(0);
                 result.Put(b1);
                 result.Put(b2);
                 result.Position(0);
                 return new Kirikiri.Tjs2.Variant(result);
             }
             if (mObject is int)
             {
                 int result = ((int)mObject) + ((int)val.mObject);
                 return new Kirikiri.Tjs2.Variant(result);
             }
         }
     }
     if (mObject == null)
     {
         if (val.mObject != null)
         {
             if (val.mObject is int)
             {
                 return new Kirikiri.Tjs2.Variant(((int)val.mObject));
             }
             else
             {
                 if (val.mObject is double)
                 {
                     return new Kirikiri.Tjs2.Variant(((double)val.mObject));
                 }
             }
         }
     }
     if (val.mObject == null)
     {
         if (mObject != null)
         {
             if (mObject is int)
             {
                 return new Kirikiri.Tjs2.Variant(((int)mObject));
             }
             else
             {
                 if (mObject is double)
                 {
                     return new Kirikiri.Tjs2.Variant(((double)mObject));
                 }
             }
         }
     }
     return new Kirikiri.Tjs2.Variant(AsDouble() + val.AsDouble());
 }
示例#3
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public int LittlerThanForSort(Kirikiri.Tjs2.Variant val)
 {
     if ((mObject is string) == false || (val.mObject is string) == false)
     {
         if ((mObject is int) && (val.mObject is int))
         {
             return ((int)val.mObject) - ((int)mObject);
         }
         double ret = val.AsDouble() - AsDouble();
         if (ret == 0.0)
         {
             return 0;
         }
         else
         {
             if (ret < 0.0)
             {
                 return -1;
             }
             else
             {
                 return 1;
             }
         }
     }
     string s1 = AsString();
     string s2 = val.AsString();
     return Sharpen.Runtime.CompareOrdinal(s2, s1);
 }
示例#4
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public bool NormalCompare(Kirikiri.Tjs2.Variant val2)
 {
     if (mObject != null && val2.mObject != null)
     {
         if (mObject.GetType().IsAssignableFrom(val2.mObject.GetType()))
         {
             // 同じクラス
             if (mObject is int)
             {
                 return ((int)mObject) == ((int)val2.mObject);
             }
             if (mObject is string)
             {
                 return ((string)mObject).Equals(((string)val2.mObject));
             }
             if (mObject is ByteBuffer)
             {
                 //return ((ByteBuffer)mObject).compareTo( ((ByteBuffer)val2.mObject) ) == 0;
                 ByteBuffer v1 = (ByteBuffer)mObject;
                 ByteBuffer v2 = (ByteBuffer)val2.mObject;
                 int c1 = v1.Limit();
                 int c2 = v2.Limit();
                 if (c1 == c2)
                 {
                     for (int i = 0; i < c1; i++)
                     {
                         byte b1 = v1.Get(i);
                         byte b2 = v2.Get(i);
                         if (b1 != b2)
                         {
                             return false;
                         }
                     }
                 }
                 else
                 {
                     return false;
                 }
                 return true;
             }
             if (mObject is double)
             {
                 return ((double)mObject) == ((double)val2.mObject);
             }
             return mObject.Equals(val2.mObject);
         }
         else
         {
             if (mObject is string || val2.mObject is string)
             {
                 string v1 = AsString();
                 string v2 = val2.AsString();
                 return v1.Equals(v2);
             }
             else
             {
                 if (mObject is Number && val2.mObject is Number)
                 {
                     double r1 = ((Number)mObject);
                     double r2 = ((Number)val2.mObject);
                     if (Double.IsNaN(r1) || Double.IsNaN(r2))
                     {
                         return false;
                     }
                     if (Double.IsInfinite(r1) || Double.IsInfinite(r2))
                     {
                         return Double.Compare(r1, r2) == 0;
                     }
                     return r1 == r2;
                 }
                 else
                 {
                     return false;
                 }
             }
         }
     }
     else
     {
         // 片方はnull
         if (mObject == null && val2.mObject == null)
         {
             return true;
         }
         if (mObject == null)
         {
             if (val2.mObject is int)
             {
                 return ((int)val2.mObject) == 0;
             }
             if (val2.mObject is double)
             {
                 return ((double)val2.mObject) == 0.0;
             }
             if (val2.mObject is string)
             {
                 return ((string)val2.mObject).Length == 0;
             }
             return false;
         }
         else
         {
             if (mObject is int)
             {
                 return ((int)mObject) == 0;
             }
             if (mObject is double)
             {
                 return ((double)mObject) == 0.0;
             }
             if (mObject is string)
             {
                 return ((string)mObject).Length == 0;
             }
             return false;
         }
     }
 }
示例#5
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public bool LittlerThan(Kirikiri.Tjs2.Variant val)
 {
     if ((mObject is string) == false || (val.mObject is string) == false)
     {
         if ((mObject is int) && (val.mObject is int))
         {
             return ((int)mObject) > ((int)val.mObject);
         }
         return AsDouble() > val.AsDouble();
     }
     string s1 = AsString();
     string s2 = val.AsString();
     return Sharpen.Runtime.CompareOrdinal(s1, s2) > 0;
 }