001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * docs/licenses/cddl.txt. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2010-2014 UnboundID Corp. 026 */ 027 package com.unboundid.directory.sdk.common.types; 028 029 030 031 /** 032 * This enum defines a set of values which may be used to represent the result 033 * of a Boolean evaluation in which the result may be undefined. 034 */ 035 public enum ConditionResult 036 { 037 /** 038 * A condition result value which represents a Boolean result of "true". 039 */ 040 TRUE("true"), 041 042 043 044 /** 045 * A condition result value which represents a Boolean result of "false". 046 */ 047 FALSE("false"), 048 049 050 051 /** 052 * A condition result value which represents an undefined result. 053 */ 054 UNDEFINED("undefined"); 055 056 057 058 // The string representation of this condition result. 059 private final String name; 060 061 062 063 /** 064 * Creates a new condition result value with the provided name. 065 * 066 * @param name The name for this condition result value. 067 */ 068 private ConditionResult(final String name) 069 { 070 this.name = name; 071 } 072 073 074 075 /** 076 * Retrieves the condition result value which is the inverse of this value. 077 * The inverse of {@code TRUE} is {@code FALSE}, and vice-versa. The inverse 078 * of {@code UNDEFINED} is {@code UNDEFINED}. 079 * 080 * @return The condition result value which is the inverse of this value. 081 */ 082 public ConditionResult invert() 083 { 084 switch (this) 085 { 086 case TRUE: 087 return FALSE; 088 case FALSE: 089 return TRUE; 090 case UNDEFINED: 091 default: 092 return UNDEFINED; 093 } 094 } 095 096 097 098 /** 099 * Retrieves the condition result value which is the inverse of the provided 100 * result. The inverse of {@code TRUE} is {@code FALSE}, and vice-versa. The 101 * inverse of {@code UNDEFINED} is {@code UNDEFINED}. 102 * 103 * @param r The condition result value for which to retrieve the inverse 104 * value. It must not be {@code null}. 105 * 106 * @return The condition result value which is the inverse of the provided 107 * result. 108 */ 109 public static ConditionResult invert(final ConditionResult r) 110 { 111 return r.invert(); 112 } 113 114 115 116 /** 117 * Retrieves a string representation of this condition result value. 118 * 119 * @return A string representation of this condition result value. 120 */ 121 @Override() 122 public String toString() 123 { 124 return name; 125 } 126 }