1/*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23package org.graalvm.compiler.core.common.util;
24
25import java.util.ArrayList;
26import java.util.Collection;
27import java.util.HashSet;
28import java.util.Set;
29
30/**
31 * Mimic a set implementation with an ArrayList. Beneficial for small sets (compared to
32 * {@link HashSet}).
33 */
34public class ArraySet<E> extends ArrayList<E> implements Set<E> {
35    private static final long serialVersionUID = 4476957522387436654L;
36
37    public ArraySet() {
38        super();
39    }
40
41    public ArraySet(int i) {
42        super(i);
43    }
44
45    public ArraySet(Collection<? extends E> c) {
46        super(c);
47    }
48
49    @Override
50    public boolean add(E e) {
51        // avoid duplicated entries
52        if (contains(e)) {
53            return false;
54        }
55        return super.add(e);
56    }
57}
58