Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3385 was 3385, checked in by swagner, 14 years ago

Added base class DeepCloneable again (#975)

File size: 3.6 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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Core {
29  [StorableClass]
30  public sealed class OperationCollection : DeepCloneable, IList<IOperation>, IOperation {
31    [Storable]
32    private IList<IOperation> operations;
33
34    [Storable]
35    private bool parallel;
36    public bool Parallel {
37      get { return parallel; }
38      set { parallel = value; }
39    }
40
41    public OperationCollection() {
42      operations = new List<IOperation>();
43      parallel = false;
44    }
45    public OperationCollection(IEnumerable<IOperation> collection) {
46      operations = new List<IOperation>(collection.Where(e => e != null));
47      parallel = false;
48    }
49    public OperationCollection(params IOperation[] list) {
50      operations = new List<IOperation>(list.Where(e => e != null));
51      parallel = false;
52    }
53
54    public override IDeepCloneable Clone(Cloner cloner) {
55      OperationCollection clone = (OperationCollection)Activator.CreateInstance(this.GetType());
56      cloner.RegisterClonedObject(this, clone);
57      clone.operations = new List<IOperation>(this.Select(x => (IOperation)cloner.Clone(x)));
58      clone.parallel = parallel;
59      return clone;
60    }
61
62    #region IList<IOperation> Members
63    public int IndexOf(IOperation item) {
64      return operations.IndexOf(item);
65    }
66    public void Insert(int index, IOperation item) {
67      if (item != null) operations.Insert(index, item);
68    }
69    public void RemoveAt(int index) {
70      operations.RemoveAt(index);
71    }
72    public IOperation this[int index] {
73      get { return operations[index]; }
74      set { if (value != null) operations[index] = value; }
75    }
76    #endregion
77
78    #region ICollection<IOperation> Members
79    public void Add(IOperation item) {
80      if (item != null) operations.Add(item);
81    }
82    public void Clear() {
83      operations.Clear();
84    }
85    public bool Contains(IOperation item) {
86      return operations.Contains(item);
87    }
88    public void CopyTo(IOperation[] array, int arrayIndex) {
89      operations.CopyTo(array, arrayIndex);
90    }
91    public int Count {
92      get { return operations.Count; }
93    }
94    public bool IsReadOnly {
95      get { return operations.IsReadOnly; }
96    }
97    public bool Remove(IOperation item) {
98      return operations.Remove(item);
99    }
100    #endregion
101
102    #region IEnumerable<IOperation> Members
103    public IEnumerator<IOperation> GetEnumerator() {
104      return operations.GetEnumerator();
105    }
106    #endregion
107
108    #region IEnumerable Members
109    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
110      return operations.GetEnumerator();
111    }
112    #endregion
113  }
114}
Note: See TracBrowser for help on using the repository browser.