DisableInfo implements JsonSerializable { @NonNull public static List<DisableInfo> filter(@NonNull Collection<DisableInfo> disableInfos, @NonNull String sdkVersion, long appVersion) { JsonSerializable versionObject = VersionUtils.createVersionObject(appVersion); List<DisableInfo> filtered = new ArrayList<>(); for (DisableInfo info : disableInfos) { if (info.sdkVersionConstraints != null) { boolean isSdkVersionMatch = false; for (String constraint : info.sdkVersionConstraints) { if (IvyVersionMatcher.newMatcher(constraint).apply(sdkVersion)) { isSdkVersionMatch = true; break; } } if (!isSdkVersionMatch) { continue; } } if (info.appVersionPredicate != null && !info.appVersionPredicate.apply(versionObject)) { continue; } filtered.add(info); } return filtered; } private  DisableInfo(@NonNull Builder builder); @NonNull static List<DisableInfo> filter(@NonNull Collection<DisableInfo> disableInfos, @NonNull String sdkVersion, long appVersion); @NonNull @Override JsonValue toJsonValue(); @Override boolean equals(@Nullable Object o); @NonNull static DisableInfo fromJson(@NonNull JsonValue value); @Nullable Set<String> getSdkVersionConstraints(); @Nullable JsonPredicate getAppVersionPredicate(); @NonNull Set<String> getDisabledModules(); long getRemoteDataRefreshInterval(); static Builder newBuilder();  }
@Test public void testFilter() { DisableInfo pushModule = DisableInfo.newBuilder() .setDisabledModules(Collections.singleton("push")) .build(); DisableInfo messageCenter = DisableInfo.newBuilder() .setDisabledModules(Collections.singleton("message_center")) .setRemoteDataInterval(100) .setSDKVersionConstraints(Collections.singleton("6.0.0")) .build(); DisableInfo allModules = DisableInfo.newBuilder() .setDisabledModules(Modules.ALL_MODULES) .setRemoteDataInterval(50000) .setSDKVersionConstraints(Collections.singleton("5.0.+")) .build(); DisableInfo sdkVersion = DisableInfo.newBuilder() .setDisabledModules(Modules.ALL_MODULES) .setAppVersionPredicate(VersionUtils.createVersionPredicate(ValueMatcher.newNumberRangeMatcher(5.0, 6.0))) .build(); List<DisableInfo> result = DisableInfo.filter(Arrays.asList(pushModule, messageCenter, allModules, sdkVersion), "8.0.0", 1); assertTrue(result.contains(pushModule)); result = DisableInfo.filter(Arrays.asList(pushModule, messageCenter, allModules, sdkVersion), "6.0.0", 1); assertTrue(result.contains(pushModule)); assertTrue(result.contains(messageCenter)); result = DisableInfo.filter(Arrays.asList(pushModule, messageCenter, allModules, sdkVersion), "5.0.4", 1); assertTrue(result.contains(pushModule)); assertTrue(result.contains(allModules)); result = DisableInfo.filter(Arrays.asList(messageCenter, allModules, sdkVersion), "9.0.4", 1); assertTrue(result.isEmpty()); result = DisableInfo.filter(Arrays.asList(messageCenter, allModules, sdkVersion), "9.0.4", 5); assertTrue(result.contains(sdkVersion)); }