/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.core.util;

import java.util.HashSet;
import java.util.Set;

/**
 * Set-related convenience methods.
 */
public final class SetUtils {
    private SetUtils() {
    }

    /**
     * Extracts the Strings from a Set that start with a given prefix.
     *
     * @param set a Set of Strings (assumed to all be non-{@code null})
     * @param prefix the prefix to look for in the string set
     * @return an array of the matching strings from the given set
     */
    public static String[] prefixSet(final Set<String> set, final String prefix) {
        final Set<String> prefixSet = new HashSet<>();
        for (final String str : set) {
            if (str.startsWith(prefix)) {
                prefixSet.add(str);
            }
        }
        return prefixSet.toArray(new String[prefixSet.size()]);
    }
}

@@ -843,34 +843,8 @@
 l;%0A%0A
-import java.util.HashSet;%0A
 impo
@@ -936,16 +936,83 @@
 Utils %7B%0A
+%0A    private static final String%5B%5D EMPTY_STRINGS = new String%5B0%5D;%0A%0A
     priv
@@ -1027,21 +1027,16 @@
 tils() %7B
-%0A    
 %7D%0A%0A    /
@@ -1049,70 +1049,90 @@
   * 
-Extracts the Strings from a Set that
+Collects strings
  start
+ing
  with 
-a
+the
  given 
-prefix
+%7B@code prefix%7D from the given %7B@code set%7D
 .%0A  
@@ -1160,59 +1160,33 @@
 t a 
-S
+(nullable) s
 et of 
-S
+s
 trings
- (assumed to all be non-%7B@code null%7D)
 %0A   
@@ -1203,19 +1203,17 @@
  prefix 
-the
+a
  prefix 
@@ -1412,185 +1412,176 @@
     
-final Set%3CString%3E prefixSet = new HashSet%3C%3E();%0A        for (final String str : set) %7B%0A
+if (set == null) %7B%0A            return EMPTY_STRINGS;%0A   
      
+%7D%0A
        
-if (str.startsWith(prefix)) %7B%0A                prefixSet.add(str);%0A            %7D
+ return set%0A                .stream()%0A                .filter(string -%3E string.startsWith(prefix))
 %0A   
@@ -1581,34 +1581,32 @@
 x))%0A        
-%7D%0A
         
 return prefi
@@ -1597,24 +1597,8 @@
     
-return prefixSet
 .toA
@@ -1606,36 +1606,21 @@
 ray(
-new 
 String%5B
-prefixSet.size()%5D
+%5D::new
 );%0A 
@@ -1624,10 +1624,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Fix NPE in SetUtils#prefixSet(). (#612)