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 *   https://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.apache.bcel.verifier.statics;
020
021import java.util.HashSet;
022import java.util.Set;
023
024/**
025 * A small utility class representing a set of basic int values.
026 */
027public class IntList {
028
029    /** The ints are stored as Integer objects in a hash set so that {@link #contains(int)} is O(1), not a linear scan. */
030    private final Set<Integer> set;
031
032    /** This constructor creates an empty list. */
033    IntList() {
034        set = new HashSet<>();
035    }
036
037    /** Adds an element to the list. */
038    void add(final int i) {
039        set.add(Integer.valueOf(i));
040    }
041
042    /** Tests if the specified int is already in the list. */
043    boolean contains(final int i) {
044        return set.contains(Integer.valueOf(i));
045    }
046}