Revision 99e6329f trunk/Pithos.Core/Agents/CollectionExtensions.cs

b/trunk/Pithos.Core/Agents/CollectionExtensions.cs
55 55
    /// </summary>
56 56
    public static class CollectionExtensions
57 57
    {
58
        public static IEnumerable<T> Replace<T>(this IEnumerable<T> list,Func<T,bool> match, Func<T,IEnumerable<T>> replace)
59
        {
60
            foreach (var item in list)
61
            {
62
                if (match(item))
63
                    foreach (var newItem in replace(item))
64
                    {
65
                        yield return newItem;
66
                    }
67
                else
68
                    yield return item;
69
            }
70
        }
71

  
72

  
58 73
        /// <summary>
59 74
        /// Remove the first message in a queue that matches the predicate
60 75
        /// </summary>
......
85 100
        }
86 101

  
87 102

  
103
        /// <summary>
104
        /// Return only the info objects that are below one of the filter Uris
105
        /// </summary>
106
        /// <param name="infos">ObjectInfo items to filter</param>
107
        /// <param name="filterUris">List of filter Uris</param>
108
        /// <returns>An enumerable of ObjectInfo items. If the list of filter Uris is empty or null, the original list is returned</returns>
88 109
        public static IEnumerable<ObjectInfo> FilterBelow(this IEnumerable<ObjectInfo> infos,List<Uri> filterUris  )
89 110
        {
90 111
            if (filterUris == null)
......
98 119
            return filteredUris;
99 120
        }
100 121

  
101
        public static IEnumerable<ObjectInfo> FilterDirectlyBelow(this IEnumerable<ObjectInfo> infos,List<Uri> filterUris  )
122
        /// <summary>
123
        /// Return only the info objects that are directly below one of the filter Uris
124
        /// </summary>
125
        /// <param name="infos">ObjectInfo items to filter</param>
126
        /// <param name="filterUris">List of filter Uris</param>
127
        /// <returns>An enumerable of ObjectInfo items. If the list of filter Uris is empty or null, the original list is returned</returns>
128
        public static IEnumerable<ObjectInfo> FilterDirectlyBelow(this IEnumerable<ObjectInfo> infos, List<Uri> filterUris)
102 129
        {
103 130
            if (filterUris == null)
104 131
                return infos;
......
111 138
            return filteredUris;
112 139
        }
113 140

  
141
        /// <summary>
142
        /// Checkes whether a Uri is below a root Uri
143
        /// </summary>
144
        /// <param name="target"></param>
145
        /// <param name="root"></param>
146
        /// <returns></returns>
114 147
        public static bool IsAtOrBelow(this Uri target,Uri root)
115 148
        {
116 149
            Contract.Requires(root != null);
......
137 170
        }
138 171

  
139 172

  
173
        /// <summary>
174
        /// Checks whether a Uri is directly below a root Uri
175
        /// </summary>
176
        /// <param name="target"></param>
177
        /// <param name="root"></param>
178
        /// <returns></returns>
140 179
        public static bool IsAtOrDirectlyBelow(this Uri target,Uri root)
141 180
        {
142 181
            Contract.Requires(root!=null);
......
150 189
                && target.IsAtOrBelow(root);
151 190
        }
152 191

  
192
        /// <summary>
193
        /// Checkes whether a file path is below a root path
194
        /// </summary>
195
        /// <param name="targetPath"></param>
196
        /// <param name="rootPath"></param>
197
        /// <returns></returns>
153 198
        public static bool IsAtOrBelow(this string targetPath, string rootPath)
154 199
        {
155 200
            Contract.Requires(!String.IsNullOrWhiteSpace(targetPath));
......
161 206
            return InnerAtOrBelow(targetSegments, rootSegments);
162 207
        }
163 208

  
209
        /// <summary>
210
        /// Checks whether a file path is directly below a root path
211
        /// </summary>
212
        /// <param name="targetPath"></param>
213
        /// <param name="rootPath"></param>
214
        /// <returns></returns>
164 215
        public static bool IsAtOrDirectlyBelow(this string targetPath, string rootPath)
165 216
        {
166 217
            Contract.Requires(!String.IsNullOrWhiteSpace(targetPath));

Also available in: Unified diff