Example #1
0
 public static String digest(Object object) {
   try {
     return digest(ObjectUtil.objectToBytes(object));
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
Example #2
0
 public static String sha1(final Object o) {
   try {
     return doDigestForByteArray(ObjectUtil.toArray(o), "SHA-1");
   } catch (IOException e) {
   }
   return null;
 }
Example #3
0
 /**
  * Implementation of the OCL <tt>Collection::count(object : T) : Integer</tt> operation.
  *
  * @param self the source collection
  * @param object an object
  * @return the number of occurrences of the object in the collection
  */
 public static int count(Collection<?> self, Object object) {
   int count = 0;
   for (Object next : self) {
     if (ObjectUtil.equal(next, object)) {
       count++;
     }
   }
   return count;
 }
Example #4
0
  /**
   * Computes the hash of a collection, accounting for the similar hashing of primitive numeric
   * values that OCL considers equal but Java does not.
   *
   * @param c a collection
   * @return its hash
   */
  public static int hashCode(Collection<?> c) {
    int result = 1;

    for (Object next : c) {
      result = 37 * result + ObjectUtil.hashCode(next);
    }

    return result;
  }
Example #5
0
  /**
   * Implementation of the OCL
   *
   * <ul>
   *   <li><tt>OrderedSet::indexOf(object : T) : Integer</tt>
   *   <li><tt>Sequence::indexOf(object : T) : Integer</tt>
   * </ul>
   *
   * operations.
   *
   * @param self the source collection
   * @param object an object
   * @return the index of the object in the source collection
   */
  public static <E> Integer indexOf(Collection<? extends E> self, E object) {
    int index = 1;

    for (E next : self) {
      if (ObjectUtil.equal(object, next)) {
        return index;
      }
      index++;
    }

    return null; // invalid
  }
Example #6
0
 public static boolean isEmpty(String str) {
   return ObjectUtil.isNull(str) || str.length() == 0;
 }
Example #7
0
  /** 计算贝塞尔曲线点 */
  private static void calculateBezier() {
    PointBean mControlPoint; // 贝塞尔控制点
    PointBean mBezierPoint; // 贝塞尔曲线上的点
    PointBean mStartPoint; // 贝塞尔曲线起点
    PointBean mEndPoint; // 贝塞尔曲线终点
    float t = 0.01f; // 默认t取0.01
    float BezierX;
    float BezierY;
    mControlPoint = mBezierPoints.get(1);
    mStartPoint = mBezierPoints.get(0);
    mEndPoint = mBezierPoints.get(2);

    mBezierResult.add(mStartPoint);

    // 先计算两点之间距离,根据距离选择t
    float distance; // 起点和终点两点间距离
    distance = calculateDistance(mStartPoint, mEndPoint);
    t = 1 / distance; // 再根据距离选取t的取值 100->0.01,   10->0.1,   1->1
    float step = t / 2; // 除以2再取多一点的点

    if (t > 0 && t < 1) { // t取值范围
      // 公式 (1-t)^2 * x1 + 2 * t * (1-t) * x0 + t^2 * x2 = x
      for (; t <= 1.0f; t += step) {
        BezierX =
            (float) Math.pow(1 - t, 2) * mBezierPoints.get(0).getX()
                + 2 * t * (1 - t) * mControlPoint.getX()
                + (float) Math.pow(t, 2) * mBezierPoints.get(2).getX();

        BezierY =
            (float) Math.pow(1 - t, 2) * mBezierPoints.get(0).getY()
                + 2 * t * (1 - t) * mControlPoint.getY()
                + (float) Math.pow(t, 2) * mBezierPoints.get(2).getY();

        mBezierPoint = new PointBean(BezierX, BezierY);
        mBezierResult.add(mBezierPoint);
      }
    }

    mBezierResult.add(mEndPoint);

    switch (Constant.CURRENT_USE_TYPE) {
      case Constant.PAINT:
        ObjectUtil.createBezierLine(mBezierResult);
        break;
      case Constant.FIREWORKS:
        // 需要每个点位置刚好接上,不能重叠
        mDeleteLeftPoints = splicePoints(mBezierResult);
        ObjectUtil.createBezierLine(mDeleteLeftPoints);
        break;
      case Constant.WALLPAPER:
        // 需要先除去一些点
        mDeleteLeftPoints = deletePoints(mBezierResult);
        ObjectUtil.createBezierLine(mDeleteLeftPoints);
        break;
      case Constant.MOSAIC:
        ObjectUtil.createBezierLine(mBezierResult);
        break;
      case Constant.ERASER:
        ObjectUtil.createBezierLine(mBezierResult);
        break;
      default:
        break;
    }
  }
Example #8
0
 @Override
 public int hashCode() {
   return ObjectUtil.nullSafeHashCode(_table) ^ ObjectUtil.nullSafeHashCode(_fk);
 }
Example #9
0
  /**
   * 业务逻辑实现 - 点击统计下载excel
   *
   * @param ws 工作表
   * @param totals 待写入数据
   * @throws WriteException
   */
  @SuppressWarnings("unchecked")
  private static void addLabelExcel(WritableSheet ws, List totals, List columnList)
      throws WriteException {
    int row = 0, column = 0;
    // 设置Excel列中文标题
    Iterator itColumnList = columnList.iterator();
    while (itColumnList.hasNext()) {
      DownloadAttribute columnTitle = (DownloadAttribute) itColumnList.next();
      ws.addCell(new Label(column, row, columnTitle.getExcelName()));
      column++;
    }
    if (totals != null && totals.size() != 0) {
      Iterator itTotals = totals.iterator();
      WritableFont detFont =
          new WritableFont(
              WritableFont.ARIAL,
              10,
              WritableFont.NO_BOLD,
              false,
              UnderlineStyle.NO_UNDERLINE,
              jxl.format.Colour.BLACK);
      NumberFormat pnf = new NumberFormat("0.00"); // 用于Price Number的格式
      WritableCellFormat priceFormat = new WritableCellFormat(detFont, pnf);
      NumberFormat nf = new NumberFormat("0"); // 用于Number的格式
      WritableCellFormat numberFormat = new WritableCellFormat(detFont, nf);

      WritableFont stringFont =
          new WritableFont(
              WritableFont.ARIAL,
              10,
              WritableFont.NO_BOLD,
              false,
              UnderlineStyle.NO_UNDERLINE,
              jxl.format.Colour.BLACK);
      WritableCellFormat stringFormat = new WritableCellFormat(stringFont);
      WritableCellFormat stringWrapFormat = new WritableCellFormat(stringFont);
      stringWrapFormat.setWrap(true);

      row = 1;
      while (itTotals.hasNext()) {
        Object obj = itTotals.next();
        Map subTotals = obj instanceof Map ? (HashMap) obj : ObjectUtil.transform(obj);
        Iterator itColumnName = columnList.iterator();
        column = 0;
        while (itColumnName.hasNext()) {
          DownloadAttribute columnInfo = (DownloadAttribute) itColumnName.next();
          String columnType = columnInfo.getExcelType();
          String columnName = columnInfo.getRowName();
          Object columnValue = subTotals.get(columnName);
          if (columnValue == null) {
            column++;
            continue;
          }
          String strValue = null;
          if (columnValue instanceof Date) {
            strValue = DateTimeUtil.getFormatDateTime((Date) columnValue);
          } else {
            strValue = columnValue.toString();
          }
          // 设置内容
          if (columnType.equals("Label")) {
            if (columnValue.toString().indexOf("\r\n") > 0) {
              ws.addCell(new Label(column, row, strValue, stringWrapFormat));
            } else {
              ws.addCell(new Label(column, row, strValue, stringFormat));
            }
          }
          if (columnType.equals("Number"))
            ws.addCell(
                new jxl.write.Number(column, row, Double.parseDouble(strValue), numberFormat));
          if (columnType.equals("Price"))
            ws.addCell(
                new jxl.write.Number(column, row, Double.parseDouble(strValue), priceFormat));
          column++;
        }
        row++;
      }
    }
  }