Ejemplo n.º 1
0
        /// <summary>
        /// Returns a new OrderedMap containing all the keys of this OrderedMap.
        /// </summary>
        /// <param name="filter">A value used to filter the keys for the specified value. If null, no filtering is done.</param>
        /// <returns>Returns a new OrderedMap with the keys of this OrderedMap.</returns>
        public OrderedMap GetKeysOrderedMap(object filter)
        {
            OrderedMap newOrderedMap = null;

            if (this.Count > 0)
            {
                newOrderedMap = new OrderedMap();
                foreach (string theKey in this.Keys)
                {
                    if (filter == null)
                        newOrderedMap[null] = theKey;
                    else
                    {
                        if (this[theKey].ToString().Equals(filter.ToString()))
                            newOrderedMap[null] = theKey;
                    }
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 /// <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;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a new OrderedMap that represents a slice of the specified OrderedMap.
        /// </summary>
        /// <param name="input">The OrderedMap to extract the slice from.</param>
        /// <param name="offset">The starting position of the slice.</param>
        /// <param name="length">The length of the slice.</param>
        /// <returns>Returns a new OrderedMap that represents a slice of the specified OrderedMap.</returns>
        public static OrderedMap Slice(OrderedMap input, int offset, int length)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();

                int theOffset = offset, theLength = length;
                _GetAbsPositions(ref theOffset, ref theLength, input.Count);
                for (int index = theOffset; index < theOffset + theLength; index++)
                {
                    System.Collections.DictionaryEntry entry = input.GetEntryAt(index);

                    if (OrderedMap.IsKeyInteger((string) entry.Key))
                        newOrderedMap[null] = entry.Value;
                    else
                        newOrderedMap[entry.Key] = entry.Value;
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Sorts by key the specified OrderedMap and reverses it. The existing keys are preserved.
 /// </summary>
 /// <param name="input">The OrderedMap to be sorted.</param>
 /// <param name="sortFlags">The sorting options (SORTREGULAR, SORTNUMERIC, SORTSTRING).</param>
 public static void SortKeyPreserveReverse(ref OrderedMap input, int sortFlags)
 {
     OrderedMap.Sort(ref input, sortFlags, true, false, null, null);
     input = OrderedMap.Reverse(input, true);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Reverses the specified OrderedMap, if <code>preserveKeys</code> is true, the original keys will be used.
        /// </summary>
        /// <param name="input">The OrderedMap that will be reversed.</param>
        /// <param name="preserveKeys">The boolean value that indicates whether to preserve the original keys or auto-generate new keys.</param>
        /// <returns>Returns a new reversed OrderedMap.</returns>
        public static OrderedMap Reverse(OrderedMap input, bool preserveKeys)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();
                for (int index = input.Count - 1; index >= 0; index--)
                {
                    System.Collections.DictionaryEntry entry = input.GetEntryAt(index);
                    if (preserveKeys)
                        newOrderedMap[entry.Key] = entry.Value;
                    else
                    {
                        if (IsKeyInteger(entry.Key.ToString()))
                            newOrderedMap[null] = entry.Value;
                        else
                            newOrderedMap[entry.Key] = entry.Value;
                    }
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Randomizes the order of the elements in the specified OrderedMap.
 /// </summary>
 /// <param name="input">The OrderedMap to be randomly re-ordered.</param>
 public static void Shuffle(ref OrderedMap input)
 {
     OrderedMap.SortValueUser(ref input, "RamdomCompare", input);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Splits the specified OrderedMap into chunks
        /// </summary>
        /// <param name="input">The OrderedMap to be splitted.</param>
        /// <param name="size">The size of each chunk.</param>
        /// <param name="preserveKeys">If true, the original keys will be preserved, otherwise new integer indices will be used.</param>
        /// <returns>Returns a new OrderedMap containing all the chunks.</returns>
        public static OrderedMap Chunk(OrderedMap input, int size, bool preserveKeys)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();
                int totalChunks = input.Count/size;
                totalChunks += (input.Count%size) > 0 ? 1 : 0;
                for (int index = 0; index < totalChunks; index++)
                {
                    OrderedMap theChunk = new OrderedMap();
                    for (int chunkIndex = 0; chunkIndex < size; chunkIndex++)
                    {
                        if ((index*size) + chunkIndex < input.Count)
                        {
                            string key = "";
                            if (preserveKeys)
                                key = input.GetKeyAt((index*size) + chunkIndex);
                            else
                                key = chunkIndex.ToString();

                            theChunk[key] = input.GetValueAt((index*size) + chunkIndex);
                        }
                        else
                            break;
                    }
                    newOrderedMap[index] = theChunk;
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Counts all the values of the specified OrderedMap.
        /// </summary>
        /// <param name="input">The OrderedMap that contains the values to be counted.</param>
        /// <returns>Returns a new OrderedMap which contains the values and their frecuency.</returns>
        public static OrderedMap CountValues(OrderedMap input)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();
                foreach (object theValue in input.Values)
                {
                    if (newOrderedMap[theValue] != null)
                        newOrderedMap[theValue] = ((int) newOrderedMap[theValue]) + 1;
                    else
                        newOrderedMap[theValue] = 1;
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Appends the contents of the second OrderedMap to the first OrderedMap into a new OrderedMap. 
        /// </summary>
        /// <param name="input1">The first OrderedMap.</param>
        /// <param name="input2">The second OrderedMap to be appended.</param>
        /// <returns>Returns a new OrderedMap with the appended OrderedMaps.</returns>
        public static OrderedMap Append(OrderedMap input1, OrderedMap input2)
        {
            OrderedMap newOrderedMap = null;

            //if at least one of the OrderedMaps is not null
            if (input1 != null || input2 != null)
            {
                newOrderedMap = new OrderedMap();
                if (input1 != null)
                    newOrderedMap = new OrderedMap(input1, false);

                if (input2 != null)
                {
                    foreach (string key in input2.Keys)
                    {
                        if (newOrderedMap[key] == null)
                            newOrderedMap[key] = input2[key];
                    }
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Changes the case of all string keys of the specified OrderedMap.
        /// </summary>
        /// <param name="input">The OrderedMap that contains the keys to be changed.</param>
        /// <param name="arrayCase">Indicates whether to change the keys to lowercase (0) or to uppercase (any other integer value)</param>
        /// <returns>Returns a new OrderedMap with all string keys lowercased or uppercased.</returns>
        public static OrderedMap ChangeCase(OrderedMap input, int arrayCase)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();
                foreach (string key in input.Keys)
                {
                    string newKey = key;
                    newKey = (arrayCase == 0 ? key.ToLower() : key.ToUpper());
                    newOrderedMap[newKey] = input[key];
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets a value in a multidimensional OrderedMap. 
        /// </summary>
        /// <param name="args">The parameter <code>args</code> is an array of objects with the following form:
        /// args(value, key1, ..., keyn-1, keyn). Where value (the first element) is the value to be set, the rest of the elements
        /// are the keys, each key represents a dimension. 
        /// For instance, a PHP source code that look like this: <code>arr[1][3][4][6] = "value";</code> would be converted using this method
        /// like this: <code>arr.SetValue("value", 1, 3, 4, 6);</code>.</param>
        public void SetValue(params object[] args)
        {
            if (args.Length < 2) return;
            if (args.Length == 2)
            {
                this[args[1]] = args[0];
                return;
            }

            //if there are at least two indexers go on.

            string theKey = "";
            //loop over the specified keys creating new OrderedMaps (i.e. dimensions) when necessary.
            OrderedMap currentOrderedMap = this;
            for (int index = 1; index < args.Length - 1; index++)
            {
                //if a key is not specified (null), it should be calculated.
                theKey = args[index] == null ? currentOrderedMap._GetMaxIntegerKey() : args[index].ToString();

                if (currentOrderedMap[theKey] == null)
                {
                    //specified element does not exist, create a new OrderedMap (i.e. a new dimension).
                    currentOrderedMap[theKey] = new OrderedMap();
                }
                else
                {
                    //current element already exists in OrderedMap.
                    if (currentOrderedMap[theKey] is string)
                    {
                        //current element is not a OrderedMap but a string. If possible, change the string value and return.
                        object newValue;
                        if (index == args.Length - 1)
                        {
                            //the string value should be changed by the new value.
                            newValue = args[0];
                        }
                        else if (index == args.Length - 2)
                        {
                            newValue = this._ReplaceCharAt((string) currentOrderedMap[theKey], (int) args[index + 1],
                                                           args[0].ToString()[0]);
                        }
                        else
                        {
                            //the indexers are not valid in the string value, ignore this case and return.
                            return;
                        }

                        //update the string value and return.
                        currentOrderedMap[theKey] = newValue;
                        return;
                    }
                    else
                    {
                        if (!(currentOrderedMap[theKey] is OrderedMap))
                        {
                            //current element is not a string nor an OrderedMap. It is not possible to use that element as an array.
                            throw new System.Exception("Warning: Cannot use a scalar value as an array");
                        }
                    }
                }

                //move to next dimension, current element is an OrderedMap (either a new or an existing one).
                currentOrderedMap = (OrderedMap) currentOrderedMap[theKey];
            } //end for

            //current OrderedMap represents the last dimension, set a new entry in the current OrderedMap,
            //formed by the last key (if any) and the specified value.
            currentOrderedMap[args[args.Length - 1]] = args[0];
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns a new OrderedMap containing all the values of this OrderedMap.
 /// </summary>
 /// <returns></returns>
 public OrderedMap GetValuesOrderedMap()
 {
     OrderedMap newOrderedMap = null;
     if (this.Count > 0)
     {
         newOrderedMap = new OrderedMap(this.Values, false);
     }
     return newOrderedMap;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Returns an OrderedMap containing randomly-choosen keys from this OrderedMap.
 /// </summary>
 /// <param name="numKeys">The number of keys to obtain.</param>
 /// <returns>Returns a new OrderedMap containing randomly-choosen keys.</returns>
 public OrderedMap GetRandomKeys(int numKeys)
 {
     OrderedMap newOrderedMap = null;
     if (this.Count > 0)
     {
         newOrderedMap = new OrderedMap();
         System.Random random = new System.Random();
         for (int index = 0; index < numKeys; index++)
         {
             int randKeyIndex = random.Next(this.Count - 1);
             newOrderedMap[null] = this.GetKeyAt(randKeyIndex);
         }
     }
     return newOrderedMap;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Pads de specified OrderedMap with the specified pad value. 
        /// If <code>padSize</code> is negative, then the OrderedMap will be left-padded, otherwise it will be right-paddded.
        /// </summary>
        /// <param name="input">The OrderedMap that will be use to do the padding.</param>
        /// <param name="padSize">The padding size.</param>
        /// <param name="padValue">The value used to pad.</param>
        /// <returns>Returns a new paddde OrderedMap.</returns>
        public static OrderedMap Pad(OrderedMap input, int padSize, object padValue)
        {
            OrderedMap newOrderedMap = null;
            if (input != null && input.Count > 0)
            {
                int absSize = System.Math.Abs(padSize);
                if (absSize > input.Count)
                {
                    int toPad = absSize - input.Count;
                    if (padSize > 0)
                    {
                        newOrderedMap = new OrderedMap();
                        foreach (string key in input.Keys)
                        {
                            if (IsKeyInteger(key))
                                newOrderedMap[null] = input[key];
                            else
                                newOrderedMap[key] = input[key];
                        }

                        for (int index = 0; index < toPad; index++)
                        {
                            newOrderedMap[null] = padValue;
                        }
                    }
                    else
                    {
                        newOrderedMap = new OrderedMap();
                        for (int index = 0; index < toPad; index++)
                        {
                            newOrderedMap[null] = padValue;
                        }
                        newOrderedMap = OrderedMap.Merge(newOrderedMap, input);
                    }
                }
                else
                {
                    newOrderedMap = new OrderedMap(input, false);
                }
            }

            return newOrderedMap;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a new OrderedMap with a consecutive range of numbers.
        /// </summary>
        /// <param name="low">The first value of the range.</param>
        /// <param name="high">The last value of the range.</param>
        /// <returns>Returns a new OrderedMap with a consecutive range of numbers.</returns>
        public static OrderedMap CreateRange(int low, int high)
        {
            OrderedMap newOrderedMap = new OrderedMap();
            bool increment = high >= low ? true : false;

            for (int index = low; increment ? index <= high : index >= high; index += increment ? 1 : -1)
            {
                newOrderedMap[null] = index;
            }
            return newOrderedMap;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Reduces the specified OrderedMap to a single value using a callback function.
        /// </summary>
        /// <param name="input">The OrderedMap that contains the values to be reduced.</param>
        /// <param name="methodName">The method name to use for reduction.</param>
        /// <param name="initial">The initial value of the resulting reduced value.</param>
        /// <param name="instance">The instance that contains the definition of the method used for reduction.</param>
        /// <returns>Returns a single value which represents the reduction of the OrderedMap according to the specified callback method.</returns>
        public static double Reduce(OrderedMap input, string methodName, int initial, object instance)
        {
            double result = initial;

            if (input != null && input.Count > 0)
            {
                try
                {
                    System.Type theType = instance.GetType();
                    System.Reflection.MethodInfo callbackMethod = theType.GetMethod(methodName);

                    if (input != null && input.Count > 0)
                    {
                        object[] parameters = new object[] {initial, input.GetValueAt(0)};
                        result = (double) callbackMethod.Invoke(instance, parameters);
                        for (int index = 1; index < input.Count; index++)
                        {
                            object theValue = input.GetValueAt(index);
                            if (System.Text.RegularExpressions.Regex.IsMatch(theValue.ToString(),
                                                                             OrderedMap._NUMBERREGULAREXPRESSION))
                            {
                                parameters[0] = result;
                                parameters[1] = theValue;
                                result = (double) callbackMethod.Invoke(instance, parameters);
                            }
                        }
                    }
                }
                catch (System.Exception exception)
                {
                    throw exception;
                }
            }

            return result;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates a new OrderedMap with a consecutive range of characters (actually strings are used for compatibility).
        /// </summary>
        /// <param name="lowChar">The first value of the range.</param>
        /// <param name="highChar">The last value of the range.</param>
        /// <returns>Returns a new OrderedMap with a consecutive range of characters.</returns>
        public static OrderedMap CreateRange(string lowChar, string highChar)
        {
            OrderedMap newOrderedMap = new OrderedMap();
            int lowCharInt = (int) lowChar[0], highCharInt = (int) highChar[0];
            bool increment = highCharInt >= lowCharInt ? true : false;

            for (int index = lowCharInt;
                 increment ? index <= highCharInt : index >= highCharInt;
                 index += increment ? 1 : -1)
            {
                newOrderedMap[null] = new string(new char[] {(char) index});
            }
            return newOrderedMap;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Shifts (removes) the first element of the specified OrderedMap and returns the value. All the numeric keys are recalculated.
 /// </summary>
 /// <param name="input">The OrderedMap that will be shifted.</param>
 /// <returns>Returns the element that was removed from the specified OrderedMap.</returns>
 public static object Shift(ref OrderedMap input)
 {
     object result = null;
     if (input.Count > 0)
     {
         OrderedMap newOrderedMap = new OrderedMap();
         result = input.GetValueAt(0);
         input.RemoveAt(0);
         foreach (string key in input.Keys)
         {
             if (OrderedMap.IsKeyInteger(key))
                 newOrderedMap[null] = input[key];
             else
                 newOrderedMap[key] = input[key];
         }
         input = newOrderedMap;
         input.Reset();
     }
     return result;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates a new OrderedMap and fills it with the specified value.
 /// </summary>
 /// <param name="startIndex">The index used to calculate the keys.</param>
 /// <param name="num">The number of entries of the value.</param>
 /// <param name="theValue">The value to fill the OrderedMap with.</param>
 /// <returns>Returns a new OrderedMap filled with the specified value.</returns>
 public static OrderedMap Fill(int startIndex, int num, object theValue)
 {
     OrderedMap newOrderedMap = new OrderedMap();
     for (int index = startIndex; index < startIndex + num; index++)
         newOrderedMap[index] = theValue;
     return newOrderedMap;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Returns a new OrderedMap that represents a slice of the specified OrderedMap.
 /// </summary>
 /// <param name="input">The OrderedMap to extract the slice from.</param>
 /// <param name="offset">The starting position of the slice.</param>
 /// <returns>Returns a new OrderedMap that represents a slice of the specified OrderedMap.</returns>
 public static OrderedMap Slice(OrderedMap input, int offset)
 {
     return OrderedMap.Slice(input, offset, input.Count);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Filters the elements of the specified OrderedMap using the specified method that belongs to the specified instance.
        /// </summary>
        /// <param name="input">The Ordered to be filtered.</param>
        /// <param name="functionName">The callback method used to filter the OrderedMap.</param>
        /// <param name="instance">The instance which defines the callback method.</param>
        /// <returns>Returns a new OrderedMap with the filtered elements.</returns>
        public static OrderedMap Filter(OrderedMap input, string methodName, object instance)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                if (methodName == null)
                {
                    //No filter is needed.
                    newOrderedMap = new OrderedMap(input, false);
                }
                else
                {
                    try
                    {
                        newOrderedMap = new OrderedMap();
                        System.Type theType = instance.GetType();
                        System.Reflection.MethodInfo callbackMethod = theType.GetMethod(methodName);

                        foreach (string theKey in input.Keys)
                        {
                            if ((bool) callbackMethod.Invoke(instance, new object[] {input[theKey]}))
                                newOrderedMap[theKey] = input[theKey];
                        }
                    }
                    catch (System.Exception exception)
                    {
                        throw exception;
                    }
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Sorts the specified OrderedMap according to the rest of the arguments.
        /// The basic functionality of the sorting mechanism is:
        /// 1. An ArrayList is created using the specified OrderedMap, each ArrayList element is an OrderedMapSortItem (that represent an entry of the OrderedMap).
        /// 2. The method ArrayList.Sort of the just created ArrayList is called.
        /// 3. Since the OrderedMapSortItem class implements the System.IComparable interface, the ArrayList is sorted using that interface of each element.
        /// 4. An sorted-OrderedMap is then created and returned.
        /// </summary>
        /// <param name="input">The OrderedMap to be sorted.</param>
        /// <param name="sortFlags">The sorting options (SORTREGULAR, SORTNUMERIC, SORTSTRING).</param>
        /// <param name="preserveKeys">The boolean value that indicates whether to preserve the original keys (true) or not (false).</param>
        /// <param name="byValue">The value that indicates whether to sort the item by its value (true) or by its key (false).</param>
        /// <param name="methodName">The name of the user-defined method that will be used as comparing method.</param>
        /// <param name="instance">The instance of the class that defines the user-defined method that will be used as comparing method.</param>
        /// <remarks>If predefined sorting mechanisms need to be used (that is SORTREGULAR, SORTNUMERIC, SORTSTRING), then
        ///  the parameters <code>methodName</code> and <code>instance</code> can be null.</remarks>
        public static void Sort(ref OrderedMap input, int sortFlags, bool preserveKeys, bool byValue, string methodName,
                                object instance)
        {
            System.Collections.ArrayList sortedOrderedMap = new System.Collections.ArrayList();
            foreach (string key in input.Keys)
            {
                OrderedMapSortItem item = null;
                if ((methodName == null || methodName == "") && instance == null)
                    item = new OrderedMapSortItem(key, input[key], sortFlags, byValue);
                else
                    item = new OrderedMapSortItem(key, input[key], byValue, methodName, instance);

                sortedOrderedMap.Add(item);
            }

            sortedOrderedMap.Sort();

            OrderedMap newOrderedMap = new OrderedMap();
            for (int index = 0; index < sortedOrderedMap.Count; index++)
            {
                OrderedMapSortItem entry = (OrderedMapSortItem) sortedOrderedMap[index];
                if (preserveKeys)
                    newOrderedMap[entry.Key] = entry.Value;
                else
                    newOrderedMap[null] = entry.Value;
            }

            newOrderedMap._index = input._index;
            input = newOrderedMap;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Exchanges all keys in the OrderedMap with their associated values.
        /// </summary>
        /// <param name="toTransform">The OrderedMap that contains the keys and values to be exchanged.</param>
        /// <returns>Returns a new exchanged OrderedMap.</returns>
        public static OrderedMap Flip(OrderedMap toTransform)
        {
            OrderedMap newOrderedMap = null;

            if (toTransform != null && toTransform.Count > 0)
            {
                try
                {
                    newOrderedMap = new OrderedMap();
                    foreach (string key in toTransform.Keys)
                    {
                        newOrderedMap[toTransform[key]] = key;
                    }
                }
                catch (System.Exception exception)
                {
                    throw exception;
                }
            }

            return newOrderedMap;
        }
Ejemplo n.º 25
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;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Computes the intersection of two OrderedMaps with extra key checking.
 /// That is, elements and keys of the first OrderedMap present in the second OrderedMap.
 /// </summary>
 /// <param name="input1">The OrderedMap that contains the entries to be searched.</param>
 /// <param name="input2">The OrderedMap where the entries of the first element will be searched.</param>
 /// <returns>Returns a new OrderedMap that contains the entries of the first OrderedMap present in the second OrderedMap.</returns>
 public static OrderedMap IntersectionWithKey(OrderedMap input1, OrderedMap input2)
 {
     OrderedMap newOrderedMap = null;
     for (int index = 0; index < input1.Count; index++)
     {
         System.Collections.DictionaryEntry entry = input1.GetEntryAt(index);
         if (input2.SearchStringRepresentation(entry) != -1)
         {
             if (newOrderedMap == null) newOrderedMap = new OrderedMap();
             newOrderedMap[entry.Key] = entry.Value;
         }
     }
     return newOrderedMap;
 }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Merges the contents of the first OrderedMap with the contents of the second OrderedMap into a new OrderedMap. 
        /// </summary>
        /// <param name="input1">The first OrderedMap to be merged.</param>
        /// <param name="input2">The second OrderedMap to be merged.</param>
        /// <returns>Returns a new OrderedMap with the merged OrderedMaps.</returns>
        public static OrderedMap Merge(OrderedMap input1, OrderedMap input2)
        {
            OrderedMap newOrderedMap = null;

            //if at least one of the OrderedMaps is not null
            if (input1 != null || input2 != null)
            {
                newOrderedMap = new OrderedMap();
                if (input1 != null)
                {
                    foreach (string key in input1.Keys)
                    {
                        if (IsKeyInteger(key))
                            newOrderedMap[null] = input1[key];
                        else
                            newOrderedMap[key] = input1[key];
                    }
                }

                if (input2 != null)
                {
                    foreach (string key in input2.Keys)
                    {
                        if (IsKeyInteger(key))
                            newOrderedMap[null] = input2[key];
                        else
                            newOrderedMap[key] = input2[key];
                    }
                }
            }
            return newOrderedMap;
        }
Ejemplo n.º 29
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;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Returns the current key and value pair of this OrderedMap and advances the internal index by one.
        /// </summary>
        /// <returns>Returns the current key and value pair from this OrderedMap</returns>
        public OrderedMap Each()
        {
            OrderedMap each = null;
            if ((this._index < this.Count) && (this._index >= 0))
            {
                DictionaryEntry entry = this.GetEntryAt(this._index);
                each = new OrderedMap(
                    new object[] {1, entry.Value},
                    new object[] {"value", entry.Value},
                    new object[] {0, entry.Key},
                    new object[] {"key", entry.Key});

                this._index++;
            }
            return each;
        }