示例#1
0
        /// <summary>
        /// Parses a given key according to the expected key format and forms the given
        /// segments.
        /// </summary>
        /// <param name="key">the key in expected dataType:operationType*measurementType format
        ///     </param>
        /// <param name="value">a generic value expected to match the output type</param>
        /// <exception cref="System.ArgumentException">if invalid format</exception>
        internal OperationOutput(string key, object value)
        {
            int place = key.IndexOf(TypeSep);

            if (place == -1)
            {
                throw new ArgumentException("Invalid key format - no type seperator - " + TypeSep
                                            );
            }
            try
            {
                dataType = OperationOutput.OutputType.ValueOf(StringUtils.ToUpperCase(Sharpen.Runtime.Substring
                                                                                          (key, 0, place)));
            }
            catch (Exception e)
            {
                throw new ArgumentException("Invalid key format - invalid output type", e);
            }
            key   = Sharpen.Runtime.Substring(key, place + 1);
            place = key.IndexOf(MeasurementSep);
            if (place == -1)
            {
                throw new ArgumentException("Invalid key format - no measurement seperator - " +
                                            MeasurementSep);
            }
            opType          = Sharpen.Runtime.Substring(key, 0, place);
            measurementType = Sharpen.Runtime.Substring(key, place + 1);
            this.value      = value;
        }
示例#2
0
 internal OperationOutput(OperationOutput.OutputType dataType, string opType, string
                          measurementType, object value)
 {
     this.dataType        = dataType;
     this.opType          = opType;
     this.measurementType = measurementType;
     this.value           = value;
 }
示例#3
0
 /// <summary>Merges according to the documented rules for merging.</summary>
 /// <remarks>
 /// Merges according to the documented rules for merging. Only will merge if
 /// measurement type and operation type is the same.
 /// </remarks>
 /// <param name="o1">the first object to merge with the second</param>
 /// <param name="o2">the second object.</param>
 /// <returns>OperationOutput merged output.</returns>
 /// <exception cref="System.ArgumentException">if unable to merge due to incompatible formats/types
 ///     </exception>
 internal static Org.Apache.Hadoop.FS.Slive.OperationOutput Merge(Org.Apache.Hadoop.FS.Slive.OperationOutput
                                                                  o1, Org.Apache.Hadoop.FS.Slive.OperationOutput o2)
 {
     if (o1.GetMeasurementType().Equals(o2.GetMeasurementType()) && o1.GetOperationType
             ().Equals(o2.GetOperationType()))
     {
         object newvalue = null;
         OperationOutput.OutputType newtype = null;
         string opType = o1.GetOperationType();
         string mType  = o1.GetMeasurementType();
         if (o1.GetOutputType() == OperationOutput.OutputType.String || o2.GetOutputType()
             == OperationOutput.OutputType.String)
         {
             newtype = OperationOutput.OutputType.String;
             StringBuilder str = new StringBuilder();
             str.Append(o1.GetValue());
             str.Append(StringSep);
             str.Append(o2.GetValue());
             newvalue = str.ToString();
         }
         else
         {
             if (o1.GetOutputType() == OperationOutput.OutputType.Double || o2.GetOutputType()
                 == OperationOutput.OutputType.Double)
             {
                 newtype = OperationOutput.OutputType.Double;
                 try
                 {
                     newvalue = double.ParseDouble(o1.GetValue().ToString()) + double.ParseDouble(o2.GetValue
                                                                                                      ().ToString());
                 }
                 catch (FormatException e)
                 {
                     throw new ArgumentException("Unable to combine a type with a double " + o1 + " & "
                                                 + o2, e);
                 }
             }
             else
             {
                 if (o1.GetOutputType() == OperationOutput.OutputType.Float || o2.GetOutputType()
                     == OperationOutput.OutputType.Float)
                 {
                     newtype = OperationOutput.OutputType.Float;
                     try
                     {
                         newvalue = float.ParseFloat(o1.GetValue().ToString()) + float.ParseFloat(o2.GetValue
                                                                                                      ().ToString());
                     }
                     catch (FormatException e)
                     {
                         throw new ArgumentException("Unable to combine a type with a float " + o1 + " & "
                                                     + o2, e);
                     }
                 }
                 else
                 {
                     if (o1.GetOutputType() == OperationOutput.OutputType.Long || o2.GetOutputType() ==
                         OperationOutput.OutputType.Long)
                     {
                         newtype = OperationOutput.OutputType.Long;
                         try
                         {
                             newvalue = long.Parse(o1.GetValue().ToString()) + long.Parse(o2.GetValue().ToString
                                                                                              ());
                         }
                         catch (FormatException e)
                         {
                             throw new ArgumentException("Unable to combine a type with a long " + o1 + " & "
                                                         + o2, e);
                         }
                     }
                     else
                     {
                         if (o1.GetOutputType() == OperationOutput.OutputType.Integer || o2.GetOutputType(
                                 ) == OperationOutput.OutputType.Integer)
                         {
                             newtype = OperationOutput.OutputType.Integer;
                             try
                             {
                                 newvalue = System.Convert.ToInt32(o1.GetValue().ToString()) + System.Convert.ToInt32
                                                (o2.GetValue().ToString());
                             }
                             catch (FormatException e)
                             {
                                 throw new ArgumentException("Unable to combine a type with an int " + o1 + " & "
                                                             + o2, e);
                             }
                         }
                     }
                 }
             }
         }
         return(new Org.Apache.Hadoop.FS.Slive.OperationOutput(newtype, opType, mType, newvalue
                                                               ));
     }
     else
     {
         throw new ArgumentException("Unable to combine dissimilar types " + o1 + " & " +
                                     o2);
     }
 }