Esempio n. 1
0
 /** Return index of the process where the given y position is placed */
 int findIndex(int y) {
   int index = -1;
   // for (int i = 0; i < proct; i++) {
   int groups_size = all_states.visible.size();
   for (int i = 0; i < groups_size; i++) {
     int a = (int) Math.rint(getEvtYCord(i));
     int b = a + (int) Math.rint(yDensity);
     if (y >= a && y <= b) {
       index = i;
       break;
     }
   }
   return index;
 }
Esempio n. 2
0
  /**
   * Converter from a numeric object to Long. Input is checked to be within range represented by
   * Long.
   */
  static Long convertToLong(SessionInterface session, Object a) {

    if (a instanceof Integer) {
      return ValuePool.getLong(((Integer) a).intValue());
    } else if (a instanceof Long) {
      return (Long) a;
    } else if (a instanceof BigDecimal) {
      BigDecimal bd = (BigDecimal) a;

      if (bd.compareTo(MAX_LONG) > 0 || bd.compareTo(MIN_LONG) < 0) {
        throw Error.error(ErrorCode.X_22003);
      }

      return ValuePool.getLong(bd.longValue());
    } else if (a instanceof Double || a instanceof Float) {
      double d = ((Number) a).doubleValue();

      if (session instanceof Session) {
        if (!((Session) session).database.sqlConvertTruncate) {
          d = java.lang.Math.rint(d);
        }
      }

      if (Double.isInfinite(d)
          || Double.isNaN(d)
          || d >= (double) Long.MAX_VALUE + 1
          || d <= (double) Long.MIN_VALUE - 1) {
        throw Error.error(ErrorCode.X_22003);
      }

      return ValuePool.getLong((long) d);
    } else {
      throw Error.error(ErrorCode.X_42561);
    }
  }
Esempio n. 3
0
  /**
   * Converter from a numeric object to Integer. Input is checked to be within range represented by
   * the given number type.
   */
  static Integer convertToInt(SessionInterface session, Object a, int type) {

    int value;

    if (a instanceof Integer) {
      if (type == Types.SQL_INTEGER) {
        return (Integer) a;
      }

      value = ((Integer) a).intValue();
    } else if (a instanceof Long) {
      long temp = ((Long) a).longValue();

      if (Integer.MAX_VALUE < temp || temp < Integer.MIN_VALUE) {
        throw Error.error(ErrorCode.X_22003);
      }

      value = (int) temp;
    } else if (a instanceof BigDecimal) {
      BigDecimal bd = ((BigDecimal) a);

      if (bd.compareTo(MAX_INT) > 0 || bd.compareTo(MIN_INT) < 0) {
        throw Error.error(ErrorCode.X_22003);
      }

      value = bd.intValue();
    } else if (a instanceof Double || a instanceof Float) {
      double d = ((Number) a).doubleValue();

      if (session instanceof Session) {
        if (!((Session) session).database.sqlConvertTruncate) {
          d = java.lang.Math.rint(d);
        }
      }

      if (Double.isInfinite(d)
          || Double.isNaN(d)
          || d >= (double) Integer.MAX_VALUE + 1
          || d <= (double) Integer.MIN_VALUE - 1) {
        throw Error.error(ErrorCode.X_22003);
      }

      value = (int) d;
    } else {
      throw Error.error(ErrorCode.X_42561);
    }

    if (type == Types.TINYINT) {
      if (Byte.MAX_VALUE < value || value < Byte.MIN_VALUE) {
        throw Error.error(ErrorCode.X_22003);
      }
    } else if (type == Types.SQL_SMALLINT) {
      if (Short.MAX_VALUE < value || value < Short.MIN_VALUE) {
        throw Error.error(ErrorCode.X_22003);
      }
    }

    return Integer.valueOf(value);
  }
Esempio n. 4
0
  protected void setValues() {
    int numDisp = dtypeV.size();
    allDispHt = _yPix - rulerHt;
    eachDispHt = (int) Math.rint(allDispHt / (double) numDisp);
    eachDispIHt = eachDispHt - 2 * hBWt;

    if (eachDispHt < 1) eachDispHt = 1; // eachDispHt should be non zero

    calcYDensity();
  }
Esempio n. 5
0
 /** This method gets the length for the given event based on its starting and ending timestamps */
 int getW(double begT, double endT) {
   return ((int) Math.rint(endT * xDensity) - (int) Math.rint(begT * xDensity));
 }
Esempio n. 6
0
 /** This method calculates the x co-ordinate of the givent event from its starting time */
 int getEvtXCord(double t) {
   return (int) (Math.rint(t * xDensity));
 }