Пример #1
0
        /// <summary>
        /// Obtains a boolean value from an object.
        /// </summary>
        /// <param name="objectValue">The object to convert to boolean.</param>
        /// <returns>Returns the boolean representation of the object.</returns>
        public static bool ToBoolean(object objectValue)
        {
            bool result = false;

            if (objectValue != null)
            {
                if (objectValue is int || objectValue is long || objectValue is double || objectValue is bool)
                {
                    result = System.Convert.ToBoolean(objectValue);
                }
                else if (objectValue is string)
                {
                    result = ToBoolean((string)objectValue);
                }
                else if (objectValue is OrderedMap)
                {
                    OrderedMap orderedMap = (OrderedMap)objectValue;
                    result = orderedMap.Count == 0 ? false : true;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Returns an OrderedMap with the pathnames that match the specified pattern.
        /// </summary>
        /// <param name="pattern">The search pattern.</param>
        /// <returns>Returns an OrderedMap with the pathnames that match the specified pattern.</returns>
        public static OrderedMap Glob(string pattern)
        {
            OrderedMap newOrderedMap = null;

            try
            {
                string path =
                    System.Web.HttpContext.Current.Request.MapPath(
                        System.Web.HttpContext.Current.Request.ApplicationPath);
                System.IO.DirectoryInfo    dirInfo   = new System.IO.DirectoryInfo(System.IO.Path.GetDirectoryName(path));
                System.IO.FileSystemInfo[] fileInfos = dirInfo.GetFiles(pattern);
                if (fileInfos.Length > 0)
                {
                    newOrderedMap = new OrderedMap();
                    for (int index = 0; index < fileInfos.Length; index++)
                    {
                        newOrderedMap[index] = fileInfos[index].Name;
                    }
                }
            }
            catch
            {
            }
            return(newOrderedMap);
        }
Пример #3
0
        /// <summary>
        /// Converts an object to its numeric double representation.
        /// </summary>
        /// <param name="instance">The object value to convert.</param>
        /// <returns>Returns the numeric double representation of the object.</returns>
        public static double ToDouble(object instance)
        {
            double result = 0;

            if (instance != null)
            {
                if (instance is int || instance is long || instance is double || instance is bool || instance is UInt32 || instance is UInt16)
                {
                    result = System.Convert.ToDouble(instance);
                }
                else if (instance is string)
                {
                    result = ToDouble((string)instance);
                }
                else if (instance is OrderedMap)
                {
                    OrderedMap orderedMap = (OrderedMap)instance;
                    result = orderedMap.Count == 0 ? 0 : 1;
                }
                else
                {
                    result = 1;
                }
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Reads a line from the specified stream and parses it for CSV fields.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="length">The maximum length of the line to be read</param>
        /// <param name="delimiter">The delimiter which separates the CSV fields.</param>
        /// <returns>Returns an OrderedMap that contains the CSV fields of the read line.</returns>
        public static OrderedMap ReadCSV(System.IO.FileStream stream, int length, string delimiter)
        {
            OrderedMap newOrderedMap = null;

            try
            {
                string line = ReadLine(stream, length);
                if (line != null)
                {
                    if (delimiter == null || delimiter == string.Empty)
                    {
                        delimiter = ",";
                    }
                    string[] fields = line.Split(delimiter[0]);
                    for (int index = 0; index < fields.Length; index++)
                    {
                        fields[index] = fields[index].Trim();
                    }

                    newOrderedMap = new OrderedMap(fields, false);
                }
            }
            catch
            {
            }
            return(newOrderedMap);
        }
Пример #5
0
        /// <summary>
        /// Reads the specified INI file and returns the contents in an OrderedMap.
        /// </summary>
        /// <param name="fileName">The INI file to read.</param>
        /// <returns>Returns the contents of the specified INI file.</returns>
        public static OrderedMap ParseINI(string fileName)
        {
            OrderedMap newOrderedMap = null;

            try
            {
                using (System.IO.StreamReader stream = new System.IO.StreamReader(fileName))
                {
                    newOrderedMap = new OrderedMap();
                    string line;
                    while ((line = stream.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line != "" && !line.StartsWith(";") && !line.StartsWith("["))
                        {
                            string[] lineContents = line.Split('=');
                            newOrderedMap[lineContents[0].Trim()] = lineContents[1].Trim();
                        }
                    }
                }
            }
            catch
            {
            }
            return(newOrderedMap);
        }
Пример #6
0
        /// <summary>
        /// Converts an object into an OrderedMap
        /// </summary>
        /// <param name="obj">The object to convert to OrderedMap.</param>
        /// <returns>Returns an OrderedMap representation of the object.</returns>
        public static OrderedMap ToArray(object obj)
        {
            OrderedMap result = new OrderedMap();

            if (obj != null)
            {
                if (obj is OrderedMap)
                {
                    result = new OrderedMap((OrderedMap)obj, false);
                }
                else if (obj is string || obj is int || obj is long || obj is double || obj is bool)
                {
                    result = new OrderedMap(obj);
                }
                else
                {
                    System.Reflection.FieldInfo[] fields = obj.GetType().GetTypeInfo().GetFields();
                    for (int index = 0; index < fields.Length; index++)
                    {
                        result[fields[index].Name] = fields[index].GetValue(obj);
                    }
                }
            }
            return(result);
        }
 /**
  * Factory method to create an unmodifiable sorted map.
  *
  * @param map  the map to decorate, must not be null
  * @throws IllegalArgumentException if map is null
  */
 public static OrderedMap decorate(OrderedMap map)
 {
     if (map is Unmodifiable)
     {
         return map;
     }
     return new UnmodifiableOrderedMap(map);
 }
Пример #8
0
 /**
  * Factory method to create an unmodifiable sorted map.
  *
  * @param map  the map to decorate, must not be null
  * @throws IllegalArgumentException if map is null
  */
 public static OrderedMap decorate(OrderedMap map)
 {
     if (map is Unmodifiable)
     {
         return(map);
     }
     return(new UnmodifiableOrderedMap(map));
 }
Пример #9
0
        public static OrderedMap FileToArray(StreamReader reader)
        {
            var result = new OrderedMap();
            var line   = reader.ReadLine();

            while (line != null)
            {
                result[line] = line;
                line         = reader.ReadLine();
            }
            return(result);
        }
Пример #10
0
        public void doCallTest()
        {
            PrivateObject          param0 = null;                               // TODO: Initialize to an appropriate value
            YmlpConnector_Accessor target = new YmlpConnector_Accessor(param0); // TODO: Initialize to an appropriate value
            string       method           = string.Empty;                       // TODO: Initialize to an appropriate value
            OrderedMap   commandParams    = null;                               // TODO: Initialize to an appropriate value
            YmlpResponse expected         = null;                               // TODO: Initialize to an appropriate value
            YmlpResponse actual;

            actual = target.doCall(method, commandParams);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Пример #11
0
 public void read(Json json, OrderedMap <String, Object> jsonData)
 {
     /*playerProfile = json.readValue( "currentLevelId", Integer.class, jsonData );
      * credits = json.readValue( "credits", Integer.class, jsonData );
      * // libgdx handles the keys of JSON formatted HashMaps as Strings, but we
      * // want it to be integers instead (because the levelIds are integers)
      * Map<String,Integer> highScores = json.readValue( "highScores", HashMap.class,
      *  Integer.class, jsonData );
      * for( String levelIdAsString : highScores.keySet() ) {
      *  int levelId = Integer.valueOf( levelIdAsString );
      *  Integer highScore = highScores.get( levelIdAsString);
      *  this.highScores.put( levelId, highScore );
      * }*/
 }
Пример #12
0
        private static OrderedMap DeepCloneMap(OrderedMap map)
        {
            var  taggedEntries = new KeyValuePair <EvaluationResult, TaggedEntry> [map.Count];
            long tag           = 0;

            foreach (var kv in map)
            {
                var clonedKey   = DeepCloneValue(kv.Key);
                var clonedValue = DeepCloneValue(kv.Value);
                taggedEntries[tag] = new KeyValuePair <EvaluationResult, TaggedEntry>(clonedKey, new TaggedEntry(clonedValue, tag));
                tag++;
            }

            return(new OrderedMap(ImmutableDictionary <EvaluationResult, TaggedEntry> .Empty.SetItems(taggedEntries), tag));
        }
Пример #13
0
        ///// <summary>
        ///// Gets the number of available bytes of the specified disk.
        ///// </summary>
        ///// <param name="disk">The disk to obtain the information for.<param>
        ///// <returns>Returns number of available bytes of the specified disk.</returns>
        //public static long GetDiskFreeSpace(string disk)
        //{
        //    long result = 0;
        //    try
        //    {
        //        string root = System.IO.Path.GetPathRoot(System.IO.Path.GetFullPath(disk));
        //        root = root.Replace(@"\", "");
        //        System.Management.ManagementObject theDisk =
        //            new System.Management.ManagementObject("win32_logicaldisk.deviceid=\"" + root + "\"");
        //        theDisk.Get();
        //        result = System.Convert.ToInt64(theDisk["FreeSpace"]);
        //    }
        //    catch
        //    {
        //    }
        //    return result;
        //}

        ///// <summary>
        ///// Gets total size of the specified disk.
        ///// </summary>
        ///// <param name="disk">The disk to obtain the information for.<param>
        ///// <returns>Returns total size of the specified disk.</returns>
        //public static long GetDiskSize(string disk)
        //{
        //    long result = 0;
        //    try
        //    {
        //        string root = System.IO.Path.GetPathRoot(System.IO.Path.GetFullPath(disk));
        //        root = root.Replace(@"\", "");
        //        System.Management.ManagementObject theDisk =
        //            new System.Management.ManagementObject("win32_logicaldisk.deviceid=\"" + root + "\"");
        //        theDisk.Get();
        //        result = System.Convert.ToInt64(theDisk["Size"]);
        //    }
        //    catch
        //    {
        //    }
        //    return result;
        //}

        /// <summary>
        /// Returns an OrderedMap with information about the specified path.
        /// </summary>
        /// <param name="path">The path to retrieve the information from.</param>
        /// <returns>Returns an OrderedMap with information about the specified path.</returns>
        public static OrderedMap PathInfo(string path)
        {
            OrderedMap pathInfo = null;

            try
            {
                pathInfo              = new OrderedMap();
                pathInfo["dirname"]   = System.IO.Path.GetDirectoryName(path);
                pathInfo["basename"]  = System.IO.Path.GetFileName(path);
                pathInfo["extension"] = System.IO.Path.GetExtension(path);
            }
            catch
            {
            }
            return(pathInfo);
        }
Пример #14
0
        private static bool TryHashMap(OrderedMap map, HashingHelper helper)
        {
            helper.Add(map.Count);
            foreach (var kv in map)
            {
                if (!TryHashValue(kv.Key, helper))
                {
                    return(false);
                }
                if (!TryHashValue(kv.Value, helper))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #15
0
        /// <summary>
        /// Converts an object into an OrderedMap
        /// </summary>
        /// <param name="obj">The object to convert to OrderedMap.</param>
        /// <returns>Returns an OrderedMap representation of the object.</returns>
        public static OrderedMap ToArray(object obj)
        {
            OrderedMap result = new OrderedMap();

            if (obj != null)
            {
                if (obj is OrderedMap)
                    result = new OrderedMap((OrderedMap) obj, false);
                else if (obj is string || obj is int || obj is long || obj is double || obj is bool)
                    result = new OrderedMap(obj);
                else
                {
                    System.Reflection.FieldInfo[] fields = obj.GetType().GetFields();
                    for (int index = 0; index < fields.Length; index++)
                        result[fields[index].Name] = fields[index].GetValue(obj);
                }
            }
            return result;
        }
Пример #16
0
        /// <summary>
        /// Reads an entire file into an OrderedMap.
        /// </summary>
        /// <param name="fileName">The name of the file to open and read.</param>
        /// <returns>Returns an OrderedMap containing the data from the file.</returns>
        public static OrderedMap FileToArray(string fileName)
        {
            OrderedMap result = null;

            using (System.IO.FileStream file = new System.IO.FileStream(fileName, System.IO.FileMode.Open,
                                                                        System.IO.FileAccess.Read, System.IO.FileShare.Read))
            {
                result = new OrderedMap();
                System.IO.StreamReader reader = new StreamReader(file);
                string line = reader.ReadLine();
                while (line != null)
                {
                    result[line] = line;
                    line         = reader.ReadLine();
                }
            }

            return(result);
        }
Пример #17
0
        /// <summary>
        /// Reads an entire file into an OrderedMap.
        /// </summary>
        /// <param name="fileName">The name of the file to open and read.</param>
        /// <returns>Returns an OrderedMap containing the data from the file.</returns>
        public static OrderedMap FileToArray(string fileName)
        {
            OrderedMap result = null;

            try
            {
                result = new OrderedMap();
                System.IO.StreamReader reader = new System.IO.StreamReader(fileName);
                string line = reader.ReadLine();
                while (line != null)
                {
                    result[line] = line;
                    line         = reader.ReadLine();
                }
                reader.Close();
            }
            catch
            {
            }
            return(result);
        }
Пример #18
0
        /// <summary>
        /// Gets a boolean value that indicates whether the specified value is a method or not.
        /// </summary>
        /// <param name="method">The value that may contain a method name (string) or an OrderedMap.
        /// If the value is an OrderedMap, then it should have to entries: a class instance and a method name.</param>
        /// <param name="callableName">The referenced string value used to return the method name.</param>
        /// <param name="declaringType">The method declaring type. This parameter is used when the first parameter is a string.</param>
        /// <returns>Returns a boolean value that indicates whther the specified value is a method or not.</returns>
        public static bool IsCallable(object method, ref string callableName, System.Type declaringType)
        {
            bool result = false;

            try
            {
                System.Reflection.MethodInfo methodInfo = null;

                if (method is System.String)
                {
                    callableName = method.ToString();
                    methodInfo   = declaringType.GetTypeInfo().GetMethod(method.ToString());
                    if (methodInfo != null)
                    {
                        callableName = methodInfo.Name;
                        result       = true;
                    }
                }
                else if (method is OrderedMap)
                {
                    OrderedMap typeMethod = (OrderedMap)method;
                    callableName = typeMethod.ToString();
                    methodInfo   = typeMethod.GetValueAt(0).GetType().GetTypeInfo().GetMethod(typeMethod.GetValueAt(1).ToString());
                    if (methodInfo != null)
                    {
                        callableName = typeMethod.GetValueAt(0).GetType().Name + ":" + methodInfo.Name;
                        result       = true;
                    }
                }
                else
                {
                    callableName = method.ToString();
                }
            }
            catch
            {
            }

            return(result);
        }
 //-----------------------------------------------------------------------
 /**
  * Constructor that wraps (not copies).
  *
  * @param map  the map to decorate, must not be null
  * @throws IllegalArgumentException if map is null
  */
 private UnmodifiableOrderedMap(OrderedMap map)
     : base(map)
 {
 }
 /**
  * Constructor that wraps (not copies).
  *
  * @param map  the map to decorate, must not be null
  * @throws IllegalArgumentException if the collection is null
  */
 public AbstractOrderedMapDecorator(OrderedMap map)
     : base(map)
 {
 }
 /**
  * Constructor that wraps (not copies).
  *
  * @param map  the map to decorate, must not be null
  * @throws IllegalArgumentException if the collection is null
  */
 public AbstractOrderedMapDecorator(OrderedMap map)
     : base(map)
 {
 }
Пример #22
0
        //-----------------------------------------------------------------------

        /**
         * Constructor that wraps (not copies).
         *
         * @param map  the map to decorate, must not be null
         * @throws IllegalArgumentException if map is null
         */
        private UnmodifiableOrderedMap(OrderedMap map)
            : base(map)
        {
        }
Пример #23
0
 public Emitter(int max)
 {
     this._emitterTable = new OrderedMap <T, SortedList <Updateable> >();
     this._active       = true;
     _maxFrameTask      = max;
 }