001/*
002 * Copyright (C) 2011 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.collect;
016
017import com.google.common.annotations.GwtCompatible;
018
019/**
020 * Indicates whether an endpoint of some range is contained in the range itself ("closed") or not
021 * ("open"). If a range is unbounded on a side, it is neither open nor closed on that side; the
022 * bound simply does not exist.
023 *
024 * @since 10.0
025 */
026@GwtCompatible
027public enum BoundType {
028  /**
029   * The endpoint value <i>is not</i> considered part of the set ("exclusive").
030   */
031  OPEN(false),
032  CLOSED(true);
033
034  final boolean inclusive;
035
036  BoundType(boolean inclusive) {
037    this.inclusive = inclusive;
038  }
039
040  /**
041   * Returns the bound type corresponding to a boolean value for inclusivity.
042   */
043  static BoundType forBoolean(boolean inclusive) {
044    return inclusive ? CLOSED : OPEN;
045  }
046
047  BoundType flip() {
048    return forBoolean(!inclusive);
049  }
050}