Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3782 was 3390, checked in by swagner, 15 years ago

Refactored HeuristicLab.Collections (#977)

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