/** * Pie图存在数据类型的判断 * * @param dataList - 需要转发的list * @param oldKey - 需要查找的key * @param newKey - 替换后的新key * @param sign - 1:int,2:String,3:object * @return */ @SuppressWarnings({"unchecked", "rawtypes"}) public static List changeList(List<Map> dataList, String oldKey, String newKey, int sign) { if (oldKey == null || newKey == null || oldKey.equals(newKey)) return dataList; // 不需要转列(名称为空,或相等) ArrayList newList = new ArrayList(); for (Map object : dataList) { Map newMap = new HashMap(); Iterator it = object.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); if (oldKey.equalsIgnoreCase(String.valueOf(key))) { if (sign == 1) { newMap.put(newKey, StringUtil.convertStr(value + "", 0)); newMap.put(oldKey, StringUtil.convertStr(value + "", 0)); } if (sign == 2) { newMap.put(newKey, value + ""); newMap.put(oldKey, value + ""); } if (sign == 3) { newMap.put(newKey, value); newMap.put(oldKey, value); } } else { newMap.put(key, value); } } newList.add(newMap); } return newList; }
public static void main(String[] args) throws Exception { String name = "null"; System.out.println("2--->" + StringUtil.rep(name, "")); // String text= "據記載" ; // System.out.println( Jsoup.parse(html)) ; // System.out.println( Jsoup.parse(text).text()) ; // System.out.println(StringUtil.replaceString("💥")); // String // para="para=|userIds=1652752642,1770318172|indexType=NUM_OF_TWEETS|freq=week|dateId=2010-11-30"; // System.out.print // System.out.println(getPara(para,"userIds")); // Date myDate = StringUtil.getDate(1297673149); // System.out.println(StringUtil.getSearchKey("中国|人", "")) ; // SimpleDateFormat fm2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // System.out.println(myDate.toLocaleString()); // System.out.println(myDate.toLocaleString()); // System.out.println(fm2.format(myDate)); // SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // sd.setTimeZone(TimeZone.getTimeZone("GMT+8")); // String strDate = sd.format(new Date(1297673149*1000L)); // System.out.println("正八区当前时间:"+strDate); // System.out.println(""+new java.text.SimpleDateFormat("yyyy MM-dd HH:mm:ss").format(new // java.util.Date // (1297673149*1000L))); // String timezone_info = System.getProperty("user.timezone"); // System.out.println("当前的时区:"+timezone_info); // System.out.println("时区信息:"+TimeZone.getDefault()); // String smallStr = "3,5,7"; // String bigStr = "1,2,3,4,5,6,7"; // String otherStr = StringUtil.findOtherList(smallStr, bigStr); // System.out.print(otherStr); // String str = "中国"; // str = new String(str.getBytes("utf-8"),"ISO-8859-1"); // System.out.println(str); // String str1 =URLEncoder.encode(str,"utf-8"); // System.out.println(str1); // String sign = "clientid=10283&keywords=china&media=1&key=12345678"; // // 331caff5b9bf29f54debebc8d659c198 // 331caff5b9bf29f54debebc8d659c198 // System.out.println(StringUtil.MD5(sign)); // int num = 1413; // int length = 11; // String str = StringUtil.makeIntToString(num, length); // System.out.println(str); // num = 1313144143; // length = 9; // str = StringUtil.makeIntToString(num, length); // System.out.println(str); // String str = "/(00)\\"; // System.out.println(StringUtil.getValidContent(str)); // str = str.replace("\\", ""); // String str = "♪秦小岚😘๓小米『米娅美妆』适合初学者的完美的翅膀眼线教程||『米娅美妆』适合初学者的完美的翅膀眼线教程" ; // System.out.println(StringFilter(str)); // String docId = "2014102800000004493"; // int folderId = 1413; // String hId = StringUtil.genernateHID(docId, folderId); // System.out.println(hId); }
/** * 补齐小时段/工作日数据 * * @param data - 需要补齐的数据 * @param sign - 需要补齐的类型,1:小时段,2:工作日 * @param scene - 场景StatUserBar,StatUserBarLine * @return */ @SuppressWarnings({"unchecked", "rawtypes"}) public List addOther(List data, int sign, String scene) { if (data == null || data.size() <= 0) return data; int maxLeng = 0; String key = ""; int start = 0; if (sign == 1) { maxLeng = 24; if (data.size() == maxLeng) return data; key = "HOUR_ID"; } else if (sign == 2) { maxLeng = 8; start = 1; if (data.size() == maxLeng) return data; if (scene != null && scene.trim().equals("statUserBarLine")) key = "WEKDAY_ID"; if (scene != null && scene.trim().equals("statUserBar")) key = "WORKDAY_ID"; } else if (sign == 3) { // 补齐粉丝数分布 maxLeng = 13; key = "TYPE"; } for (int i = start; i < maxLeng; i++) { boolean ret = false; for (int j = 0; j < data.size(); j++) { Map map = (Map) data.get(j); int t = StringUtil.convertStr(map.get(key) + "", 0); if (i == t) { ret = true; break; } } if (!ret) { Map map = new HashMap(); // map.put("Post", 0); map.put(key, i); // map.put("Thread", 0); if (start == 1) data.add(i - 1, map); // 每工作日 else data.add(i, map); // 每小时 } } return data; }
/** * 将DocId和FolderId进行组合,生产HBase rowKey docId:yyyyMMdd+11位数 folderId:?位数 * * @param docId - 文章编号 * @param folderId - 所属任务编号 * @return HID - HBase rowKey:yyyyMMdd+folderId+0?+remove(0)+docId */ public static String genernateHID(String docId, int folderId) { if (docId == null || docId.trim().equals("") || docId.trim().length() != 19 || folderId == 0) return null; int maxLength = 19; // 生成HID的长度 String yyyyMMdd = docId.substring(0, 8); String thisDocId = docId.substring(9, docId.length()); long myId = StringUtil.convertStrToLong(thisDocId, 0); thisDocId = myId + ""; int length = thisDocId.length(); String folderIds = folderId + ""; int folderLength = folderIds.length(); String zeros = ""; for (int i = 0; i < maxLength - 8 - length - folderLength; i++) { zeros += "0"; } String hId = yyyyMMdd + folderId + "" + zeros + thisDocId; return hId; }
public static String formatNum(Object obj) { DecimalFormat df = new DecimalFormat("###,###,###.##"); return df.format(Double.valueOf(StringUtil.rep(obj, "0"))); }