001/*
002 * Copyright (C) 2008 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 static java.util.Collections.sort;
020
021import com.google.common.annotations.GwtCompatible;
022import java.util.List;
023import java.util.SortedSet;
024import org.jspecify.annotations.NullMarked;
025
026/**
027 * Create string sets for testing collections that are sorted by natural ordering.
028 *
029 * @author Jared Levy
030 */
031@GwtCompatible
032@NullMarked
033public abstract class TestStringSortedSetGenerator extends TestStringSetGenerator
034    implements TestSortedSetGenerator<String> {
035
036  @Override
037  public SortedSet<String> create(Object... elements) {
038    return (SortedSet<String>) super.create(elements);
039  }
040
041  @Override
042  protected abstract SortedSet<String> create(String[] elements);
043
044  /** Sorts the elements by their natural ordering. */
045  /*
046   * While the current implementation returns `this`, that's not something we mean to guarantee.
047   * Callers of TestContainerGenerator.order need to be prepared for implementations to return a new
048   * collection.
049   */
050  @SuppressWarnings("CanIgnoreReturnValueSuggester")
051  @Override
052  public List<String> order(List<String> insertionOrder) {
053    sort(insertionOrder);
054    return insertionOrder;
055  }
056
057  @Override
058  public String belowSamplesLesser() {
059    return "!! a";
060  }
061
062  @Override
063  public String belowSamplesGreater() {
064    return "!! b";
065  }
066
067  @Override
068  public String aboveSamplesLesser() {
069    return "~~ a";
070  }
071
072  @Override
073  public String aboveSamplesGreater() {
074    return "~~ b";
075  }
076}