1 10 package org.jgap.impl; 11 12 import java.io.*; 13 import java.util.*; 14 import org.jgap.*; 15 import org.jgap.util.*; 16 import org.apache.commons.lang.builder.*; 17 18 29 public class ChainOfSelectors 30 implements Serializable, ICloneable, Comparable { 31 32 private final static String CVS_REVISION = "$Revision: 1.13 $"; 33 34 38 private Vector m_selectors; 39 40 public ChainOfSelectors() { 41 m_selectors = new Vector(); 42 } 43 44 53 public void addNaturalSelector(NaturalSelector a_selector) 54 throws InvalidConfigurationException { 55 if (a_selector == null) { 56 throw new InvalidConfigurationException( 57 "This Configuration object is locked. Settings may not be " + 58 "altered."); 59 } 60 m_selectors.add(a_selector); 61 } 62 63 71 public void addAll(Collection a_c) 72 throws InvalidConfigurationException { 73 Iterator it = a_c.iterator(); 74 while (it.hasNext()) { 75 NaturalSelector selector = (NaturalSelector) it.next(); 76 addNaturalSelector(selector); 77 } 78 } 79 80 86 public int size() { 87 return m_selectors.size(); 88 } 89 90 96 public boolean isEmpty() { 97 return size() == 0; 98 } 99 100 public int hashCode() { 101 return m_selectors.hashCode(); 102 } 103 104 112 public boolean equals(final Object a_obj) { 113 try { 114 ChainOfSelectors c2 = (ChainOfSelectors) a_obj; 115 if (c2 == null) { 116 return false; 117 } 118 return m_selectors.equals(c2.m_selectors); 119 } catch (ClassCastException cex) { 120 return false; 121 } 122 } 123 124 133 public NaturalSelector get(final int a_index) { 134 return (NaturalSelector) m_selectors.get(a_index); 135 } 136 137 143 public void clear() { 144 m_selectors.clear(); 145 } 146 147 153 public Iterator iterator() { 154 return m_selectors.iterator(); 155 } 156 157 163 public Object clone() { 164 ChainOfSelectors result = new ChainOfSelectors(); 165 result.m_selectors = (Vector) m_selectors.clone(); 166 return result; 167 } 168 169 178 public int compareTo(Object a_other) { 179 if (a_other == null) { 180 return 1; 181 } 182 else { 183 ChainOfSelectors other = (ChainOfSelectors) a_other; 184 return new CompareToBuilder() 185 .append(m_selectors.toArray(), other.m_selectors.toArray()) 186 .toComparison(); 187 } 188 } 189 } 190 | Popular Tags |