class Store {

  public static boolean isSubscribedToFeatureSet(
      List<Subscription> subscriptions, String projectName, String featureSetName) {
    // Case 1: Highest priority check, to exclude all matching subscriptions with excluded flag =
    // true
    for (Subscription sub : subscriptions) {
      // If configuration missing, fail
      if (sub.getProject().isEmpty() || sub.getName().isEmpty()) {
        throw new IllegalArgumentException(
            String.format("Subscription is missing arguments: %s", sub.toString()));
      }
      // Match feature set name to pattern
      Pattern patternName = getNamePattern(sub);
      Pattern patternProject = getProjectPattern(sub);
      // SubCase: Project name and feature set name matches and excluded flag is true
      if (patternProject.matcher(projectName).matches()
          && patternName.matcher(featureSetName).matches()
          && sub.getExclude()) {
        return false;
      }
    }
    // Case 2: Featureset is not excluded, check if it is included in the current subscriptions
    // filteredSubscriptions only contain subscriptions with excluded flag = false
    List<Subscription> filteredSubscriptions =
        subscriptions.stream().filter(sub -> !sub.getExclude()).collect(Collectors.toList());

    for (Subscription filteredSub : filteredSubscriptions) {
      // Match feature set name to pattern
      Pattern patternName = getNamePattern(filteredSub);
      Pattern patternProject = getProjectPattern(filteredSub);
      // SubCase: Project name and feature set name matches
      if (patternProject.matcher(projectName).matches()
          && patternName.matcher(featureSetName).matches()) {
        return true;
      }
    }
    return false;
  }

}