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  /** The endpoint value <i>is not</i> considered part of the set ("exclusive"). */
029  OPEN(false),
030  CLOSED(true);
031
032  final boolean inclusive;
033
034  BoundType(boolean inclusive) {
035    this.inclusive = inclusive;
036  }
037
038  /** Returns the bound type corresponding to a boolean value for inclusivity. */
039  static BoundType forBoolean(boolean inclusive) {
040    return inclusive ? CLOSED : OPEN;
041  }
042
043  BoundType flip() {
044    return forBoolean(!inclusive);
045  }
046}