001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.util.filter;
020
021import java.util.List;
022
023import org.eclipse.aether.graph.DependencyFilter;
024import org.eclipse.aether.graph.DependencyNode;
025
026import static java.util.Objects.requireNonNull;
027
028/**
029 * A dependency filter that negates another filter.
030 */
031public final class NotDependencyFilter implements DependencyFilter {
032
033    private final DependencyFilter filter;
034
035    /**
036     * Creates a new filter negatint the specified filter.
037     *
038     * @param filter The filter to negate, must not be {@code null}.
039     */
040    public NotDependencyFilter(DependencyFilter filter) {
041        this.filter = requireNonNull(filter, "dependency filter cannot be null");
042    }
043
044    public boolean accept(DependencyNode node, List<DependencyNode> parents) {
045        return !filter.accept(node, parents);
046    }
047
048    @Override
049    public boolean equals(Object obj) {
050        if (this == obj) {
051            return true;
052        }
053
054        if (obj == null || !getClass().equals(obj.getClass())) {
055            return false;
056        }
057
058        NotDependencyFilter that = (NotDependencyFilter) obj;
059
060        return this.filter.equals(that.filter);
061    }
062
063    @Override
064    public int hashCode() {
065        int hash = getClass().hashCode();
066        hash = hash * 31 + filter.hashCode();
067        return hash;
068    }
069}