Application breaks when resistance is set to 0 ohms

This commit is contained in:
bancika
2012-03-04 15:09:12 +00:00
parent 4f113f032d
commit 6ca16d07e6
@@ -32,6 +32,25 @@ public class Resistance extends AbstractMeasure<ResistanceUnit> {
public Color[] getColorCode(ResistorColorCode resistorColorCode) { public Color[] getColorCode(ResistorColorCode resistorColorCode) {
Color[] bands; Color[] bands;
if (getValue() == 0) {
switch (resistorColorCode) {
case _4_BAND:
bands = new Color[3];
bands[0] = COLOR_DIGITS[0];
bands[1] = COLOR_DIGITS[0];
bands[2] = COLOR_MULTIPLIER[2];
break;
case _5_BAND:
bands = new Color[4];
bands[0] = COLOR_DIGITS[0];
bands[1] = COLOR_DIGITS[0];
bands[2] = COLOR_DIGITS[0];
bands[3] = COLOR_MULTIPLIER[2];
break;
default:
bands = new Color[] {};
}
} else {
double base = getValue() * getUnit().getFactor(); double base = getValue() * getUnit().getFactor();
int multiplier = 0; int multiplier = 0;
while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) { while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) {
@@ -63,6 +82,7 @@ public class Resistance extends AbstractMeasure<ResistanceUnit> {
default: default:
bands = new Color[] {}; bands = new Color[] {};
} }
}
return bands; return bands;
} }