diff options
author | Dimitar Misev <dimitar@debian.(none)> | 2011-02-05 22:44:35 +0100 |
---|---|---|
committer | www-data <www-data@ubuntu.localdomain> | 2011-02-16 10:01:49 +0100 |
commit | 3d356cc9ef7b1055242256c00a2e6b93b5462880 (patch) | |
tree | 977d6292418f8bce19632e10e13ac39da617c226 /petascope/src/petascope/wcps/server/core/ComplexConstant.java | |
parent | 054f18a0e07c429609aae393f6bde67f21f9b82c (diff) | |
download | rasdaman-upstream-3d356cc9ef7b1055242256c00a2e6b93b5462880.tar.gz rasdaman-upstream-3d356cc9ef7b1055242256c00a2e6b93b5462880.tar.xz rasdaman-upstream-3d356cc9ef7b1055242256c00a2e6b93b5462880.zip |
Diffstat (limited to 'petascope/src/petascope/wcps/server/core/ComplexConstant.java')
-rw-r--r-- | petascope/src/petascope/wcps/server/core/ComplexConstant.java | 203 |
1 files changed, 101 insertions, 102 deletions
diff --git a/petascope/src/petascope/wcps/server/core/ComplexConstant.java b/petascope/src/petascope/wcps/server/core/ComplexConstant.java index 144aa32..a5157b4 100644 --- a/petascope/src/petascope/wcps/server/core/ComplexConstant.java +++ b/petascope/src/petascope/wcps/server/core/ComplexConstant.java @@ -14,109 +14,108 @@ * You should have received a copy of the GNU General Public License * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / - rasdaman GmbH. + * Copyright 2003 - 2010 Peter Baumann / rasdaman GmbH. * * For more information please see <http://www.rasdaman.org> * or contact Peter Baumann via <baumann@rasdaman.com>. */ -package petascope.wcps.server.core;
-
-import petascope.wcps.server.exceptions.WCPSException;
-import org.w3c.dom.*;
-
-public class ComplexConstant implements IRasNode {
-
- private String re, im;
-
- public ComplexConstant(String str) throws WCPSException {
- boolean ok = true;
- // We only accept the following String representation of a complex number: {re,im}
- if (str.startsWith("{") && str.endsWith("}")) {
- str = str.substring(1, str.length() - 2);
- if (str.indexOf(",") != -1 && str.lastIndexOf(",") != str.indexOf(",")) {
- int comma = str.indexOf(",");
- re = str.substring(0, comma - 1);
- im = str.substring(comma + 1, str.length() - comma - 1);
- } else {
- ok = false;
- }
- } else {
- ok = false;
- }
- if (ok == false) {
- throw new WCPSException("Could not parse Complex Constant !");
- }
-
- // parse the real part
- try {
- Integer real = Integer.parseInt(re);
- } catch (NumberFormatException e) {
- try {
- Float real = Float.parseFloat(re);
- } catch (NumberFormatException e2) {
- throw new WCPSException("Could not parse float or integer "
- + "number for real part of complex number:" + re);
- }
- }
- // parse the imaginary part
- try {
- Integer imag = Integer.parseInt(im);
- } catch (NumberFormatException e) {
- try {
- Float imag = Float.parseFloat(im);
- } catch (NumberFormatException e2) {
- throw new WCPSException("Could not parse float or integer "
- + "number for imaginary part of complex number" + im);
- }
- }
- }
-
- public ComplexConstant(Node node, XmlQuery xq) throws WCPSException {
- System.err.println("Parsing complex constant: " + node.getNodeName());
-
- while ((node != null) && node.getNodeName().equals("#text")) {
- node = node.getNextSibling();
- }
-
- while (node != null) {
- String name = node.getNodeName();
- if (name.equals("re")) {
- re = node.getNodeValue();
- } else if (name.equals("im")) {
- im = node.getNodeValue();
- } else {
- throw new WCPSException("Unknown node while processing complex constant: " + name);
- }
-
- node = node.getNextSibling();
- }
-
- // parse the real part
- try {
- Integer real = Integer.parseInt(re);
- } catch (NumberFormatException e) {
- try {
- Float real = Float.parseFloat(re);
- } catch (NumberFormatException e2) {
- throw new WCPSException("Could not parse float or integer "
- + "number for real part of complex number:" + re);
- }
- }
- // parse the imaginary part
- try {
- Integer imag = Integer.parseInt(im);
- } catch (NumberFormatException e) {
- try {
- Float imag = Float.parseFloat(im);
- } catch (NumberFormatException e2) {
- throw new WCPSException("Could not parse float or integer "
- + "number for imaginary part of complex number" + im);
- }
- }
- }
-
- public String toRasQL() {
- return "complex ( " + re + ", " + im + " ) ";
- }
-}
+package petascope.wcps.server.core; + +import petascope.exceptions.WCPSException; +import org.w3c.dom.*; + +public class ComplexConstant implements IRasNode { + + private String re, im; + + public ComplexConstant(String str) throws WCPSException { + boolean ok = true; + // We only accept the following String representation of a complex number: {re,im} + if (str.startsWith("{") && str.endsWith("}")) { + str = str.substring(1, str.length() - 2); + if (str.indexOf(",") != -1 && str.lastIndexOf(",") != str.indexOf(",")) { + int comma = str.indexOf(","); + re = str.substring(0, comma - 1); + im = str.substring(comma + 1, str.length() - comma - 1); + } else { + ok = false; + } + } else { + ok = false; + } + if (ok == false) { + throw new WCPSException("Could not parse Complex Constant !"); + } + + // parse the real part + try { + Integer real = Integer.parseInt(re); + } catch (NumberFormatException e) { + try { + Float real = Float.parseFloat(re); + } catch (NumberFormatException e2) { + throw new WCPSException("Could not parse float or integer " + + "number for real part of complex number:" + re); + } + } + // parse the imaginary part + try { + Integer imag = Integer.parseInt(im); + } catch (NumberFormatException e) { + try { + Float imag = Float.parseFloat(im); + } catch (NumberFormatException e2) { + throw new WCPSException("Could not parse float or integer " + + "number for imaginary part of complex number" + im); + } + } + } + + public ComplexConstant(Node node, XmlQuery xq) throws WCPSException { + System.err.println("Parsing complex constant: " + node.getNodeName()); + + while ((node != null) && node.getNodeName().equals("#text")) { + node = node.getNextSibling(); + } + + while (node != null) { + String name = node.getNodeName(); + if (name.equals("re")) { + re = node.getNodeValue(); + } else if (name.equals("im")) { + im = node.getNodeValue(); + } else { + throw new WCPSException("Unknown node while processing complex constant: " + name); + } + + node = node.getNextSibling(); + } + + // parse the real part + try { + Integer real = Integer.parseInt(re); + } catch (NumberFormatException e) { + try { + Float real = Float.parseFloat(re); + } catch (NumberFormatException e2) { + throw new WCPSException("Could not parse float or integer " + + "number for real part of complex number:" + re); + } + } + // parse the imaginary part + try { + Integer imag = Integer.parseInt(im); + } catch (NumberFormatException e) { + try { + Float imag = Float.parseFloat(im); + } catch (NumberFormatException e2) { + throw new WCPSException("Could not parse float or integer " + + "number for imaginary part of complex number" + im); + } + } + } + + public String toRasQL() { + return "complex ( " + re + ", " + im + " ) "; + } +} |