<commit_before>/*
 * Copyright (C) 2011 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.common.collect;

import com.google.common.annotations.Beta;

import java.util.NoSuchElementException;
import java.util.Set;

import javax.annotation.Nullable;

/**
 * A set comprising zero or more {@linkplain Range#isEmpty nonempty},
 * {@linkplain Range#isConnected(Range) disconnected} ranges of type {@code C}.
 *
 * <p>Implementations that choose to support the {@link #add(Range)} operation are required to
 * ignore empty ranges and coalesce connected ranges.  For example:  <pre>   {@code
 *
 *   RangeSet<Integer> rangeSet = TreeRangeSet.create();
 *   rangeSet.add(Range.closed(1, 10)); // {[1, 10]}
 *   rangeSet.add(Range.closedOpen(11, 15)); // disconnected range; {[1, 10], [11, 15)}
 *   rangeSet.add(Range.closedOpen(15, 20)); // connected range; {[1, 10], [11, 20)}
 *   rangeSet.add(Range.openClosed(0, 0)); // empty range; {[1, 10], [11, 20)}
 *   rangeSet.remove(Range.open(5, 10)); // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}}</pre>
 *
 * <p>Note that the behavior of {@link Range#isEmpty()} and {@link Range#isConnected(Range)} may
 * not be as expected on discrete ranges.  See the Javadoc of those methods for details.
 *
 * <p>For a {@link Set} whose contents are specified by a {@link Range}, see {@link ContiguousSet}.
 *
 * <p>See the Guava User Guide article on <a href=
 * "https://github.com/google/guava/wiki/NewCollectionTypesExplained#rangeset">
 * RangeSets</a>.
 *
 * @author <NAME>
 * @author <NAME>
 * @since 14.0
 */
@Beta
public interface RangeSet<C extends Comparable> {

  // Query methods

  /**
   * Determines whether any of this range set's member ranges contains {@code value}.
   */
  boolean contains(C value);

  /**
   * Returns the unique range from this range set that {@linkplain Range#contains contains}
   * {@code value}, or {@code null} if this range set does not contain {@code value}.
   */
  Range<C> rangeContaining(C value);

  /**
   * Returns {@code true} if there exists a non-empty range enclosed by both a member range in this
   * range set and the specified range. This is equivalent to calling
   * {@code subRangeSet(otherRange)} and testing whether the resulting range set is non-empty.
   */
  boolean intersects(Range<C> otherRange);

  /**
   * Returns {@code true} if there exists a member range in this range set which
   * {@linkplain Range#encloses encloses} the specified range.
   */
  boolean encloses(Range<C> otherRange);

  /**
   * Returns {@code true} if for each member range in {@code other} there exists a member range in
   * this range set which {@linkplain Range#encloses encloses} it. It follows that
   * {@code this.contains(value)} whenever {@code other.contains(value)}. Returns {@code true} if
   * {@code other} is empty.
   *
   * <p>This is equivalent to checking if this range set {@link #encloses} each of the ranges in
   * {@code other}.
   */
  boolean enclosesAll(RangeSet<C> other);

  /**
   * Returns {@code true} if this range set contains no ranges.
   */
  boolean isEmpty();

  /**
   * Returns the minimal range which {@linkplain Range#encloses(Range) encloses} all ranges
   * in this range set.
   *<commit_msg>Add @since for RangeSet.intersects. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=111072613<commit_after>/*
 * Copyright (C) 2011 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.common.collect;

import com.google.common.annotations.Beta;

import java.util.NoSuchElementException;
import java.util.Set;

import javax.annotation.Nullable;

/**
 * A set comprising zero or more {@linkplain Range#isEmpty nonempty},
 * {@linkplain Range#isConnected(Range) disconnected} ranges of type {@code C}.
 *
 * <p>Implementations that choose to support the {@link #add(Range)} operation are required to
 * ignore empty ranges and coalesce connected ranges.  For example:  <pre>   {@code
 *
 *   RangeSet<Integer> rangeSet = TreeRangeSet.create();
 *   rangeSet.add(Range.closed(1, 10)); // {[1, 10]}
 *   rangeSet.add(Range.closedOpen(11, 15)); // disconnected range; {[1, 10], [11, 15)}
 *   rangeSet.add(Range.closedOpen(15, 20)); // connected range; {[1, 10], [11, 20)}
 *   rangeSet.add(Range.openClosed(0, 0)); // empty range; {[1, 10], [11, 20)}
 *   rangeSet.remove(Range.open(5, 10)); // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}}</pre>
 *
 * <p>Note that the behavior of {@link Range#isEmpty()} and {@link Range#isConnected(Range)} may
 * not be as expected on discrete ranges.  See the Javadoc of those methods for details.
 *
 * <p>For a {@link Set} whose contents are specified by a {@link Range}, see {@link ContiguousSet}.
 *
 * <p>See the Guava User Guide article on <a href=
 * "https://github.com/google/guava/wiki/NewCollectionTypesExplained#rangeset">
 * RangeSets</a>.
 *
 * @author <NAME>
 * @author <NAME>
 * @since 14.0
 */
@Beta
public interface RangeSet<C extends Comparable> {

  // Query methods

  /**
   * Determines whether any of this range set's member ranges contains {@code value}.
   */
  boolean contains(C value);

  /**
   * Returns the unique range from this range set that {@linkplain Range#contains contains}
   * {@code value}, or {@code null} if this range set does not contain {@code value}.
   */
  Range<C> rangeContaining(C value);

  /**
   * Returns {@code true} if there exists a non-empty range enclosed by both a member range in this
   * range set and the specified range. This is equivalent to calling
   * {@code subRangeSet(otherRange)} and testing whether the resulting range set is non-empty.
   *
   * @since 20.0
   */
  boolean intersects(Range<C> otherRange);

  /**
   * Returns {@code true} if there exists a member range in this range set which
   * {@linkplain Range#encloses encloses} the specified range.
   */
  boolean encloses(Range<C> otherRange);

  /**
   * Returns {@code true} if for each member range in {@code other} there exists a member range in
   * this range set which {@linkplain Range#encloses encloses} it. It follows that
   * {@code this.contains(value)} whenever {@code other.contains(value)}. Returns {@code true} if
   * {@code other} is empty.
   *
   * <p>This is equivalent to checking if this range set {@link #encloses} each of the ranges in
   * {@code other}.
   */
  boolean enclosesAll(RangeSet<C> other);

  /**
   * Returns {@code true} if this range set contains no ranges.
   */
  boolean isEmpty();

  /**
   * Returns the minimal range which {@linkplain Range#encloses(Range) encloses} all ranges
   * in this range set.
   *
{'fraction_non_alphanumeric': 0.12560386473429952, 'fraction_numerical': 0.018279148713931322, 'mean_word_length': 3.754810676598386, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5318733', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2242, 'n_words': 890}