@@ -1331,7 +1331,7 @@ public static ScriptEngine getScriptEngine(String lang) {
13311331 * @return
13321332 * @throws Exception
13331333 */
1334- private static <T , M extends Map <String , Object >, L extends List <Object >> M operate (Operation opt , M targetChild
1334+ public static <T , M extends Map <String , Object >, L extends List <Object >> M operate (Operation opt , M targetChild
13351335 , M real , @ NotNull Parser <T , M , L > parser ) throws Exception {
13361336 if (targetChild == null ) {
13371337 return real ;
@@ -1522,7 +1522,7 @@ public static void verifyType(@NotNull String tk, @NotNull String tv, Object rv,
15221522 * @param parser
15231523 * @throws Exception
15241524 */
1525- private static <T , M extends Map <String , Object >, L extends List <Object >> void verifyValue (@ NotNull String tk
1525+ public static <T , M extends Map <String , Object >, L extends List <Object >> void verifyValue (@ NotNull String tk
15261526 , @ NotNull Object tv , @ NotNull M real , @ NotNull Parser <T , M , L > parser ) throws Exception {
15271527 if (tv == null ) {
15281528 throw new IllegalArgumentException ("operate operate == VERIFY " + tk + ":" + tv + " , >> tv == null!!!" );
@@ -1576,7 +1576,7 @@ else if (tk.endsWith("~")) { // 正则匹配
15761576 }
15771577 }
15781578 else if (tk .endsWith ("{}" )) { //rv符合tv条件或在tv内
1579- if (tv instanceof String ) {//TODO >= 0, < 10
1579+ if (tv instanceof String ) { //TODO >= 0, < 10
15801580 verifyCondition ("{}" , real , tk , tv , parser );
15811581 }
15821582 else if (tv instanceof List <?>) {
@@ -1595,26 +1595,6 @@ else if (tv instanceof List<?>) {
15951595 throw new UnsupportedDataTypeException ("服务器Request表verify配置错误!" );
15961596 }
15971597 }
1598- else if (tk .endsWith ("{L}" )) { //字符串长度
1599- if (tv instanceof String ) {
1600- logic = new Logic (tk .substring (0 , tk .length () - 3 ));
1601-
1602- rk = logic .getKey ();
1603- rv = real .get (rk );
1604- if (rv == null ) {
1605- return ;
1606- }
1607- String [] tvs = tv .toString ().split ("," );
1608- for (String tvItem : tvs ) {
1609- if (!verifyRV (tvItem ,rv .toString ())) {
1610- throw new IllegalArgumentException (rk + ":value 中value长度不合法!必须匹配 " + tk + ":" + tv + " !" );
1611- }
1612- }
1613- }
1614- else {
1615- throw new UnsupportedDataTypeException ("服务器Request表verify配置错误!" );
1616- }
1617- }
16181598 else if (tk .endsWith ("<>" )) { //rv包含tv内的值
16191599 logic = new Logic (tk .substring (0 , tk .length () - 2 ));
16201600 rk = logic .getKey ();
@@ -1655,41 +1635,39 @@ else if (tk.endsWith("<>")) { //rv包含tv内的值
16551635 }
16561636 }
16571637
1658- /**
1659- * 校验字符串长度
1660- *
1638+ /**校验字符串长度
16611639 * @param rule 规则
1662- * @param content 内容
1640+ * @param len 长度
16631641 * @return
16641642 * @throws UnsupportedDataTypeException
16651643 */
1666- private static boolean verifyRV (String rule ,String content ) throws UnsupportedDataTypeException {
1644+ public static boolean verifyLength (String rule , int len ) throws UnsupportedDataTypeException {
16671645 String first = null ;
16681646 String second = null ;
16691647 Matcher matcher = VERIFY_LENGTH_PATTERN .matcher (rule );
16701648 while (matcher .find ()) {
1671- first = StringUtil .isEmpty (first )? matcher .group ("first" ): first ;
1672- second = StringUtil .isEmpty (second )? matcher .group ("second" ): second ;
1649+ first = StringUtil .isEmpty (first ) ? matcher .group ("first" ) : first ;
1650+ second = StringUtil .isEmpty (second ) ? matcher .group ("second" ) : second ;
16731651 }
16741652 // first和second为空表示规则不合法
1675- if (StringUtil .isEmpty (first ) || StringUtil .isEmpty (second )){
1653+ if (StringUtil .isEmpty (first ) || StringUtil .isEmpty (second )) {
16761654 throw new UnsupportedDataTypeException ("服务器Request表verify配置错误!" );
16771655 }
16781656
16791657 int secondNum = Integer .parseInt (second );
1680- switch (Objects .requireNonNull (first )){
1658+ switch (Objects .requireNonNull (first )) {
16811659 case ">" :
1682- return content . length () > secondNum ;
1660+ return len > secondNum ;
16831661 case ">=" :
1684- return content . length () >= secondNum ;
1662+ return len >= secondNum ;
16851663 case "<" :
1686- return content . length () < secondNum ;
1664+ return len < secondNum ;
16871665 case "<=" :
1688- return content . length () <= secondNum ;
1666+ return len <= secondNum ;
16891667 case "<>" :
1690- return content .length () != secondNum ;
1691- default :
1668+ return len != secondNum ;
16921669 }
1670+
16931671 // 出现不能识别的符号也认为规则不合法
16941672 throw new UnsupportedDataTypeException ("服务器Request表verify配置错误!" );
16951673 }
@@ -1702,13 +1680,40 @@ private static boolean verifyRV(String rule,String content) throws UnsupportedDa
17021680 * @param parser
17031681 * @throws Exception
17041682 */
1705- private static <T , M extends Map <String , Object >, L extends List <Object >> void verifyCondition (
1683+ public static <T , M extends Map <String , Object >, L extends List <Object >> void verifyCondition (
17061684 @ NotNull String funChar , @ NotNull M real , @ NotNull String tk , @ NotNull Object tv
17071685 , @ NotNull Parser <T , M , L > parser ) throws Exception {
1708- //不能用Parser, 0 这种不符合 StringUtil.isName !
1709- Logic logic = new Logic (tk .substring (0 , tk .length () - funChar .length ()));
1686+ // 不能用Parser, 0 这种不符合 StringUtil.isName !
1687+
1688+ boolean isRange = "{}" .equals (funChar );
1689+
1690+ String k = tk .substring (0 , tk .length () - funChar .length ());
1691+ Logic logic = new Logic (k );
17101692 String rk = logic .getKey ();
1711- Object rv = real .get (rk );
1693+ boolean isLen = isRange && k .endsWith ("[" );
1694+ boolean isJSOnLen = isRange && k .endsWith ("{" );
1695+ k = isLen || isJSOnLen ? rk .substring (0 , rk .length () - 1 ) : rk ;
1696+ Object rv = real .get (k );
1697+ int len = 0 ;
1698+ if (isLen ) {
1699+ len = StringUtil .length (rv , false );
1700+ }
1701+ else if (isJSOnLen ) {
1702+ rv = rv instanceof Map ? ((Map <?, ?>) rv ) : (rv instanceof Collection ? ((Collection <?>) rv ) : JSON .parse (rv ));
1703+ len = rv instanceof Map ? ((Map <?, ?>) rv ).size () : (rv instanceof Collection ? ((Collection <?>) rv ).size () : StringUtil .length (rv , false ));
1704+ }
1705+
1706+ if (isLen || isJSOnLen ) {
1707+ String [] tvs = tv .toString ().split ("," );
1708+ for (String tvItem : tvs ) {
1709+ if (! verifyLength (tvItem , len )) {
1710+ throw new IllegalArgumentException (k + ":value 中value长度不合法!必须匹配 " + tk + ":" + tv + " !" );
1711+ }
1712+ }
1713+
1714+ return ;
1715+ }
1716+
17121717 if (rv == null ) {
17131718 return ;
17141719 }
0 commit comments