Package org.zkoss.zss.engine.xel

Examples of org.zkoss.zss.engine.xel.SSErrorXelException


      x = ((Double)UtilFns.validateNumber(CommonFns.toNumber(args[0]).doubleValue())).doubleValue();
      //get |x| for finding which way to calculate Jn(x)
      absX = Math.abs(x);
      n = CommonFns.toNumber(args[1]).intValue();
      if (n < 0)
        throw new SSErrorXelException(SSError.NUM);
    }
    catch (ClassCastException e){
      throw new SSErrorXelException(SSError.VALUE);
    }
    //use iteration method.
    if( absX < THRESHOLD )
    {
      /* Start the iteration, first find TERM(n,0)
View Full Code Here


    int n;
    try {
      x = ((Double)UtilFns.validateNumber(CommonFns.toNumber(args[0]).doubleValue())).doubleValue();
      n = CommonFns.toNumber(args[1]).intValue();
      if (n < 0)
        throw new SSErrorXelException(SSError.NUM);
    }
    catch (ClassCastException e){
      throw new SSErrorXelException(SSError.VALUE);
    }
   
    //if x is small enough, use approximate formula to get result.
    if( x == 0) result = BesselK0(x);
    else if ( x == 1) result = BesselK1(x);
View Full Code Here

    int n;
    try {
      x = ((Double)UtilFns.validateNumber(CommonFns.toNumber(args[0]).doubleValue())).doubleValue();
      n = CommonFns.toNumber(args[1]).intValue();
      if (n < 0)
        throw new SSErrorXelException(SSError.NUM);
    }
    catch (ClassCastException e){
      throw new SSErrorXelException(SSError.VALUE);
    }
   
    //if x is small enough, use approximate formula to get result.
    if( x == 0) result = BesselY0(x);
    else if ( x == 1) result = BesselY1(x);
View Full Code Here

 
  /* return decimal */
  private static int binToDec(String bin) {
    int places = bin.length();
    if(places > 10) {
      throw new SSErrorXelException(SSError.NUM);
    } else {
      for(int i = 0; i < places; i++) {
        if(bin.charAt(i)!='0' && bin.charAt(i)!='1') {
          throw new SSErrorXelException(SSError.NUM);
        }
      }
      Integer result = Integer.valueOf(bin, 2);
      if(places == 10) {
        result = Integer.valueOf(result.intValue() - 1024);
View Full Code Here

    String suffix = "i";
    if(args.length==3) {
      suffix = args[2].toString();     
    }
    if(Double.isNaN(real) || Double.isNaN(imaginary) || (suffix!="i" && suffix!="j")) {
      throw new SSErrorXelException(SSError.VALUE);
    }
    return new Complex(real, imaginary, suffix);
  }
View Full Code Here

      String temp;
     
      double mag1 = 1, mag2 = 1;
     
      if( oldType.compareTo(newType) != 0)
        throw new SSErrorXelException(SSError.NA);
     
      //  Units that have Prefix-enable:
      //  Weight and mass:
      //    g, u
      //
      //  Length:
      //    m, ang
      //         
      //  Time:
      //    sec
      //
      //  Pressure:
      //    p, atm, mmHg  => all can have Prefix
      //        
      //  Force:
      //    N, dy
      //
      //  Energy:
      //    J, e, c, cal, ev, wh
      //
      //  Power:
      //    w
      //
      //  Magnet:
      //    T, ga
      //        
      //  Temp:
      //    K
      //
      //  Liquid:
      //    l
      if ( oldType.equals("mass"))
      {
        if( oldUnit.endsWith("g") || oldUnit.endsWith("u"))
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("g"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("u"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("g") || newUnit.endsWith("u"))
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("g"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("u"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        MassUnit mass = new MassUnit( value * mag1, oldUnit);
        return new Double( mass.doConvert(newUnit) / mag2);
       

      }
      else if (oldType.equals("dist"))
      {
        if( oldUnit.endsWith("m") || oldUnit.endsWith("ang"))
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("m"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("ang"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
         
        }
        if( newUnit.endsWith("m") || newUnit.endsWith("ang"))
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("g"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("u"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        LengthUnit length = new LengthUnit( value * mag1, oldUnit);
        return new Double( length.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("time"))
      {
        if( oldUnit.endsWith("sec") )
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("sec"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("sec") )
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("sec"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        TimeUnit time = new TimeUnit( value * mag1, oldUnit);
        return new Double( time.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("pres"))
      {
        if( oldUnit.endsWith("p") || oldUnit.endsWith("at") || oldUnit.endsWith("mmHg"))
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("p"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("at"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("mmHg"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
         
        }
        if( newUnit.endsWith("p") || newUnit.endsWith("at") || oldUnit.endsWith("mmHg"))
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("p"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("at"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("mmHg"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do prefix expand for output
        PressUnit press = new PressUnit( value * mag1, oldUnit);
        return new Double( press.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("forc"))
      {
        if( oldUnit.endsWith("N") || oldUnit.endsWith("dy") )
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("N"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("dy"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("N") || newUnit.endsWith("dy"))
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("N"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("dy"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        ForceUnit force = new ForceUnit( value * mag1, oldUnit);
        return new Double( force.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("ener"))
      {
        if( oldUnit.endsWith("J") || oldUnit.endsWith("e") || oldUnit.endsWith("c") || oldUnit.endsWith("cal") || oldUnit.endsWith("ev") || oldUnit.endsWith("wh"))
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("J"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("e"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("c"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("cal"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("ev"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("wh"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("J") || newUnit.endsWith("e") || newUnit.endsWith("c") || newUnit.endsWith("cal") || newUnit.endsWith("ev") || newUnit.endsWith("wh"))
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("J"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("e"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("c"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("cal"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("ev"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("wh"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        EnergyUnit energy = new EnergyUnit( value * mag1, oldUnit);
        return new Double( energy.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("powe"))
      {
        if( oldUnit.endsWith("w") )
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("w"))) != null)
          {
          //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("w") )
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("w"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        PowerUnit power = new PowerUnit( value * mag1, oldUnit);
        return new Double( power.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("magn"))
      {
        if( oldUnit.endsWith("T") || oldUnit.endsWith("ga") )
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("T"))) != null)
          {
            //do prefix expand
            mag1 = expandPrefix(temp);
          }
          else if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("ga"))) != null)
          {
            //do prefix expand
            mag1 = expandPrefix(temp);
          }
         
        }
        if( newUnit.endsWith("T") || newUnit.endsWith("ga"))
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("T"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
          else if ((temp = newUnit.substring(0, newUnit.lastIndexOf("ga"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        MagnetUnit magnet = new MagnetUnit( value * mag1, oldUnit);
        return new Double( magnet.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("temp"))
      {
        if( oldUnit.endsWith("K") )
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("T"))) != null)
          {
            //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("K") )
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("T"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        TempUnit temperatrue = new TempUnit( value * mag1, oldUnit);
        return new Double( temperatrue.doConvert(newUnit) / mag2);
      }
      else if (oldType.equals("liqu"))
      {
        if( oldUnit.endsWith("l") )
        {
          if ((temp = oldUnit.substring(0, oldUnit.lastIndexOf("T"))) != null)
          {
            //do prefix expand
            mag1 = expandPrefix(temp);
          }
        }
        if( newUnit.endsWith("l") )
        {
          if ((temp = newUnit.substring(0, newUnit.lastIndexOf("T"))) != null)
          {
          //do prefix expand for output
            mag2 = expandPrefix(temp);
          }
        }
       
        //do unit convert.
        FluidUnit fluid = new FluidUnit( value * mag1, oldUnit);
        return new Double( fluid.doConvert(newUnit) / mag2);
      }
      else
        throw new SSErrorXelException(SSError.VALUE);
    }
    catch ( NullPointerException e) {
      throw new SSErrorXelException(SSError.NA);
    }
    catch ( IndexOutOfBoundsException e) {
      throw new SSErrorXelException(SSError.NA);
    }
    catch ( ConvertUnitException e) {
      throw new SSErrorXelException(SSError.VALUE);
    }
  }
View Full Code Here

  }
 
  /* return binary */
  private static String decToBin(int dec, int places) {
    if(dec < -512 || dec > 511) {
      throw new SSErrorXelException(SSError.NUM);
    } else {
      String result = Integer.toBinaryString(dec);
      if(dec < 0){
        result = result.substring(result.length()-10, result.length());
      }
View Full Code Here

  }
 
  /* return octal */
  private static String decToOct(int dec, int places) {
    if(dec < -536870912 || dec > 536870911) {
      throw new SSErrorXelException(SSError.NUM);
    } else {
      String result = Integer.toOctalString(dec);
      if(dec < 0){
        result = result.substring(result.length()-10, result.length());
      }
View Full Code Here

   */
  public static Object engineerDelta(Object[] args, XelContext ctx) {
    double num1 = CommonFns.toNumber(args[0]).doubleValue();
    double num2 = CommonFns.toNumber(args[1]).doubleValue();
    if(Double.isNaN(num1) || Double.isNaN(num2)) {
      throw new SSErrorXelException(SSError.VALUE);
    } else {
      int result = 0;
      if(num1==num2) {
        result = 1;
      }
View Full Code Here

   */
  public static Object engineerErf(Object[] args, XelContext ctx) {
    double lowerLimit = CommonFns.toNumber(args[0]).doubleValue();
    double upperLimit = 0.0;
    if(lowerLimit < 0 || upperLimit < 0) {
      throw new SSErrorXelException(SSError.NUM);
    } else {
      try {
        double erf = Erf.erf(lowerLimit);
        if(args.length == 2) {
          upperLimit = CommonFns.toNumber(args[1]).doubleValue();
          erf = Erf.erf(upperLimit) - erf;
        }
        return new Double(erf);
      } catch (MathException e) {
        throw new SSErrorXelException(SSError.VALUE);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.zkoss.zss.engine.xel.SSErrorXelException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.