public static boolean isMatch()

in dubbo-common/src/main/java/org/apache/dubbo/common/ServiceKey.java [72:145]


        public static boolean isMatch(ServiceKey rule, ServiceKey target) {
            // 1. match interface (accurate match)
            if (!Objects.equals(rule.getInterfaceName(), target.getInterfaceName())) {
                return false;
            }

            // 2. match version (accurate match)
            // 2.1. if rule version is *, match all
            if (!CommonConstants.ANY_VALUE.equals(rule.getVersion())) {
                // 2.2. if rule version is null, target version should be null
                if (StringUtils.isEmpty(rule.getVersion()) && !StringUtils.isEmpty(target.getVersion())) {
                    return false;
                }
                if (!StringUtils.isEmpty(rule.getVersion())) {
                    // 2.3. if rule version contains ',', split and match each
                    if (rule.getVersion().contains(CommonConstants.COMMA_SEPARATOR)) {
                        String[] versions = rule.getVersion().split("\\" + CommonConstants.COMMA_SEPARATOR, -1);
                        boolean match = false;
                        for (String version : versions) {
                            version = version.trim();
                            if (StringUtils.isEmpty(version) && StringUtils.isEmpty(target.getVersion())) {
                                match = true;
                                break;
                            } else if (version.equals(target.getVersion())) {
                                match = true;
                                break;
                            }
                        }
                        if (!match) {
                            return false;
                        }
                    }
                    // 2.4. if rule version is not contains ',', match directly
                    else if (!Objects.equals(rule.getVersion(), target.getVersion())) {
                        return false;
                    }
                }
            }

            // 3. match group (wildcard match)
            // 3.1. if rule group is *, match all
            if (!CommonConstants.ANY_VALUE.equals(rule.getGroup())) {
                // 3.2. if rule group is null, target group should be null
                if (StringUtils.isEmpty(rule.getGroup()) && !StringUtils.isEmpty(target.getGroup())) {
                    return false;
                }
                if (!StringUtils.isEmpty(rule.getGroup())) {
                    // 3.3. if rule group contains ',', split and match each
                    if (rule.getGroup().contains(CommonConstants.COMMA_SEPARATOR)) {
                        String[] groups = rule.getGroup().split("\\" + CommonConstants.COMMA_SEPARATOR, -1);
                        boolean match = false;
                        for (String group : groups) {
                            group = group.trim();
                            if (StringUtils.isEmpty(group) && StringUtils.isEmpty(target.getGroup())) {
                                match = true;
                                break;
                            } else if (group.equals(target.getGroup())) {
                                match = true;
                                break;
                            }
                        }
                        if (!match) {
                            return false;
                        }
                    }
                    // 3.4. if rule group is not contains ',', match directly
                    else if (!Objects.equals(rule.getGroup(), target.getGroup())) {
                        return false;
                    }
                }
            }

            return true;
        }