コード例 #1
0
ファイル: Token.java プロジェクト: nikhi/basex
  /**
   * Creates a byte array representation from the specified double value; inspired by Xavier Franc's
   * Qizx/open processor.
   *
   * @param dbl double value to be converted
   * @return byte array
   */
  public static byte[] token(final double dbl) {
    final byte[] b = tok(dbl);
    if (b != null) return b;

    final double a = Math.abs(dbl);
    return chopNumber(token(a >= 1e-6 && a < 1e6 ? DD.format(dbl) : SD.format(dbl)));
  }
コード例 #2
0
ファイル: Token.java プロジェクト: nikhi/basex
 /**
  * Checks if the specified value equals a constant token.
  *
  * @param dbl value to be converted
  * @return byte array or zero, or {@code null}
  */
 private static byte[] tok(final double dbl) {
   if (dbl == Double.POSITIVE_INFINITY) return INF;
   if (dbl == Double.NEGATIVE_INFINITY) return NINF;
   if (dbl == 0) return 1 / dbl > 0 ? ZERO : MZERO;
   if (Double.isNaN(dbl)) return NAN;
   final double a = Math.abs(dbl);
   if (a < 1e6) {
     final int i = (int) dbl;
     if (i == dbl) return token(i);
   }
   return null;
 }
コード例 #3
0
ファイル: Token.java プロジェクト: nikhi/basex
  /**
   * Creates a byte array representation from the specified float value.
   *
   * @param flt float value to be converted
   * @return byte array
   */
  public static byte[] token(final float flt) {
    final byte[] b = tok(flt);
    if (b != null) return b;

    // not that brilliant here.. no chance for elegant code either
    // due to the nifty differences between Java and XQuery
    for (int i = 0; i < FLT.length; ++i) if (flt == FLT[i]) return FLTSTR[i];
    final float a = Math.abs(flt);
    final boolean small = a >= 1e-6f && a < 1e6f;
    String s1 = small ? DF.format(flt) : SF.format(flt);
    final String s2 = Float.toString(flt);
    if (s2.length() < s1.length() && (!s2.contains("E") || !small)) s1 = s2;
    return chopNumber(token(s1));
  }
コード例 #4
0
 public void run() {
   try {
     if (myPreviousThread != null) myPreviousThread.join();
     Thread.sleep(delay);
     log("> run MouseWheelThread " + amount);
     while (!hasFocus()) {
       Thread.sleep(1000);
     }
     int dir = 1;
     if (System.getProperty("os.name").toUpperCase().indexOf("MAC") != -1) {
       // yay for Apple
       dir = -1;
     }
     robot.setAutoDelay(Math.max(duration / Math.abs(amount), 1));
     for (int i = 0; i < Math.abs(amount); i++) {
       robot.mouseWheel(amount > 0 ? dir : -dir);
     }
     robot.setAutoDelay(1);
   } catch (Exception e) {
     log("Bad parameters passed to mouseWheel");
     e.printStackTrace();
   }
   log("< run MouseWheelThread ");
 }
コード例 #5
0
 /**
  * Parses the given text into a Java class capable of being run
  *
  * @param text the text of the script/class to parse
  * @return the main class defined in the given script
  */
 public Class parseClass(String text) throws CompilationFailedException {
   return parseClass(
       text, "script" + System.currentTimeMillis() + Math.abs(text.hashCode()) + ".groovy");
 }