private static PathPattern mergePatterns(@Nullable PathPattern oldPattern, PathPattern newPattern) { if (oldPattern != null) { return oldPattern.combine(newPattern); } else { return newPattern; } }
/** * Returns a new instance with URL patterns from the current instance ("this") and * the "other" instance as follows: * <ul> * <li>If there are patterns in both instances, combine the patterns in "this" with * the patterns in "other" using {@link PathPattern#combine(PathPattern)}. * <li>If only one instance has patterns, use them. * <li>If neither instance has patterns, use an empty String (i.e. ""). * </ul> */ @Override public PatternsRequestCondition combine(PatternsRequestCondition other) { List<PathPattern> combined = new ArrayList<>(); if (!this.patterns.isEmpty() && !other.patterns.isEmpty()) { for (PathPattern pattern1 : this.patterns) { for (PathPattern pattern2 : other.patterns) { combined.add(pattern1.combine(pattern2)); } } } else if (!this.patterns.isEmpty()) { combined.addAll(this.patterns); } else if (!other.patterns.isEmpty()) { combined.addAll(other.patterns); } return new PatternsRequestCondition(combined); }
public String combine(String string1, String string2) { PathPattern pattern1 = pp.parse(string1); PathPattern pattern2 = pp.parse(string2); return pattern1.combine(pattern2).getPatternString(); }