content: /*
   * Copyright 2024-2024 the original author or authors.
   */
  
  package com.alibaba.langengine.modelcontextprotocol.util;
  
  import java.util.Collection;
  import java.util.Map;
  
  /**
   * Miscellaneous utility methods.
   *
   * JDK 1.8 compatible version.
   *
   * @author Christian Tzolov
   */
  public final class Utils {
  
      private Utils() {
          // Utility class should not be instantiated
      }
  
      /**
       * Check whether the given {@code String} contains actual <em>text</em>.
       * <p>
       * More specifically, this method returns {@code true} if the {@code String} is not
       * {@code null}, its length is greater than 0, and it contains at least one
       * non-whitespace character.
       * @param str the {@code String} to check (may be {@code null})
       * @return {@code true} if the {@code String} is not {@code null}, its length is
       * greater than 0, and it does not contain whitespace only
       * @see Character#isWhitespace
       */
      public static boolean hasText(String str) {
          if (str == null || str.isEmpty()) {
              return false;
          }
          for (int i = 0; i < str.length(); i++) {
              if (!Character.isWhitespace(str.charAt(i))) {
                  return true;
              }
          }
          return false;
      }
  
      /**
       * Return {@code true} if the supplied Collection is {@code null} or empty. Otherwise,
       * return {@code false}.
       * @param collection the Collection to check
       * @return whether the given Collection is empty
       */
      public static boolean isEmpty(Collection<?> collection) {
          return (collection == null || collection.isEmpty());
      }
  
      /**
       * Return {@code true} if the supplied Map is {@code null} or empty. Otherwise, return
       * {@code false}.
       * @param map the Map to check
       * @return whether the given Map is empty
       */
      public static boolean isEmpty(Map<?, ?> map) {
          return (map == null || map.isEmpty());
      }
  }
  