fs-danaus
2024-08-09 7204e3dff0490732e861ccd1338e3e3c31d768c6
提交 | 用户 | age
a6a76f 1 package com.yc.utils;
F 2
3 import com.yc.action.grid.GridUtils;
4
1fbd50 5 import lombok.AllArgsConstructor;
J 6 import lombok.Data;
7
a6a76f 8 import java.net.URLDecoder;
F 9 import java.util.ArrayList;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15
16
17 public class Test
18 {
19     /**
20      * 验证ip是否合法
21      * 
22      * @param text
23      *            ip地址
24      * @return 验证信息
25      */
26     public static String ipCheck(String text) {
27         if (text != null && !text.isEmpty()) {
db9674 28             // 定义正则表达式1
a6a76f 29             String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
F 30                     + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
31                     + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
32                     + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
33             // 判断ip地址是否与正则表达式匹配
34             if (text.matches(regex)) {
35                 // 返回判断信息
36                 return text + "是一个合法的IP地址!";
37             } else {
38                 // 返回判断信息
39                 return text + "不是一个合法的IP地址!";
40             }
41         }
42         // 返回判断信息
43         return "请输入要验证的IP地址!";
44     }
45     private static String procHy(String str){ //去掉有超链接内容只返回内容
46
47         String regex="<(\\S*?) [^>]*>.*?</\\1>|<.*? />";
48         //String regex = "<a.*>(.*)</a>";
49         Pattern pt=Pattern.compile(regex);
50         String temp=str;
51         //保存超链接外的内容
52         String otherStr=null;
53
54         Matcher mt=pt.matcher(temp.replaceAll("<A", "<a").replaceAll("A>", "a>"));//.replaceAll("<A", "<a").replaceAll("A>", "a>")
55         StringBuilder sb=new StringBuilder();
56         while(mt.find())
57         {
58
59             String s2=">.*?</(a|font)>";//标题部分
60             Pattern pt2=Pattern.compile(s2);
61             Matcher mt2=pt2.matcher(mt.group());
62            if(otherStr==null){
63                otherStr=temp.replaceAll(mt.group()," ");
64            }else{
65                otherStr=otherStr.replaceAll(mt.group()," ");
66            }
67             while(mt2.find())
68             {
69                 String tm=mt2.group().replaceAll(">|</a>|</font>","");
70                 sb.append(tm).append("  ");
71             }
72
73         }
74         return "".equals(sb.toString())?str:(otherStr+sb.toString());
75
76     }
77   public static void main(String[] args) throws Exception {
c79713 78 //jinwu
1fbd50 79     //  System.out.println(MD5Util.string2MD5("jinwu"));
J 80     //  System.out.println(LocalTime.parse("18:30",DateTimeFormatter.ofPattern("HH:mm")).getHour());
c79713 81       //System.out.println(LocalDateTime.now().plusMinutes(30).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
a6a76f 82
c79713 83   }
1fbd50 84   //@Data
J 85   //@AllArgsConstructor
c79713 86     public class Student {
F 87         private String name;
88         private int age;
89         private Integer score;
a6a76f 90
F 91       //BuildFormat.createImage("e:/456.jpg",bufferedImage);
92      // final byte[] bytes = RSATool.decryptBASE64("abc=");
93 //      System.out.println(URLDecoder.decode("{\n" +
94 //              "\t\"customer\": {\n" +
95 //              "\t\t\"cltName\": \"测试练习人\",\n" +
96 //              "\t\t\"tel\": \"123123123\",\n" +
97 //              "\t\t\"tel2\": null,\n" +
98 //              "\t\t\"propertyAddress\": \"测试地址\",\n" +
99 //              "\t\t\"parentCltCode\": \"286663\",\n" +
100 //              "\t\t\"parentCltName\": \"苏州每淘-\n","utf-8"));
101 // HashMap map=new HashMap();
102 //
103 // map.put("formid",120201);
104 // map.put("headflag",1);
105 //      GFieldEntity gFieldEntity=GridUtils.fromJson(GridUtils.toJson(map),GFieldEntity.class);
1fbd50 106       //System.out.println(URLDecoder.decode("DD00018;00A48Q","utf-8"));
a6a76f 107   }
F 108   public void st(){
109       Map map=new HashMap();
110       Ac ac=new Ac();
111       ac.setBol(true);
112       map.put("a",ac.isBol());
113       System.out.println(GridUtils.toJson(map));
114   }
115   public  class Ac{
116         boolean bol;
117
118       public boolean isBol() {
119           return bol;
120       }
121
122       public void setBol(boolean bol) {
123           this.bol = bol;
124       }
125   }
126     public static boolean isMessyCode(String strName) {
127         try {
128             Pattern p = Pattern.compile("\\s*|\t*|\r*|\n*");
129             Matcher m = p.matcher(strName);
130             String after = m.replaceAll("");
131             String temp = after.replaceAll("\\p{P}", "");
132             char[] ch = temp.trim().toCharArray();
133
134             int length = (ch != null) ? ch.length : 0;
135             for (int i = 0; i < length; i++) {
136                 char c = ch[i];
137                 if (!Character.isLetterOrDigit(c)) {
138                     String str = "" + ch[i];
139                     if (!str.matches("[\u4e00-\u9fa5]+")) {
140                         return true;
141                     }
142                 }
143             }
144         } catch (Exception e) {
145             e.printStackTrace();
146         }
147
148         return false;
149     }
150   public static List<String> getStrRepInfo(String str, String jieFu) {
151     String strTi = str;
152     List<String> list = new ArrayList<String>();
153     String str1 = "";
154     while (strTi.indexOf(jieFu) != -1) {
155         strTi = strTi.substring(strTi.indexOf(jieFu) + 1);
156         if (str.indexOf(jieFu) != -1) {
157         str1 = strTi.substring(0, strTi.indexOf(jieFu));// .trim()
158         if (!str1.equals("") || !jieFu.equals("&")) {
159             //if (!haseSame(str1, list)) {
160         //    list.add(str1);// 为防止信息字段为有大写,即不转换成小写,不然无法替换数据
161            // }
162             strTi = strTi.substring(strTi.indexOf(jieFu) + 1);
163         }
164         }
165
166     }
167     return list;
168   }
169
170   public static void ss(){
171     List<Integer> num=new ArrayList();
172     List<Integer> newNum=new ArrayList();
173
174     //初始化
175     for(int i=0;i<2016;i++){
176         num.add(i+1);
177     }
178       for(int i=0;i<num.size();i=i+4){
179           if(i+2>num.size()) break;
180           int one= num.get(i);
181
182           int two= num.get(i+2);
183           num.remove(i );
184           num.remove(i +2);
185           if(one%2!=0&&two%2!=0){//奇数
186               num.add((one+two)/2);
187           }
188
189
190
191       }
192       for(int i=0;i<num.size();i=i+2){
193          // if(i+2>num.size()) break;
194           int one= num.get(i);
195
196           int two= num.get(i+1);
197           num.remove(i );
198           num.remove(i +1);
199       if(one%2==0&&two%2==0){
200               num.add((one+two)/2);
201           }
202
203
204
205
206       }
207       System.out.println("奇数:"+num.size());
208   }
209   
210 }
211