001/*
002 * Copyright (C) 2007 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect.testing;
018
019import com.google.common.annotations.GwtCompatible;
020import com.google.common.collect.testing.SampleElements.Ints;
021import java.util.List;
022import java.util.Set;
023
024/**
025 * Create integer sets for collection tests.
026 *
027 * @author Gregory Kick
028 */
029@GwtCompatible
030public abstract class TestIntegerSetGenerator implements TestSetGenerator<Integer> {
031  @Override
032  public SampleElements<Integer> samples() {
033    return new Ints();
034  }
035
036  @Override
037  public Set<Integer> create(Object... elements) {
038    Integer[] array = new Integer[elements.length];
039    int i = 0;
040    for (Object e : elements) {
041      array[i++] = (Integer) e;
042    }
043    return create(array);
044  }
045
046  protected abstract Set<Integer> create(Integer[] elements);
047
048  @Override
049  public Integer[] createArray(int length) {
050    return new Integer[length];
051  }
052
053  /**
054   * {@inheritDoc}
055   *
056   * <p>By default, returns the supplied elements in their given order; however, generators for
057   * containers with a known order other than insertion order must override this method.
058   *
059   * <p>Note: This default implementation is overkill (but valid) for an unordered container. An
060   * equally valid implementation for an unordered container is to throw an exception. The chosen
061   * implementation, however, has the advantage of working for insertion-ordered containers, as
062   * well.
063   */
064  @Override
065  public List<Integer> order(List<Integer> insertionOrder) {
066    return insertionOrder;
067  }
068}