1:将带宽流量转换单位
package com.chinacache.snp.TransferChannelAlarm.util; import java.text.DecimalFormat; import java.text.Format; public class FormatToSuitableFluxUnit { private static final long K_BIT = 1000; private static final long M_BIT = 1000 * 1000; private static final long G_BIT = 1000 * 1000 * 1000; private static final long T_BIT = 1000 * 1000 * 1000 * 1000L; private static final long P_BIT = 1000 * 1000 * 1000 * 1000L * 1000L; private static final long E_BIT = 1000 * 1000 * 1000 * 1000L * 1000L * 1000L; public static final String BIT_STR = "Byte"; public static final String K_BIT_STR = "KB"; public static final String M_BIT_STR = "MB"; public static final String G_BIT_STR = "GB"; public static final String T_BIT_STR = "TB"; public static final String P_BIT_STR = "PB"; public static final String E_BIT_STR = "EB"; /** * 将以bit表示的带宽,转换为适合显示的带宽单位,精确到小数点后两位 */ public static String getSuitableFluxRepresentation(long fluxInBit) { // 保留小数点后面两位 Format format = new DecimalFormat("#.00"); if (fluxInBit >= E_BIT) { return format.format((double) fluxInBit / E_BIT) + " " + E_BIT_STR; } else if (fluxInBit >= P_BIT) { return format.format((double) fluxInBit / P_BIT) + " " + P_BIT_STR; } else if (fluxInBit >= T_BIT) { return format.format((double) fluxInBit / T_BIT) + " " + T_BIT_STR; } else if (fluxInBit >= G_BIT) { return format.format((double) fluxInBit / G_BIT) + " " + G_BIT_STR; } else if (fluxInBit >= M_BIT) { return format.format((double) fluxInBit / M_BIT) + " " + M_BIT_STR; } else if (fluxInBit >= K_BIT) { return format.format((double) fluxInBit / K_BIT) + " " + K_BIT_STR; } else { return fluxInBit +" "+ BIT_STR; } } /** * 获取合适的带宽单位 */ public static String getSuitableFluxUnit(long fluxInBit) { if (fluxInBit >= E_BIT) { return E_BIT_STR; } else if (fluxInBit >= P_BIT) { return P_BIT_STR; } else if (fluxInBit >= T_BIT) { return T_BIT_STR; } else if (fluxInBit >= G_BIT) { return G_BIT_STR; } else if (fluxInBit >= M_BIT) { return M_BIT_STR; } else if (fluxInBit >= K_BIT) { return K_BIT_STR; } else { return BIT_STR; } } }
2:对list分组(前n个list大小为groupSize)
package com.chinacache.snp.bill.datacontrast.util; import java.util.ArrayList; import java.util.List; import org.apache.commons.collections.CollectionUtils; public class GroupUtil { public static List<List<String>> divideIntoGroups(List<String> list, int groupSize) { if (CollectionUtils.isEmpty(list)) { return null; } List<List<String>> groups = new ArrayList<List<String>>(); List<String> group = null; int totalSize = list.size(); for (int i = 0; i < totalSize; i++) { if (i % groupSize == 0) { group = new ArrayList<String>(); groups.add(group); } group.add(list.get(i)); } return groups; } }
3:java时间区
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //格式日期 TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai"); //时区 sdf.setTimeZone(timezone ); System.out.println(sdf.format(new Date()));
4:读取properties配置文件的常量类
父类:
package com.chinacache.snp.TransferChannelAlarm.util; import java.io.IOException; import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Properties; import java.util.Set; import org.apache.log4j.Logger; /** * 常量配置类,从指定文件读取常量 * */ public class ConfigurableContants { private static final Logger logger = Logger.getLogger(ConfigurableContants.class); protected static Properties p = new Properties(); protected static void init(String propertyFileName) { InputStream in = null; try { in = ConfigurableContants.class.getResourceAsStream(propertyFileName); if (in != null) p.load(in); } catch (IOException e) { logger.error("load " + propertyFileName + " into Contants error"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } } protected static String getProperty(String key, String defaultValue) { return p.getProperty(key, defaultValue); } protected static String getProperty(String key) { return getProperty(key, ""); } /** * 取以","分割的集合属性 * * @param key * @param defaultValue * @return */ protected static Set<String> getSetProperty(String key, String defaultValue) { String[] strings = p.getProperty(key, defaultValue).split(","); HashSet<String> hashSet = new HashSet<String>(strings.length); for (String string : strings) { hashSet.add(string.trim()); } return hashSet; } protected static Set<String> getSetProperty(String key) { return getSetProperty(key, ""); } protected static Date getPropertyWithDateFormate(String key, String dateFormate) { String str = null; Date date = null; try { str = getProperty(key, ""); date = new SimpleDateFormat(dateFormate).parse(str); } catch (ParseException e) { logger.error("Date [" + str + "] Error in Contants"); } return date; } }
子类(每个配置文件一个子类)
package com.chinacache.snp.TransferChannelAlarm.util; /** * 常量类,包括配置文件的常量和程序定义的常量 * */ public final class SystemConstants extends ConfigurableContants { static { init("/system.properties"); } public static final String thresholdValue = getProperty("report.threshold", "1"); public static final String channelState = getProperty("channel.state", "TEST,TRANSFER"); public static final String topSize = getProperty("channel.top.n", "1000"); public static final String mailServer = getProperty("email.server", ""); public static final String addresserUser = getProperty("addresser.user", ""); public static final String addresserPass = getProperty("addresser.pass", ""); public static final String cc = getProperty("cc", "baozong.gao@chinacache.com"); public static String getStringByKey(String key) { return getProperty(key); } }
properties配置文件
report.threshold=0
channel.top.n=100000000
#channel.state=COMMERCIAL,TRANSFER
channel.state=TEST,COMMERCIAL,TRANSFER
TEST=测试
TRANSFER=转走
COMMERCIAL=商用
email.server=corp.chinacache.com
addresser.user=
addresser.pass=
cc=baozong.gao@chinacache.com
channel.top.n=100000000
#channel.state=COMMERCIAL,TRANSFER
channel.state=TEST,COMMERCIAL,TRANSFER
TEST=测试
TRANSFER=转走
COMMERCIAL=商用
email.server=corp.chinacache.com
addresser.user=
addresser.pass=
cc=baozong.gao@chinacache.com
相关推荐
分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类分页工具类
D:\002 我的工具类\001 流 D:\002 我的工具类\001 流\文件操作整体 D:\002 我的工具类\001 流\文件操作整体\FileEncodingUtil.java D:\002 我的工具类\001 流\文件操作整体\FileReadImpl.java D:\002 我的工具类\001...
[工具类] 获得汉字拼音首字母的java工具类 .java [工具类] 获取绝对路径 .java [工具类] 记录log日志文件的工具类 .java [工具类] 连接数据库的工具类 .java [工具类] 使用Java程序来实现HTTP文件的队列下载 ....
本资源包括常用工具类,目前收录了数组工具类、异步工具类、base64工具类、bitmap工具类、缓存工具类、时间工具类、http连接、json、IO、Map、MD5、数据库、SD卡、UbbToHtml等工具类合集
Class类工具 \Cookie工具类 \excel读取 工具类\Java如何生成验证码图片和点击刷新验证码\java获取当前月第一天和最后一天,上个月第一天和最后一天\java实现ftp文件的上传与下载\Json工具类 - JsonUtils.java\JS...
java工具类java工具类java工具类java工具类java工具类java工具类java工具类java工具类java工具类
Java文件工具类
Tools工具类Tools工具类
[工具类] CookieCounter .java.txt [工具类] 验证码img .jsp.txt [工具类] Java中计算任意两个日期之间的工作天数 .java.txt [工具类] java抓取网页 .java.txt [工具类] MD5 .java.txt [工具类] MD5强化版 .java.txt...
Elasticsearch工具类,支持通过标签注释实体类并通过工具类实现对es的映射(把po的结构导入es),和对es的增删查改,包括分页,scroll读取,关联查询等。
jedis的工具类,java代码写的,非常全面,jedis的工具类,java代码写的,非常全面jedis的工具类,java代码写的,非常全面jedis的工具类,java代码写的,非常全面jedis的工具类,java代码写的,非常全面jedis的工具类...
1.[工具类] 读取、打印输出、保存xml .java 2.[工具类] Java中计算任意两个日期之间的工作天数 .java 3.[工具类] MD5 .java 4.[工具类] 时间工具TimeUtil.java 5.[工具类] 通信服务端simpleServer 6.[工具类] 使用...
String工具类String工具类String工具类
1、java工具类RabbitmqUtil是本人封装好的直接使用 2、常用的方法都在里面 3、改一下初始化配置参数就行
Excel日常操作的一些工具类,简化开发,如有其他需求可以联系我,该工具类可满足日常开发的常见需求。
微信公众号支付签名生成工具类和xml和map转换工具类和双向验证请求工具类
使用java工具类可有效的提高开发效率! 没有CSDN积分的朋友到这里源头下载:http://www.javacs.cn/bbs/thread-382-1-1.html 感谢支持 [工具类] CookieCounter .java.txt [工具类] 验证码img .jsp.txt [工具类] Java中...
微信小程序支付所需工具类微信小程序支付所需工具类微信小程序支付所需工具类微信小程序支付所需工具类微信小程序支付所需工具类微信小程序支付所需工具类微信小程序支付所需工具类微信小程序支付所需工具类微信小...
java常用的工具类整理28个java常用的工具类整理28个java常用的工具类整理28个
1、这是bos开发使用的工具类,大概一千多行代码,包括获取当前组织,用户,自定义编码规则等等等等实用的方法,这是一朋友给我的,我在做金蝶开发的时候,帮了我很多很多!感兴趣的可以下来看看,每个方法都有注释。...