Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/OperationCollection.cs @ 2875

Last change on this file since 2875 was 2834, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • worked on operators, engines, and optimization
File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25
26namespace HeuristicLab.Core {
27  public class OperationCollection : DeepCloneable, IList<IOperation>, IOperation {
28    [Storable]
29    private IList<IOperation> operations;
30
31    [Storable]
32    private bool parallel;
33    public bool Parallel {
34      get { return parallel; }
35      set { parallel = value; }
36    }
37
38    public OperationCollection() {
39      operations = new List<IOperation>();
40      parallel = false;
41    }
42    public OperationCollection(IEnumerable<IOperation> collection) {
43      operations = new List<IOperation>(collection.Where(e => e != null));
44      parallel = false;
45    }
46    public OperationCollection(params IOperation[] list) {
47      operations = new List<IOperation>(list.Where(e => e != null));
48      parallel = false;
49    }
50
51    public override IDeepCloneable Clone(Cloner cloner) {
52      OperationCollection clone = new OperationCollection(this.Select(x => (IOperation)cloner.Clone(x)));
53      cloner.RegisterClonedObject(this, clone);
54      clone.parallel = parallel;
55      return clone;
56    }
57
58    #region IList<IOperation> Members
59    public int IndexOf(IOperation item) {
60      return operations.IndexOf(item);
61    }
62    public void Insert(int index, IOperation item) {
63      if (item != null) operations.Insert(index, item);
64    }
65    public void RemoveAt(int index) {
66      operations.RemoveAt(index);
67    }
68    public IOperation this[int index] {
69      get { return operations[index]; }
70      set { if (value != null) operations[index] = value; }
71    }
72    #endregion
73
74    #region ICollection<IOperation> Members
75    public void Add(IOperation item) {
76      if (item != null) operations.Add(item);
77    }
78    public void Clear() {
79      operations.Clear();
80    }
81    public bool Contains(IOperation item) {
82      return operations.Contains(item);
83    }
84    public void CopyTo(IOperation[] array, int arrayIndex) {
85      operations.CopyTo(array, arrayIndex);
86    }
87    public int Count {
88      get { return operations.Count; }
89    }
90    public bool IsReadOnly {
91      get { return operations.IsReadOnly; }
92    }
93    public bool Remove(IOperation item) {
94      return operations.Remove(item);
95    }
96    #endregion
97
98    #region IEnumerable<IOperation> Members
99    public IEnumerator<IOperation> GetEnumerator() {
100      return operations.GetEnumerator();
101    }
102    #endregion
103
104    #region IEnumerable Members
105    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
106      return operations.GetEnumerator();
107    }
108    #endregion
109  }
110}
Note: See TracBrowser for help on using the repository browser.