link start!
This commit is contained in:
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package javax.baja.units;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import javax.baja.sys.BObject;
|
||||
import javax.baja.sys.BSimple;
|
||||
import javax.baja.sys.Context;
|
||||
import javax.baja.sys.Sys;
|
||||
import javax.baja.sys.Type;
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public final class BDimension
|
||||
extends BSimple {
|
||||
private static final HashMap cache = new HashMap();
|
||||
public static final BDimension DEFAULT;
|
||||
public static final BDimension NULL;
|
||||
public static final Type TYPE;
|
||||
private int exp0;
|
||||
private int exp1;
|
||||
private String string;
|
||||
static /* synthetic */ Class class$javax$baja$units$BDimension;
|
||||
|
||||
public static final BDimension make(int n, int n2, int n3, int n4, int n5, int n6, int n7) {
|
||||
return BDimension.make(n, n2, n3, n4, n5, n6, n7, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
public static final BDimension make(int n, int n2, int n3, int n4, int n5, int n6, int n7, int n8) {
|
||||
BDimension bDimension = new BDimension();
|
||||
bDimension.exp0 = (n & 0xFF) << 24 | (n2 & 0xFF) << 16 | (n3 & 0xFF) << 8 | n4 & 0xFF;
|
||||
bDimension.exp1 = (n5 & 0xFF) << 24 | (n6 & 0xFF) << 16 | (n7 & 0xFF) << 8 | n8 & 0xFF;
|
||||
HashMap hashMap = cache;
|
||||
synchronized (hashMap) {
|
||||
BDimension bDimension2 = (BDimension)cache.get(bDimension);
|
||||
if (bDimension2 != null) {
|
||||
return bDimension2;
|
||||
}
|
||||
cache.put(bDimension, bDimension);
|
||||
return bDimension;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getMeter() {
|
||||
return (byte)(this.exp0 >> 24 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getKilogram() {
|
||||
return (byte)(this.exp0 >> 16 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getSecond() {
|
||||
return (byte)(this.exp0 >> 8 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getAmpere() {
|
||||
return (byte)(this.exp0 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getKelvin() {
|
||||
return (byte)(this.exp1 >> 24 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getMole() {
|
||||
return (byte)(this.exp1 >> 16 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getCandela() {
|
||||
return (byte)(this.exp1 >> 8 & 0xFF);
|
||||
}
|
||||
|
||||
public final int getDollar() {
|
||||
return (byte)(this.exp1 & 0xFF);
|
||||
}
|
||||
|
||||
public final String toString(Context context) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
BDimension.append(stringBuffer, "m", this.getMeter());
|
||||
BDimension.append(stringBuffer, "kg", this.getKilogram());
|
||||
BDimension.append(stringBuffer, "s", this.getSecond());
|
||||
BDimension.append(stringBuffer, "A", this.getAmpere());
|
||||
BDimension.append(stringBuffer, "K", this.getKelvin());
|
||||
BDimension.append(stringBuffer, "mol", this.getMole());
|
||||
BDimension.append(stringBuffer, "cd", this.getCandela());
|
||||
BDimension.append(stringBuffer, "$", this.getDollar());
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
private static final void append(StringBuffer stringBuffer, String string, int n) {
|
||||
if (n == 0) {
|
||||
return;
|
||||
}
|
||||
if (stringBuffer.length() > 0) {
|
||||
stringBuffer.append('\u00b7');
|
||||
}
|
||||
stringBuffer.append(string);
|
||||
if (n > 1) {
|
||||
if (n == 2) {
|
||||
stringBuffer.append('\u00b2');
|
||||
} else if (n == 3) {
|
||||
stringBuffer.append('\u00b3');
|
||||
} else {
|
||||
stringBuffer.append(n);
|
||||
}
|
||||
} else if (n < 0) {
|
||||
stringBuffer.append(n);
|
||||
}
|
||||
}
|
||||
|
||||
public final int hashCode() {
|
||||
return this.exp0 ^ this.exp1 << 1;
|
||||
}
|
||||
|
||||
public final boolean equals(Object object) {
|
||||
if (object instanceof BDimension) {
|
||||
BDimension bDimension = (BDimension)object;
|
||||
boolean bl = false;
|
||||
if (this.exp0 == bDimension.exp0 && this.exp1 == bDimension.exp1) {
|
||||
bl = true;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void encode(DataOutput dataOutput) throws IOException {
|
||||
dataOutput.writeUTF(this.encodeToString());
|
||||
}
|
||||
|
||||
public final BObject decode(DataInput dataInput) throws IOException {
|
||||
return this.decodeFromString(dataInput.readUTF());
|
||||
}
|
||||
|
||||
public final String encodeToString() {
|
||||
if (this.string == null) {
|
||||
int n;
|
||||
int n2;
|
||||
int n3;
|
||||
int n4;
|
||||
int n5;
|
||||
int n6;
|
||||
int n7;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
int n8 = this.getMeter();
|
||||
if (n8 != 0) {
|
||||
stringBuffer.append('(').append('m');
|
||||
if (n8 != 1) {
|
||||
stringBuffer.append(n8);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n7 = this.getKilogram()) != 0) {
|
||||
stringBuffer.append('(').append('k').append('g');
|
||||
if (n7 != 1) {
|
||||
stringBuffer.append(n7);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n6 = this.getSecond()) != 0) {
|
||||
stringBuffer.append('(').append('s');
|
||||
if (n6 != 1) {
|
||||
stringBuffer.append(n6);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n5 = this.getAmpere()) != 0) {
|
||||
stringBuffer.append('(').append('A');
|
||||
if (n5 != 1) {
|
||||
stringBuffer.append(n5);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n4 = this.getKelvin()) != 0) {
|
||||
stringBuffer.append('(').append('K');
|
||||
if (n4 != 1) {
|
||||
stringBuffer.append(n4);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n3 = this.getMole()) != 0) {
|
||||
stringBuffer.append('(').append("Mol");
|
||||
if (n3 != 1) {
|
||||
stringBuffer.append(n3);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n2 = this.getCandela()) != 0) {
|
||||
stringBuffer.append('(').append("cd");
|
||||
if (n2 != 1) {
|
||||
stringBuffer.append(n2);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
if ((n = this.getDollar()) != 0) {
|
||||
stringBuffer.append('(').append('$');
|
||||
if (n != 1) {
|
||||
stringBuffer.append(n);
|
||||
}
|
||||
stringBuffer.append(')');
|
||||
}
|
||||
this.string = stringBuffer.toString();
|
||||
}
|
||||
return this.string;
|
||||
}
|
||||
|
||||
public final BObject decodeFromString(String string) throws IOException {
|
||||
try {
|
||||
int n = 0;
|
||||
int n2 = 0;
|
||||
int n3 = 0;
|
||||
int n4 = 0;
|
||||
int n5 = 0;
|
||||
int n6 = 0;
|
||||
int n7 = 0;
|
||||
int n8 = 0;
|
||||
int[] nArray = new int[1];
|
||||
int n9 = 0;
|
||||
int n10 = string.length();
|
||||
while (n9 < n10) {
|
||||
if (string.charAt(n9++) != '(') {
|
||||
throw new Exception();
|
||||
}
|
||||
char c = string.charAt(n9++);
|
||||
switch (c) {
|
||||
case '$': {
|
||||
n8 = this.parseExp(string, n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 'c': {
|
||||
n7 = this.parseExp(string, ++n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 'm': {
|
||||
n = this.parseExp(string, n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 'k': {
|
||||
n2 = this.parseExp(string, ++n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
n3 = this.parseExp(string, n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 'A': {
|
||||
n4 = this.parseExp(string, n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 'K': {
|
||||
n5 = this.parseExp(string, n9, nArray);
|
||||
break;
|
||||
}
|
||||
case 'M': {
|
||||
n6 = this.parseExp(string, n9 += 2, nArray);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
n9 = nArray[0];
|
||||
if (string.charAt(n9++) == ')') continue;
|
||||
throw new Exception();
|
||||
}
|
||||
return BDimension.make(n, n2, n3, n4, n5, n6, n7, n8);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
throw new IOException(string);
|
||||
}
|
||||
}
|
||||
|
||||
private final int parseExp(String string, int n, int[] nArray) {
|
||||
boolean bl = false;
|
||||
char c = string.charAt(n);
|
||||
if (c == ')') {
|
||||
nArray[0] = n;
|
||||
return 1;
|
||||
}
|
||||
if (c == '-') {
|
||||
bl = true;
|
||||
++n;
|
||||
}
|
||||
int n2 = 0;
|
||||
while ((c = string.charAt(n)) != ')') {
|
||||
if (c < '0' || c > '9') {
|
||||
throw new IllegalArgumentException("not number: " + c);
|
||||
}
|
||||
n2 = n2 * 10 + (c - 48);
|
||||
++n;
|
||||
}
|
||||
nArray[0] = n;
|
||||
if (bl) {
|
||||
return -n2;
|
||||
}
|
||||
return n2;
|
||||
}
|
||||
|
||||
public final boolean isNull() {
|
||||
return this.equals(NULL);
|
||||
}
|
||||
|
||||
public final Type getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class(String string, boolean bl) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(string);
|
||||
if (!bl) {
|
||||
clazz = clazz.getComponentType();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private BDimension() {
|
||||
}
|
||||
|
||||
static {
|
||||
NULL = DEFAULT = BDimension.make(0, 0, 0, 0, 0, 0, 0);
|
||||
Class clazz = class$javax$baja$units$BDimension;
|
||||
if (clazz == null) {
|
||||
clazz = class$javax$baja$units$BDimension = BDimension.class("[Ljavax.baja.units.BDimension;", false);
|
||||
}
|
||||
TYPE = Sys.loadType(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package javax.baja.units;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import javax.baja.data.BIDataValue;
|
||||
import javax.baja.sys.BObject;
|
||||
import javax.baja.sys.BSimple;
|
||||
import javax.baja.sys.Context;
|
||||
import javax.baja.sys.Sys;
|
||||
import javax.baja.sys.Type;
|
||||
import javax.baja.units.BDimension;
|
||||
import javax.baja.units.UnitDatabase;
|
||||
import javax.baja.units.UnitDifferentialConverter;
|
||||
import javax.baja.units.UnitException;
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public final class BUnit
|
||||
extends BSimple
|
||||
implements BIDataValue {
|
||||
private static final HashMap cache = new HashMap();
|
||||
public static final BUnit NULL;
|
||||
public static final BUnit DEFAULT;
|
||||
public static final Type TYPE;
|
||||
private BDimension dimension;
|
||||
private String unitName;
|
||||
private String symbol;
|
||||
private double scale;
|
||||
private double offset;
|
||||
private String string;
|
||||
private boolean prefix;
|
||||
UnitDatabase.Quantity quantity;
|
||||
static /* synthetic */ Class class$javax$baja$units$BUnit;
|
||||
|
||||
public static final BUnit getUnit(String string) {
|
||||
BUnit bUnit = (BUnit)cache.get(string);
|
||||
if (bUnit == null) {
|
||||
UnitDatabase.getDefault();
|
||||
bUnit = (BUnit)cache.get(string);
|
||||
if (bUnit == null) {
|
||||
throw new UnitException("Unknown unit: " + string);
|
||||
}
|
||||
}
|
||||
return bUnit;
|
||||
}
|
||||
|
||||
public static final BUnit make(String string, BDimension bDimension) {
|
||||
return BUnit.make(string, null, bDimension, 1.0, 0.0);
|
||||
}
|
||||
|
||||
public static final BUnit make(String string, String string2, BDimension bDimension) {
|
||||
return BUnit.make(string, string2, bDimension, 1.0, 0.0);
|
||||
}
|
||||
|
||||
public static final BUnit make(String string, String string2, BDimension bDimension, double d) {
|
||||
return BUnit.make(string, string2, bDimension, d, 0.0);
|
||||
}
|
||||
|
||||
public static final BUnit make(String string, BDimension bDimension, double d) {
|
||||
return BUnit.make(string, null, bDimension, d, 0.0);
|
||||
}
|
||||
|
||||
public static final BUnit make(String string, String string2, BDimension bDimension, double d, double d2) {
|
||||
return BUnit.make(string, string2, bDimension, d, d2, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
public static final BUnit make(String string, String string2, BDimension bDimension, double d, double d2, boolean bl) {
|
||||
if (string == null || bDimension == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (string.indexOf(59) >= 0) {
|
||||
throw new UnitException("Invalid unitName: " + string);
|
||||
}
|
||||
if (string2 == null) {
|
||||
string2 = string;
|
||||
} else if (string2.indexOf(59) >= 0) {
|
||||
throw new UnitException("Invalid symbol: " + string2);
|
||||
}
|
||||
HashMap hashMap = cache;
|
||||
synchronized (hashMap) {
|
||||
BUnit bUnit = (BUnit)cache.get(string);
|
||||
if (bUnit == null) {
|
||||
bUnit = new BUnit();
|
||||
bUnit.unitName = string;
|
||||
bUnit.symbol = string2;
|
||||
bUnit.dimension = bDimension;
|
||||
bUnit.scale = d;
|
||||
bUnit.offset = d2;
|
||||
bUnit.prefix = bl;
|
||||
cache.put(string, bUnit);
|
||||
return bUnit;
|
||||
}
|
||||
if (!bUnit.dimension.equals(bDimension)) {
|
||||
throw new UnitException("Duplicate unit is incompatible: " + string);
|
||||
}
|
||||
return bUnit;
|
||||
}
|
||||
}
|
||||
|
||||
public final BDimension getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
public final String getUnitName() {
|
||||
return this.unitName;
|
||||
}
|
||||
|
||||
public final String getUnitName(Context context) {
|
||||
return this.unitName;
|
||||
}
|
||||
|
||||
public final String getSymbol() {
|
||||
return this.symbol;
|
||||
}
|
||||
|
||||
public final String getSymbol(Context context) {
|
||||
return this.symbol;
|
||||
}
|
||||
|
||||
public final double getScale() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
public final double getOffset() {
|
||||
return this.offset;
|
||||
}
|
||||
|
||||
public final boolean getIsPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public final boolean isConvertible(BUnit bUnit) {
|
||||
return this.dimension.equals(bUnit.dimension);
|
||||
}
|
||||
|
||||
public final double toNormal(double d) {
|
||||
return d * this.scale + this.offset;
|
||||
}
|
||||
|
||||
public final double fromNormal(double d) {
|
||||
return (d - this.offset) / this.scale;
|
||||
}
|
||||
|
||||
public final double convertTo(BUnit bUnit, double d) {
|
||||
if (!this.dimension.equals(bUnit.dimension)) {
|
||||
throw new UnitException("Not convertible: " + this + " -> " + bUnit);
|
||||
}
|
||||
return (d * this.scale + this.offset - bUnit.offset) / bUnit.scale;
|
||||
}
|
||||
|
||||
public final BUnit getDifferentialUnit() {
|
||||
return UnitDifferentialConverter.getInstance().getDifferential(this);
|
||||
}
|
||||
|
||||
public final BUnit getAbsoluteUnit() {
|
||||
return UnitDifferentialConverter.getInstance().getAbsolute(this);
|
||||
}
|
||||
|
||||
public final boolean isNull() {
|
||||
boolean bl = false;
|
||||
if (this == NULL) {
|
||||
bl = true;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
|
||||
public final String toString(Context context) {
|
||||
return this.getSymbol(context);
|
||||
}
|
||||
|
||||
public final int hashCode() {
|
||||
return this.unitName.hashCode();
|
||||
}
|
||||
|
||||
public final boolean equals(Object object) {
|
||||
boolean bl = false;
|
||||
if (this == object) {
|
||||
bl = true;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
|
||||
public final void encode(DataOutput dataOutput) throws IOException {
|
||||
dataOutput.writeUTF(this.encodeToString());
|
||||
}
|
||||
|
||||
public final BObject decode(DataInput dataInput) throws IOException {
|
||||
return this.decodeFromString(dataInput.readUTF());
|
||||
}
|
||||
|
||||
public final String encodeToString() {
|
||||
if (this.string == null) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(this.unitName).append(';');
|
||||
if (this.symbol != this.unitName) {
|
||||
stringBuffer.append(this.symbol);
|
||||
}
|
||||
stringBuffer.append(';');
|
||||
stringBuffer.append(this.dimension.encodeToString()).append(';');
|
||||
if (this.scale != 1.0) {
|
||||
stringBuffer.append('*').append(this.scale);
|
||||
}
|
||||
if (this.offset != 0.0) {
|
||||
stringBuffer.append('+').append(this.offset);
|
||||
}
|
||||
stringBuffer.append(';');
|
||||
this.string = stringBuffer.toString();
|
||||
}
|
||||
return this.string;
|
||||
}
|
||||
|
||||
public final BObject decodeFromString(String string) throws IOException {
|
||||
try {
|
||||
int n = 0;
|
||||
int n2 = string.indexOf(59);
|
||||
String string2 = string.substring(n, n2);
|
||||
n = n2;
|
||||
n2 = string.indexOf(59, n2 + 1);
|
||||
String string3 = n + 1 == n2 ? null : string.substring(n + 1, n2);
|
||||
n = n2;
|
||||
n2 = string.indexOf(59, n2 + 1);
|
||||
BDimension bDimension = (BDimension)this.dimension.decodeFromString(string.substring(n + 1, n2));
|
||||
n = n2;
|
||||
n2 = string.indexOf(59, n2 + 1);
|
||||
String string4 = string.substring(n + 1, n2);
|
||||
double d = 1.0;
|
||||
double d2 = 0.0;
|
||||
int n3 = string4.length();
|
||||
if (n3 > 0) {
|
||||
int n4 = 0;
|
||||
if (string4.charAt(0) == '*') {
|
||||
n4 = string4.indexOf(43);
|
||||
if (n4 < 0) {
|
||||
n4 = n3;
|
||||
}
|
||||
d = Double.parseDouble(string4.substring(1, n4));
|
||||
}
|
||||
if (n4 < n3 && string4.charAt(n4) == '+') {
|
||||
d2 = Double.parseDouble(string4.substring(n4 + 1, n3));
|
||||
}
|
||||
}
|
||||
return BUnit.make(string2, string3, bDimension, d, d2);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
throw new IOException(string);
|
||||
}
|
||||
}
|
||||
|
||||
public final BIDataValue toDataValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public final Type getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class(String string, boolean bl) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(string);
|
||||
if (!bl) {
|
||||
clazz = clazz.getComponentType();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private BUnit() {
|
||||
}
|
||||
|
||||
static {
|
||||
DEFAULT = NULL = BUnit.make("null", BDimension.DEFAULT);
|
||||
Class clazz = class$javax$baja$units$BUnit;
|
||||
if (clazz == null) {
|
||||
clazz = class$javax$baja$units$BUnit = BUnit.class("[Ljavax.baja.units.BUnit;", false);
|
||||
}
|
||||
TYPE = Sys.loadType(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.xml.XElem
|
||||
* javax.baja.xml.XParser
|
||||
*/
|
||||
package javax.baja.units;
|
||||
|
||||
import com.tridium.sys.Nre;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import javax.baja.log.Log;
|
||||
import javax.baja.sys.BFrozenEnum;
|
||||
import javax.baja.sys.Sys;
|
||||
import javax.baja.sys.Type;
|
||||
import javax.baja.units.BUnit;
|
||||
import javax.baja.units.UnitDatabase;
|
||||
import javax.baja.xml.XElem;
|
||||
import javax.baja.xml.XParser;
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public final class BUnitConversion
|
||||
extends BFrozenEnum {
|
||||
public static final int NONE = 0;
|
||||
public static final int METRIC = 1;
|
||||
public static final int ENGLISH = 2;
|
||||
public static final BUnitConversion none = new BUnitConversion(0);
|
||||
public static final BUnitConversion metric = new BUnitConversion(1);
|
||||
public static final BUnitConversion english = new BUnitConversion(2);
|
||||
public static final Type TYPE;
|
||||
public static final BUnitConversion DEFAULT;
|
||||
static HashMap byMetric;
|
||||
static HashMap byEnglish;
|
||||
static boolean loaded;
|
||||
static /* synthetic */ Class class$javax$baja$units$BUnitConversion;
|
||||
|
||||
public final Type getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public static final BUnitConversion make(int n) {
|
||||
return (BUnitConversion)none.getRange().get(n, false);
|
||||
}
|
||||
|
||||
public static final BUnitConversion make(String string) {
|
||||
return (BUnitConversion)none.getRange().get(string);
|
||||
}
|
||||
|
||||
public final BUnit getDesiredUnit(BUnit bUnit) {
|
||||
BUnit bUnit2;
|
||||
if (bUnit == null) {
|
||||
return null;
|
||||
}
|
||||
if (this == none) {
|
||||
return bUnit;
|
||||
}
|
||||
if (!loaded) {
|
||||
BUnitConversion.load();
|
||||
}
|
||||
if (this == metric) {
|
||||
BUnit bUnit3 = (BUnit)byEnglish.get(bUnit.getUnitName());
|
||||
if (bUnit3 != null) {
|
||||
return bUnit3;
|
||||
}
|
||||
} else if (this == english && (bUnit2 = (BUnit)byMetric.get(bUnit.getUnitName())) != null) {
|
||||
return bUnit2;
|
||||
}
|
||||
return bUnit;
|
||||
}
|
||||
|
||||
static final void load() {
|
||||
if (loaded) {
|
||||
return;
|
||||
}
|
||||
loaded = true;
|
||||
try {
|
||||
XElem xElem = XParser.make((InputStream)Nre.bootEnv.read("/lib/unitConversion.xml")).parse();
|
||||
XElem[] xElemArray = xElem.elems();
|
||||
int n = 0;
|
||||
while (n < xElemArray.length) {
|
||||
XElem xElem2 = xElemArray[n];
|
||||
try {
|
||||
BUnit bUnit = UnitDatabase.getUnit(xElem2.get("metric"));
|
||||
BUnit bUnit2 = UnitDatabase.getUnit(xElem2.get("english"));
|
||||
byMetric.put(bUnit.getUnitName(), bUnit2);
|
||||
byEnglish.put(bUnit2.getUnitName(), bUnit);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Log.getLog("sys.unitConversion").warning("Parsing convert [line " + xElem2.line() + ']', exception);
|
||||
}
|
||||
++n;
|
||||
}
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Log.getLog("sys.unitConversion").error("Error parsing unitConversion.xml", exception);
|
||||
}
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class(String string, boolean bl) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(string);
|
||||
if (!bl) {
|
||||
clazz = clazz.getComponentType();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private BUnitConversion(int n) {
|
||||
super(n);
|
||||
}
|
||||
|
||||
static {
|
||||
Class clazz = class$javax$baja$units$BUnitConversion;
|
||||
if (clazz == null) {
|
||||
clazz = class$javax$baja$units$BUnitConversion = BUnitConversion.class("[Ljavax.baja.units.BUnitConversion;", false);
|
||||
}
|
||||
TYPE = Sys.loadType(clazz);
|
||||
DEFAULT = none;
|
||||
byMetric = new HashMap();
|
||||
byEnglish = new HashMap();
|
||||
loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.xml.XElem
|
||||
* javax.baja.xml.XParser
|
||||
*/
|
||||
package javax.baja.units;
|
||||
|
||||
import com.tridium.sys.Nre;
|
||||
import java.io.InputStream;
|
||||
import javax.baja.log.Log;
|
||||
import javax.baja.units.BDimension;
|
||||
import javax.baja.units.BUnit;
|
||||
import javax.baja.xml.XElem;
|
||||
import javax.baja.xml.XParser;
|
||||
|
||||
public class UnitDatabase {
|
||||
private static UnitDatabase db;
|
||||
private Quantity[] quantities;
|
||||
|
||||
public static BUnit getUnit(String string) {
|
||||
UnitDatabase.getDefault();
|
||||
return BUnit.getUnit(string);
|
||||
}
|
||||
|
||||
public static UnitDatabase getDefault() {
|
||||
if (db == null) {
|
||||
db = new UnitDatabase();
|
||||
try {
|
||||
db.load();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Log.getLog("sys.unitdb").error("Cannot load database", exception);
|
||||
}
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
public Quantity[] getQuantities() {
|
||||
Quantity[] quantityArray = new Quantity[this.quantities.length];
|
||||
System.arraycopy(this.quantities, 0, quantityArray, 0, quantityArray.length);
|
||||
return quantityArray;
|
||||
}
|
||||
|
||||
public Quantity getQuantity(BUnit bUnit) {
|
||||
return bUnit.quantity;
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Quantity[] quantityArray = this.getQuantities();
|
||||
int n = 0;
|
||||
while (n < quantityArray.length) {
|
||||
System.out.println(quantityArray[n].getName());
|
||||
BUnit[] bUnitArray = quantityArray[n].getUnits();
|
||||
int n2 = 0;
|
||||
while (n2 < bUnitArray.length) {
|
||||
System.out.println(" " + bUnitArray[n2].encodeToString());
|
||||
++n2;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
private final void load() throws Exception {
|
||||
XElem xElem = XParser.make((InputStream)Nre.bootEnv.read("/lib/units.xml")).parse();
|
||||
XElem[] xElemArray = xElem.elems("quantity");
|
||||
this.quantities = new Quantity[xElemArray.length];
|
||||
int n = 0;
|
||||
while (n < xElemArray.length) {
|
||||
String string = xElemArray[n].get("n");
|
||||
BDimension bDimension = null;
|
||||
try {
|
||||
bDimension = (BDimension)BDimension.DEFAULT.decodeFromString(xElemArray[n].get("dim"));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
throw new Exception("Error parsing quanitity \"" + string + "\" [line " + xElemArray[n].line() + "] " + exception);
|
||||
}
|
||||
XElem[] xElemArray2 = xElemArray[n].elems("unit");
|
||||
BUnit[] bUnitArray = new BUnit[xElemArray2.length];
|
||||
int n2 = 0;
|
||||
while (n2 < xElemArray2.length) {
|
||||
bUnitArray[n2] = this.parseUnit(bDimension, xElemArray2[n2]);
|
||||
++n2;
|
||||
}
|
||||
this.quantities[n] = new Quantity(string, bDimension, bUnitArray);
|
||||
n2 = 0;
|
||||
while (n2 < bUnitArray.length) {
|
||||
if (bUnitArray[n2] != null) {
|
||||
bUnitArray[n2].quantity = this.quantities[n];
|
||||
}
|
||||
++n2;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
private final BUnit parseUnit(BDimension bDimension, XElem xElem) throws Exception {
|
||||
String string = xElem.get("n");
|
||||
try {
|
||||
String string2 = xElem.get("s", null);
|
||||
double d = 1.0;
|
||||
String string3 = xElem.get("scale", null);
|
||||
if (string3 != null) {
|
||||
d = Double.parseDouble(string3);
|
||||
}
|
||||
double d2 = 0.0;
|
||||
String string4 = xElem.get("offset", null);
|
||||
if (string4 != null) {
|
||||
d2 = Double.parseDouble(string4);
|
||||
}
|
||||
boolean bl = false;
|
||||
String string5 = xElem.get("prefix", null);
|
||||
if (string5 != null) {
|
||||
bl = string5.equalsIgnoreCase("true");
|
||||
}
|
||||
return BUnit.make(string, string2, bDimension, d, d2, bl);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Log.getLog("sys.unitdb").warning("Error parsing unit \"" + string + "\" [line " + xElem.line() + "] ", exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Quantity {
|
||||
final String name;
|
||||
final BDimension dim;
|
||||
final BUnit[] units;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public BUnit[] getUnits() {
|
||||
BUnit[] bUnitArray = new BUnit[this.units.length];
|
||||
System.arraycopy(this.units, 0, bUnitArray, 0, bUnitArray.length);
|
||||
return bUnitArray;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name + " (" + this.dim + ')';
|
||||
}
|
||||
|
||||
Quantity(String string, BDimension bDimension, BUnit[] bUnitArray) {
|
||||
this.name = string;
|
||||
this.dim = bDimension;
|
||||
this.units = bUnitArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.xml.XElem
|
||||
* javax.baja.xml.XParser
|
||||
*/
|
||||
package javax.baja.units;
|
||||
|
||||
import com.tridium.sys.Nre;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import javax.baja.log.Log;
|
||||
import javax.baja.units.BUnit;
|
||||
import javax.baja.units.UnitDatabase;
|
||||
import javax.baja.xml.XElem;
|
||||
import javax.baja.xml.XParser;
|
||||
|
||||
public final class UnitDifferentialConverter {
|
||||
static HashMap byDifferential = new HashMap();
|
||||
static HashMap byAbsolute = new HashMap();
|
||||
private static UnitDifferentialConverter INSTANCE = new UnitDifferentialConverter();
|
||||
|
||||
public final BUnit getDifferential(BUnit bUnit) {
|
||||
BUnit bUnit2 = (BUnit)byAbsolute.get(bUnit.getUnitName());
|
||||
if (bUnit2 != null) {
|
||||
return bUnit2;
|
||||
}
|
||||
return bUnit;
|
||||
}
|
||||
|
||||
public final BUnit getAbsolute(BUnit bUnit) {
|
||||
BUnit bUnit2 = (BUnit)byDifferential.get(bUnit.getUnitName());
|
||||
if (bUnit2 != null) {
|
||||
return bUnit2;
|
||||
}
|
||||
return bUnit;
|
||||
}
|
||||
|
||||
public static final UnitDifferentialConverter getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private UnitDifferentialConverter() {
|
||||
try {
|
||||
XElem xElem = XParser.make((InputStream)Nre.bootEnv.read("/lib/unitDifferentialConversion.xml")).parse();
|
||||
XElem[] xElemArray = xElem.elems();
|
||||
int n = 0;
|
||||
while (n < xElemArray.length) {
|
||||
XElem xElem2 = xElemArray[n];
|
||||
try {
|
||||
BUnit bUnit = UnitDatabase.getUnit(xElem2.get("differential"));
|
||||
BUnit bUnit2 = UnitDatabase.getUnit(xElem2.get("absolute"));
|
||||
byDifferential.put(bUnit.getUnitName(), bUnit2);
|
||||
byAbsolute.put(bUnit2.getUnitName(), bUnit);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Log.getLog("sys.unitConversion").warning("Parsing convert [line " + xElem2.line() + ']', exception);
|
||||
}
|
||||
++n;
|
||||
}
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Log.getLog("sys.unitConversion").error("Error parsing unitDifferentialConversion.xml", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package javax.baja.units;
|
||||
|
||||
import javax.baja.sys.BajaRuntimeException;
|
||||
|
||||
public class UnitException
|
||||
extends BajaRuntimeException {
|
||||
public UnitException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
public UnitException() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user