// Path: srcdeps-core/src/main/java/org/srcdeps/core/util/BitStack.java
// public class BitStack {
//     private final BitSet bits = new BitSet();
//     private int size = 0;
// 
//     /**
//      * Pushes an item onto the top of this stack.
//      *
//      * @param item the item to push
//      * @return the {@code item} argument.
//      */
//     public boolean push(boolean item) {
//         bits.set(size++, item);
//         return item;
//     }
// 
//     /**
//      * Removes the object at the top of this stack and returns it.
//      *
//      * @return The object at the top of this stack
//      * @throws EmptyStackException if this stack is empty.
//      */
//     public synchronized boolean pop() {
//         boolean result = peek();
//         size--;
//         return result;
//     }
// 
//     /**
//      * Returns the object at the top of this stack without removing it from the stack.
//      *
//      * @return the object at the top of this stack
//      * @throws EmptyStackException if this stack is empty.
//      */
//     public synchronized boolean peek() {
//         if (size == 0)
//             throw new EmptyStackException();
//         return bits.get(size - 1);
//     }
// 
//     /**
//      * @return {@code true} if and only if this stack contains no items; {@code false} otherwise.
//      */
//     public boolean empty() {
//         return size == 0;
//     }
// 
// }
// 
// Path: srcdeps-core/src/main/java/org/srcdeps/core/util/Consumer.java
// public interface Consumer<T> {
//     void accept(T t);
// }


import java.util.TreeMap;
import org.srcdeps.core.util.BitStack;
import org.srcdeps.core.util.Consumer;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
/**
 * Copyright 2015-2018 Maven Source Dependencies
 * Plugin contributors as indicated by the @author tags.
 *
 * Licensed 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.srcdeps.core;



/**
 * A tree walker through the files in the local Maven repository which belong to a specific {@link GavSet}.
 *
 * @author <a href="https://github.com/ppalaga">Peter Palaga</a>
 * @since 3.2.2
 */
public class GavSetWalker {

    /**
     * A simple {@link Consumer} that just collects the GAV {@link Path}s into {@link #gavPaths} {@link Map}.
     */
    public static class GavPathCollector implements Consumer<GavtcPath> {

        private final Map<Path, Gav> gavPaths = new TreeMap<>();

        @Override
        public void accept(GavtcPath t) {
            gavPaths.put(t.getPath().getParent(), t);
        }

        /**
         * @return the GAV {@link Path}s collected
         */
        public Map<Path, Gav> getGavPaths() {
            return gavPaths;
        }

    }

    /**
     * A {@link FileVisitor} for walking the local Maven repository.
     */
    static class GavtcPathVisitor implements FileVisitor<Path> {
        static boolean hasIgnorableExtension(String name) {
            for (String ext : IGNORABLE_EXTENSIONS) {
                if (name.endsWith(ext)) {
                    return true;
                }
            }
            return false;
        }

        private final Consumer<GavtcPath> callback;
// Path: srcdeps-core/src/main/java/org/srcdeps/core/util/BitStack.java
// public class BitStack {
//     private final BitSet bits = new BitSet();
//     private int size = 0;
// 
//     /**
//      * Pushes an item onto the top of this stack.
//      *
//      * @param item the item to push
//      * @return the {@code item} argument.
//      */
//     public boolean push(boolean item) {
//         bits.set(size++, item);
//         return item;
//     }
// 
//     /**
//      * Removes the object at the top of this stack and returns it.
//      *
//      * @return The object at the top of this stack
//      * @throws EmptyStackException if this stack is empty.
//      */
//     public synchronized boolean pop() {
//         boolean result = peek();
//         size--;
//         return result;
//     }
// 
//     /**
//      * Returns the object at the top of this stack without removing it from the stack.
//      *
//      * @return the object at the top of this stack
//      * @throws EmptyStackException if this stack is empty.
//      */
//     public synchronized boolean peek() {
//         if (size == 0)
//             throw new EmptyStackException();
//         return bits.get(size - 1);
//     }
// 
//     /**
//      * @return {@code true} if and only if this stack contains no items; {@code false} otherwise.
//      */
//     public boolean empty() {
//         return size == 0;
//     }
// 
// }
// 
// Path: srcdeps-core/src/main/java/org/srcdeps/core/util/Consumer.java
// public interface Consumer<T> {
//     void accept(T t);
// }


// Path: srcdeps-core/src/main/java/org/srcdeps/core/GavSetWalker.java
import java.util.TreeMap;
import org.srcdeps.core.util.BitStack;
import org.srcdeps.core.util.Consumer;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

/**
 * Copyright 2015-2018 Maven Source Dependencies
 * Plugin contributors as indicated by the @author tags.
 *
 * Licensed 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.srcdeps.core;



/**
 * A tree walker through the files in the local Maven repository which belong to a specific {@link GavSet}.
 *
 * @author <a href="https://github.com/ppalaga">Peter Palaga</a>
 * @since 3.2.2
 */
public class GavSetWalker {

    /**
     * A simple {@link Consumer} that just collects the GAV {@link Path}s into {@link #gavPaths} {@link Map}.
     */
    public static class GavPathCollector implements Consumer<GavtcPath> {

        private final Map<Path, Gav> gavPaths = new TreeMap<>();

        @Override
        public void accept(GavtcPath t) {
            gavPaths.put(t.getPath().getParent(), t);
        }

        /**
         * @return the GAV {@link Path}s collected
         */
        public Map<Path, Gav> getGavPaths() {
            return gavPaths;
        }

    }

    /**
     * A {@link FileVisitor} for walking the local Maven repository.
     */
    static class GavtcPathVisitor implements FileVisitor<Path> {
        static boolean hasIgnorableExtension(String name) {
            for (String ext : IGNORABLE_EXTENSIONS) {
                if (name.endsWith(ext)) {
                    return true;
                }
            }
            return false;
        }

        private final Consumer<GavtcPath> callback;
        private final BitStack dirCanContainArtifacts = new BitStack();