/*
 * Copyright 2021 LINE Corporation
 *
 * LINE Corporation 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:
 *
 *   https://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 com.linecorp.centraldogma.common;

import static com.linecorp.centraldogma.common.DefaultPathPattern.ALL;
import static com.linecorp.centraldogma.common.DefaultPathPattern.allPattern;
import static java.util.Objects.requireNonNull;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;

/**
 * A path pattern that represents a variant of glob. For example:
 * <ul>
 *   <li>{@code "/**"} - all files</li>
 *   <li>{@code "*.json"} - all JSON files</li>
 *   <li>{@code "/foo/*.json"} - all JSON files under the directory {@code /foo}</li>
 *   <li><code>"/&#42;/foo.txt"</code> - all files named {@code foo.txt} at the second depth level</li>
 *   <li>{@code "*.json,/bar/*.txt"} - use comma to specify more than one pattern. A file will be matched
 *                                     if <em>any</em> pattern matches.</li>
 * </ul>
 */
public interface PathPattern {

    /**
     * Returns the path pattern that represents all files.
     */
    static PathPattern all() {
        return allPattern;
    }

    /**
     * Creates a path pattern with the {@code patterns}.
     */
    static PathPattern of(String... patterns) {
        return of(ImmutableSet.copyOf(requireNonNull(patterns, "patterns")));
    }

    /**
     * Creates a path pattern with the {@code patterns}.
     */
    static PathPattern of(Iterable<String> patterns) {
        requireNonNull(patterns, "patterns");
        if (Streams.stream(patterns).anyMatch(ALL::equals)) {
            return allPattern;
        }

        return new DefaultPathPattern(ImmutableSet.copyOf(patterns));
    }

    /**
     * Returns the path pattern that concatenates the {@code patterns} using ','.
     */
    String patternString();

    /**
     * Returns the encoded {@link #patternString()} which just encodes a space to '%20'.
     */
    String encoded();
}

@@ -1337,17 +1337,19 @@
  %22*.json
-,
+%22,%22
 /bar/*.t
@@ -1359,28 +1359,19 @@
 %7D - 
-use comma to specify
+if you have
  mor
@@ -1392,32 +1392,109 @@
 tern
-. A file will be matched
+ you can supply them as%0A *                                       %7B@code varargs%7D or %7B@link Iterable%7D.
 %0A * 
@@ -1529,16 +1529,41 @@
         
+  A file will be matched 
 if %3Cem%3Ea

Improve documentation for the PathPattern.java (#725)