| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
package org.jfree.data.som; |
| 28 | |
|
| 29 | |
import java.awt.Color; |
| 30 | |
import java.io.Serializable; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class SOMDataItem implements Cloneable, Serializable { |
| 39 | |
|
| 40 | |
|
| 41 | |
private Color color; |
| 42 | |
|
| 43 | |
|
| 44 | |
private String[] descriptions; |
| 45 | |
|
| 46 | |
|
| 47 | |
private double[] neuronWeights; |
| 48 | |
|
| 49 | |
|
| 50 | |
private boolean selected; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public SOMDataItem(Color color, String descriptions[], double[] neuronWeights) |
| 63 | 163 | throws NullPointerException { |
| 64 | 163 | if (color == null || descriptions == null || neuronWeights == null) |
| 65 | 3 | throw new NullPointerException("color/descriptions/neuronWeights given to SOMDataItem was null."); |
| 66 | 160 | if (descriptions.length == 0) |
| 67 | 1 | throw new IllegalArgumentException("descriptions given to SOMDataItem did not contain any strings."); |
| 68 | 159 | if (neuronWeights.length == 0) |
| 69 | 1 | throw new IllegalArgumentException("neuronWeights given to SOMDataItem did not contain any values."); |
| 70 | 158 | this.color = color; |
| 71 | 158 | this.descriptions = descriptions; |
| 72 | 158 | this.neuronWeights = neuronWeights; |
| 73 | 158 | this.selected = false; |
| 74 | 158 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public Color getColor() { |
| 82 | 198 | return color; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
public String[] getDescriptions() { |
| 91 | 108 | return descriptions; |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
public double[] getNeuronWeights() { |
| 100 | 18 | return neuronWeights; |
| 101 | |
} |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public void setColor(Color color) { |
| 109 | 46 | if (color == null) |
| 110 | 1 | throw new NullPointerException("color given to setColor() was null."); |
| 111 | 45 | this.color = color; |
| 112 | 45 | } |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
public void setDescriptions(String[] descriptions) { |
| 120 | 2 | if (descriptions == null) |
| 121 | 1 | throw new NullPointerException("descriptions given to setDescriptions() was null."); |
| 122 | 1 | this.descriptions = descriptions; |
| 123 | 1 | } |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
public void setNeuronWeights(double[] neuronWeights) { |
| 131 | 2 | if (neuronWeights == null) |
| 132 | 1 | throw new NullPointerException("neuronWeights given to setNeuronWeights() was null."); |
| 133 | 1 | this.neuronWeights = neuronWeights; |
| 134 | 1 | } |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
public boolean isSelected() { |
| 143 | 104 | return selected; |
| 144 | |
} |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public void setSelected(boolean selected) { |
| 153 | 96 | this.selected = selected; |
| 154 | 96 | } |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
public boolean equals(Object obj) { |
| 164 | 60 | if (obj == this) { |
| 165 | 25 | return true; |
| 166 | |
} |
| 167 | |
|
| 168 | 35 | if (!(obj instanceof SOMDataItem)) { |
| 169 | 1 | return false; |
| 170 | |
} |
| 171 | |
|
| 172 | 34 | SOMDataItem that = (SOMDataItem) obj; |
| 173 | |
|
| 174 | 34 | if (this.color.equals(that.color) == false) |
| 175 | 12 | return false; |
| 176 | |
|
| 177 | 22 | if (this.selected != that.selected) |
| 178 | 1 | return false; |
| 179 | |
|
| 180 | 21 | if (this.descriptions.length != that.descriptions.length) |
| 181 | 4 | return false; |
| 182 | |
|
| 183 | 44 | for (int i=0; i < this.descriptions.length; ++i) { |
| 184 | 31 | if (this.descriptions[i] == null && that.descriptions[i] == null) { |
| 185 | |
; |
| 186 | 1 | } |
| 187 | 30 | else if (this.descriptions[i] == null || |
| 188 | |
that.descriptions[i] == null || |
| 189 | |
this.descriptions[i].equals(that.descriptions[i]) == false) |
| 190 | 4 | return false; |
| 191 | |
} |
| 192 | |
|
| 193 | 13 | if (this.neuronWeights.length != that.neuronWeights.length) |
| 194 | 2 | return false; |
| 195 | |
|
| 196 | 34 | for (int i=0; i < this.neuronWeights.length; ++i) { |
| 197 | 25 | if (this.neuronWeights[i] != that.neuronWeights[i]) |
| 198 | 2 | return false; |
| 199 | |
} |
| 200 | |
|
| 201 | 9 | return true; |
| 202 | |
} |
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
public Object clone() throws CloneNotSupportedException { |
| 213 | 1 | SOMDataItem clone = (SOMDataItem) super.clone(); |
| 214 | 1 | clone.descriptions = (String[]) this.descriptions.clone(); |
| 215 | 1 | clone.neuronWeights = (double[]) this.neuronWeights.clone(); |
| 216 | 1 | return clone; |
| 217 | |
} |
| 218 | |
|
| 219 | |
} |
| 220 | |
|