001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections4.set;
018
019import java.util.Set;
020
021import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
022
023/**
024 * Decorates another <code>Set</code> to provide additional behaviour.
025 * <p>
026 * Methods are forwarded directly to the decorated set.
027 *
028 * @param <E> the type of the elements in this set
029 * @since 3.0
030 */
031public abstract class AbstractSetDecorator<E> extends AbstractCollectionDecorator<E> implements
032        Set<E> {
033
034    /** Serialization version */
035    private static final long serialVersionUID = -4678668309576958546L;
036
037    /**
038     * Constructor only used in deserialization, do not use otherwise.
039     * @since 3.1
040     */
041    protected AbstractSetDecorator() {
042        super();
043    }
044
045    /**
046     * Constructor that wraps (not copies).
047     *
048     * @param set  the set to decorate, must not be null
049     * @throws NullPointerException if set is null
050     */
051    protected AbstractSetDecorator(final Set<E> set) {
052        super(set);
053    }
054
055    /**
056     * Gets the set being decorated.
057     *
058     * @return the decorated set
059     */
060    @Override
061    protected Set<E> decorated() {
062        return (Set<E>) super.decorated();
063    }
064
065    @Override
066    public boolean equals(final Object object) {
067        return object == this || decorated().equals(object);
068    }
069
070    @Override
071    public int hashCode() {
072        return decorated().hashCode();
073    }
074
075}