| 8 | import java.util.Random; |
| 9 | |
| 10 | public class CommonUtils { |
| 11 | public static HashMap hashMapClone(HashMap source,HashMap destination){ |
| 12 | if(!source.isEmpty()){ |
| 13 | destination.clear(); |
| 14 | Iterator iterator = source.keySet().iterator(); |
| 15 | while (iterator.hasNext()){ |
| 16 | String key= (String) iterator.next(); |
| 17 | destination.put(key,source.get(key)); |
| 18 | } |
| 19 | return destination; |
| 20 | } |
| 21 | return new HashMap(); |
| 22 | } |
| 23 | |
| 24 | public static Model modelSet(HashMap<String,String> hashMap,Model model){ |
| 25 | if(!hashMap.isEmpty()){ |
| 26 | Iterator<String> iterator = hashMap.keySet().iterator(); |
| 27 | while (iterator.hasNext()){ |
| 28 | String key=iterator.next(); |
| 29 | model.addAttribute(key,hashMap.get(key)); |
| 30 | } |
| 31 | } |
| 32 | if(InfoUtils.openProxy){ //自动加上代理设置 |
| 33 | model.addAttribute("proxyset",String.format("proxy->%s://%s:%s@%s:%s", |
| 34 | InfoUtils.ProxyType,InfoUtils.ProxyUsername,InfoUtils.ProxyPassword,InfoUtils.ProxyHost,InfoUtils.ProxyPort)); |
| 35 | } |
| 36 | return model; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * 随机数生成 |
| 41 | * @return |
| 42 | */ |
| 43 | public static String Random(){ |
| 44 | String random = String.valueOf(Math.random()); |
| 45 | random = random.substring(random.length() - 8, random.length()); |
| 46 | return random; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * 随机字符串生成 |
| 51 | * @param bit |
| 52 | * @return |
| 53 | */ |
| 54 | public static String RandomStr(int bit){ //随机字符串生成 |
| 55 | String str="abcdefhijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVWXYZ"; |
| 56 | Random rand=new Random(); |
| 57 | StringBuffer buffer = new StringBuffer(); |
| 58 | for (int i = 0; i < bit; i++) { |
| 59 | int anInt = rand.nextInt(str.length()); |
| 60 | buffer.append(str.charAt(anInt)); |
| 61 | } |
| 62 | return buffer.toString(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * 字节数组转16进制 |
| 67 | * @param bytes |
nothing calls this directly
no outgoing calls
no test coverage detected