001/* 002 * Copyright 2022-2026 Revetware LLC. 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.soklet; 018 019import org.jspecify.annotations.NonNull; 020import org.jspecify.annotations.Nullable; 021 022import javax.annotation.concurrent.ThreadSafe; 023 024import static java.util.Objects.requireNonNull; 025 026/** 027 * An immutable JSON boolean. 028 * 029 * @author <a href="https://www.revetkn.com">Mark Allen</a> 030 */ 031@ThreadSafe 032public final class McpJsonBoolean implements McpJsonValue { 033 @NonNull 034 private static final McpJsonBoolean TRUE = new McpJsonBoolean(true); 035 @NonNull 036 private static final McpJsonBoolean FALSE = new McpJsonBoolean(false); 037 @NonNull 038 private final Boolean value; 039 040 /** 041 * Returns an immutable JSON boolean for the supplied value. 042 * 043 * @param value the non-null boolean value 044 * @return immutable JSON boolean 045 */ 046 @NonNull 047 public static McpJsonBoolean fromValue(@NonNull Boolean value) { 048 return requireNonNull(value) ? TRUE : FALSE; 049 } 050 051 private McpJsonBoolean(@NonNull Boolean value) { 052 this.value = requireNonNull(value); 053 } 054 055 /** @return boolean value */ 056 @NonNull 057 public Boolean getValue() { 058 return this.value; 059 } 060 061 /** @return whether this object contains the same boolean value */ 062 @Override 063 public boolean equals(@Nullable Object other) { 064 if (this == other) 065 return true; 066 if (!(other instanceof McpJsonBoolean bool)) 067 return false; 068 return this.value.equals(bool.value); 069 } 070 071 /** @return value-based hash code */ 072 @Override 073 public int hashCode() { 074 return this.value.hashCode(); 075 } 076 077 /** @return redacted diagnostic rendering */ 078 @Override 079 @NonNull 080 public String toString() { 081 return "McpJsonBoolean{value=<redacted>}"; 082 } 083}