package org.postgresql.util;
import java.io.Serializable;
import java.sql.SQLException;
public class PGmoney extends PGobject implements Serializable, Cloneable {
public double val;
public PGmoney(double value) {
this();
val = value;
}
public PGmoney(String value) throws SQLException {
this();
setValue(value);
}
public PGmoney() {
setType("money");
}
public void setValue(String s) throws SQLException {
try {
String s1;
boolean negative;
negative = (s.charAt(0) == '(');
s1 = PGtokenizer.removePara(s).substring(1);
int pos = s1.indexOf(',');
while (pos != -1) {
s1 = s1.substring(0, pos) + s1.substring(pos + 1);
pos = s1.indexOf(',');
}
val = Double.parseDouble(s1);
val = negative ? -val : val;
} catch (NumberFormatException e) {
throw new PSQLException(GT.tr("Conversion of money failed."),
PSQLState.NUMERIC_CONSTANT_OUT_OF_RANGE, e);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
long temp;
temp = Double.doubleToLongBits(val);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
public boolean equals(Object obj) {
if (obj instanceof PGmoney) {
PGmoney p = (PGmoney) obj;
return val == p.val;
}
return false;
}
public String getValue() {
if (val < 0) {
return "-$" + (-val);
} else {
return "$" + val;
}
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}