PatternContext (@Nullable String id, @Nullable StructuralSearchProfile profile) { if (profile == null) { return null; } final List<PatternContext> patternContexts = profile.getPatternContexts(); if (patternContexts.isEmpty()) { return null; } if (id == null) { return patternContexts.get(0); } return patternContexts.stream().filter(context -> context.getId().equals(id)).findFirst().orElse(patternContexts.get(0)); }