mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Application breaks when resistance is set to 0 ohms
This commit is contained in:
+50
-30
@@ -32,36 +32,56 @@ public class Resistance extends AbstractMeasure<ResistanceUnit> {
|
|||||||
|
|
||||||
public Color[] getColorCode(ResistorColorCode resistorColorCode) {
|
public Color[] getColorCode(ResistorColorCode resistorColorCode) {
|
||||||
Color[] bands;
|
Color[] bands;
|
||||||
double base = getValue() * getUnit().getFactor();
|
if (getValue() == 0) {
|
||||||
int multiplier = 0;
|
switch (resistorColorCode) {
|
||||||
while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) {
|
case _4_BAND:
|
||||||
multiplier += 1;
|
bands = new Color[3];
|
||||||
base /= 10;
|
bands[0] = COLOR_DIGITS[0];
|
||||||
}
|
bands[1] = COLOR_DIGITS[0];
|
||||||
while (base < (resistorColorCode == ResistorColorCode._4_BAND ? 10 : 100)) {
|
bands[2] = COLOR_MULTIPLIER[2];
|
||||||
multiplier -= 1;
|
break;
|
||||||
base *= 10;
|
case _5_BAND:
|
||||||
}
|
bands = new Color[4];
|
||||||
if (multiplier > 6 || multiplier < -2) {
|
bands[0] = COLOR_DIGITS[0];
|
||||||
// Out of range.
|
bands[1] = COLOR_DIGITS[0];
|
||||||
return new Color[] {};
|
bands[2] = COLOR_DIGITS[0];
|
||||||
}
|
bands[3] = COLOR_MULTIPLIER[2];
|
||||||
switch (resistorColorCode) {
|
break;
|
||||||
case _4_BAND:
|
default:
|
||||||
bands = new Color[3];
|
bands = new Color[] {};
|
||||||
bands[0] = COLOR_DIGITS[(int) (base / 10)];
|
}
|
||||||
bands[1] = COLOR_DIGITS[(int) (base % 10)];
|
} else {
|
||||||
bands[2] = COLOR_MULTIPLIER[multiplier + 2];
|
double base = getValue() * getUnit().getFactor();
|
||||||
break;
|
int multiplier = 0;
|
||||||
case _5_BAND:
|
while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) {
|
||||||
bands = new Color[4];
|
multiplier += 1;
|
||||||
bands[0] = COLOR_DIGITS[(int) (base / 100)];
|
base /= 10;
|
||||||
bands[1] = COLOR_DIGITS[(int) (base / 10 % 10)];
|
}
|
||||||
bands[2] = COLOR_DIGITS[(int) (base % 10)];
|
while (base < (resistorColorCode == ResistorColorCode._4_BAND ? 10 : 100)) {
|
||||||
bands[3] = COLOR_MULTIPLIER[multiplier + 2];
|
multiplier -= 1;
|
||||||
break;
|
base *= 10;
|
||||||
default:
|
}
|
||||||
bands = new Color[] {};
|
if (multiplier > 6 || multiplier < -2) {
|
||||||
|
// Out of range.
|
||||||
|
return new Color[] {};
|
||||||
|
}
|
||||||
|
switch (resistorColorCode) {
|
||||||
|
case _4_BAND:
|
||||||
|
bands = new Color[3];
|
||||||
|
bands[0] = COLOR_DIGITS[(int) (base / 10)];
|
||||||
|
bands[1] = COLOR_DIGITS[(int) (base % 10)];
|
||||||
|
bands[2] = COLOR_MULTIPLIER[multiplier + 2];
|
||||||
|
break;
|
||||||
|
case _5_BAND:
|
||||||
|
bands = new Color[4];
|
||||||
|
bands[0] = COLOR_DIGITS[(int) (base / 100)];
|
||||||
|
bands[1] = COLOR_DIGITS[(int) (base / 10 % 10)];
|
||||||
|
bands[2] = COLOR_DIGITS[(int) (base % 10)];
|
||||||
|
bands[3] = COLOR_MULTIPLIER[multiplier + 2];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bands = new Color[] {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bands;
|
return bands;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user