mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
improve V1 parsing
This commit is contained in:
@@ -85,4 +85,11 @@ public class AbstractMeasure<T extends Enum<? extends Unit>> implements Serializ
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return format.format(value) + unit;
|
return format.format(value) + unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static double parse(String value) {
|
||||||
|
if (value.startsWith("."))
|
||||||
|
value = "0" + value;
|
||||||
|
value = value.replace(",", ".").replace("*", "");
|
||||||
|
return Double.parseDouble(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ public class Capacitance extends AbstractMeasure<CapacitanceUnit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Capacitance parseCapacitance(String value) {
|
public static Capacitance parseCapacitance(String value) {
|
||||||
|
value = value.replace("*", "");
|
||||||
for (CapacitanceUnit unit : CapacitanceUnit.values()) {
|
for (CapacitanceUnit unit : CapacitanceUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
||||||
value = value.substring(0, value.length() - unit.toString().length() - 1).trim();
|
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
||||||
return new Capacitance(Double.parseDouble(value), unit);
|
return new Capacitance(parse(value), unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not parse capacitance: " + value);
|
throw new IllegalArgumentException("Could not parse capacitance: " + value);
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ public class Inductance extends AbstractMeasure<InductanceUnit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Inductance parseCapacitance(String value) {
|
public static Inductance parseCapacitance(String value) {
|
||||||
|
value = value.replace("*", "");
|
||||||
for (InductanceUnit unit : InductanceUnit.values()) {
|
for (InductanceUnit unit : InductanceUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
||||||
value = value.substring(0, value.length() - unit.toString().length() - 1).trim();
|
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
||||||
return new Inductance(Double.parseDouble(value), unit);
|
return new Inductance(parse(value), unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not parse inductance: " + value);
|
throw new IllegalArgumentException("Could not parse inductance: " + value);
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ public class Power extends AbstractMeasure<PowerUnit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Power parseCapacitance(String value) {
|
public static Power parseCapacitance(String value) {
|
||||||
|
value = value.replace("*", "");
|
||||||
for (PowerUnit unit : PowerUnit.values()) {
|
for (PowerUnit unit : PowerUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
||||||
value = value.substring(0, value.length() - unit.toString().length() - 1).trim();
|
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
||||||
return new Power(Double.parseDouble(value), unit);
|
return new Power(parse(value), unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not parse power: " + value);
|
throw new IllegalArgumentException("Could not parse power: " + value);
|
||||||
|
|||||||
@@ -88,10 +88,11 @@ public class Resistance extends AbstractMeasure<ResistanceUnit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Resistance parseResistance(String value) {
|
public static Resistance parseResistance(String value) {
|
||||||
|
value = value.replace("*", "").replace("R", "\u2126");
|
||||||
for (ResistanceUnit unit : ResistanceUnit.values()) {
|
for (ResistanceUnit unit : ResistanceUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
||||||
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
||||||
return new Resistance(Double.parseDouble(value), unit);
|
return new Resistance(parse(value), unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not parse resistance: " + value);
|
throw new IllegalArgumentException("Could not parse resistance: " + value);
|
||||||
|
|||||||
@@ -31,10 +31,11 @@ public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Size parseSize(String value) {
|
public static Size parseSize(String value) {
|
||||||
|
value = value.replace("*", "");
|
||||||
for (SizeUnit unit : SizeUnit.values()) {
|
for (SizeUnit unit : SizeUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
||||||
value = value.substring(0, value.length() - unit.toString().length() - 1).trim();
|
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
||||||
return new Size(Double.parseDouble(value), unit);
|
return new Size(parse(value), unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not parse size: " + value);
|
throw new IllegalArgumentException("Could not parse size: " + value);
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ public class Voltage extends AbstractMeasure<VoltageUnit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Voltage parseCapacitance(String value) {
|
public static Voltage parseCapacitance(String value) {
|
||||||
|
value = value.replace("*", "");
|
||||||
for (VoltageUnit unit : VoltageUnit.values()) {
|
for (VoltageUnit unit : VoltageUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
||||||
value = value.substring(0, value.length() - unit.toString().length() - 1).trim();
|
value = value.substring(0, value.length() - unit.toString().length()).trim();
|
||||||
return new Voltage(Double.parseDouble(value), unit);
|
return new Voltage(parse(value), unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Could not parse voltage: " + value);
|
throw new IllegalArgumentException("Could not parse voltage: " + value);
|
||||||
|
|||||||
@@ -731,7 +731,7 @@ public class V1FileParser implements IOldFileParser {
|
|||||||
private int randInt(int range) {
|
private int randInt(int range) {
|
||||||
long newSeed = randSeed * 0x08088405 + 1;
|
long newSeed = randSeed * 0x08088405 + 1;
|
||||||
randSeed = newSeed;
|
randSeed = newSeed;
|
||||||
return (int) (newSeed * range >> 32);
|
return (int) ((long)newSeed * range >> 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user