package liferay;

/**
*
*/ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern; /**
* @author Ivan
*
*/
public class TextUtil { private static Pattern N = Pattern.compile("\n");
private static Pattern R = Pattern.compile("\r");
private static Pattern RN = Pattern.compile("\r\n");
private static Pattern NR = Pattern.compile("\n\r");
private final static String BR = "<br/>"; private static NumberFormat decimalFormat = DecimalFormat
.getNumberInstance(); public static String doubleToText(double number) {
String txt = doubleToText(number, );
return txt;
} public static String doubleToText(double number, int digit) {
String txt = "";
if (number > ) {
decimalFormat.setMaximumFractionDigits(digit);
txt = decimalFormat.format(number);
}
return txt;
} public static String doubleToText2(double number, int digit) {
String txt = "";
if (number > ) {
DecimalFormat decimalFormat2 = new DecimalFormat();
decimalFormat2.setGroupingSize();
decimalFormat2.setMaximumFractionDigits(digit);
txt = decimalFormat2.format(number);
}
return txt;
} public static String doubleToText(double number, String format) {
if (format.equals("")) {
format = "#,##0.00";
} String txt = "";
if (number > ) {
DecimalFormat decimalFormat = new DecimalFormat(format);
txt = decimalFormat.format(number);
}
return txt;
} public static String textToHtml(String txt) {
Matcher m = RN.matcher(txt);
txt = m.replaceAll(BR);
m = NR.matcher(txt);
txt = m.replaceAll(BR);
m = N.matcher(txt);
txt = m.replaceAll(BR);
m = R.matcher(txt);
txt = m.replaceAll(BR);
return txt;
} public static void main(String[] args) {
// long longDuration = new Date().getTime() - 46450000;
// longDuration = new Date().getTime() - longDuration;
// double doubleDuration = longDuration;
// doubleDuration = doubleDuration / 86400000;
// System.out.println(doubleDuration);
// System.out.println(doubleToText(doubleDuration)); String sql = getRandomString();
System.out.println(sql); } public static String doSubAssignLength(String str, int length) {
String commtents = null;
if (str.length() > length) {
commtents = str.substring(, length - ) + "...";
} else {
commtents = str;
}
return commtents;
} public static String doSubString(String str) {
String commtents = null;
if (str.length() > ) {
commtents = str.substring(, ) + "...";
} else {
commtents = str;
}
return commtents;
} public static String getURL(String layoutId, String url) {
StringBuffer buffer = new StringBuffer();
buffer.append(url);
if (layoutId != null && !"".equals(layoutId)) {
int start = url.lastIndexOf("/");
int end = url.indexOf("?");
buffer.replace(start, end, layoutId);
}
return buffer.toString();
} public static String toUpperCase(String tableName) {
String prefix = tableName.substring(, ).toUpperCase();
String results = prefix + tableName.substring();
return results;
} public static String getRandomString(int length) {
char[] charArray = new char[length];
for (int i = ; i < length; i++) {
Random r = new Random();
int n = r.nextInt();
while (n < || (n > && n < ) || (n > && n < )
|| n > ) {// (!((n>=48 && n<=57) || (n>=65 && n<=90)
// && (n>=97 && n<=122))){
n = r.nextInt();
}
charArray[i] = (char) n;
}
return String.valueOf(charArray);
} public static String convertFileSize(long filesize) {
String strUnit = "Bytes";
String strAfterComma = "";
int intDivisor = ;
if (filesize >= * ) {
strUnit = " MB";
intDivisor = * ;
} else if (filesize >= ) {
strUnit = " KB";
intDivisor = ;
}
if (intDivisor == )
return filesize + " " + strUnit; strAfterComma = "" + * (filesize % intDivisor) / intDivisor;
if (strAfterComma == "")
strAfterComma = ".0"; return filesize / intDivisor + "." + strAfterComma + " " + strUnit; } }

Lifyray笑傲江湖之API总结TextUtil的更多相关文章

  1. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

  2. 12306官方火车票Api接口

    2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...

  3. 几个有趣的WEB设备API(二)

    浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...

  4. html5 canvas常用api总结(三)--图像变换API

    canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...

  5. JavaScript 对数据处理的5个API

    JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...

  6. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  7. javascript的api设计原则

    前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...

  8. 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino

    大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...

  9. 在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用

    由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.NET Web API 的书籍少之又少(我们看到的相关内容往往是某本介绍ASP.NET M ...

随机推荐

  1. Ubuntu 12.04 Openstack Essex 安装(单节点)

    这是陈沙克一篇非常好的博文,当时在进行openstack排错的时候,多亏了这篇文章里面有些内容 帮我找到了问题的所在: 原文:http://www.chenshake.com/ubuntu-12-04 ...

  2. fs-extra 文件管理

    一.fs-extra 文件管理 $npm install fs-extra --save 1.创建一个目录 fs.mkdir(path, [mode], [callback(err)]) path 将 ...

  3. [工具] 各种主流 SQLServer 迁移到 MySQL 工具对比

    我之所以会写这篇对比文章,是因为公司新产品研发真实经历过这个痛苦过程(传统基于SQL Server开发的C/S产品转为MySQL云产品). 首次需要数据转换是测试环节,当时为了快速验证新研发云产品性能 ...

  4. iOS8新特性(2)——UIPopoverController和UIPresentationController

    一.以往使用 UIPopoverController 都是只在iPad上使用 /** * UIPopoverController 只能用于iPad,上,iPhone上使用会崩溃 */ -(void)o ...

  5. Spark2 Dataset分析函数--排名函数row_number,rank,dense_rank,percent_rank

    select gender,       age,       row_number() over(partition by gender order by age) as rowNumber,    ...

  6. 7.19python昨日复习和多线程

    关于GIL锁的经典面试题!!

  7. POJ 2240 - Arbitrage - [bellman-ford求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Arbitrage is the use of discrepancies in currenc ...

  8. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...

  9. Sorted sets

    Redis in Action JOSIAH L. CARLSON MANNING Shelter Island ZSETs offer the ability to store a mapping ...

  10. JIRA licence and vulnarability,jenkins,devops

    http://blog.itpub.net/13651903/viewspace-1079918/ http://www.freebuf.com/articles/web/34051.html JIR ...