code: public static Token[] optimize(Token[] tokens) {
          if (tokens == null) {
              return null;
          }
  
          String firstVal = null;
          String lastVal = null;
  
          if (tokens.length == 1) {
              if (tokens[0].getType() == TokenType.TEXT) {
                  firstVal = tokens[0].getDefaultValue();
              }
          } else if (tokens.length > 1) {
              if (tokens[0].getType() == TokenType.TEXT) {
                  firstVal = tokens[0].getDefaultValue();
              }
              if (tokens[tokens.length - 1].getType() == TokenType.TEXT) {
                  lastVal = tokens[tokens.length - 1].getDefaultValue();
              }
          }
  
          if (firstVal != null) {
              String text = trimLeadingWhitespace(firstVal);
              if (!Objects.equals(firstVal, text)) {
                  tokens[0] = new Token(text);
              }
          }
  
          if (lastVal != null && !lastVal.isEmpty()) {
              String text = trimTrailingWhitespace(lastVal);
              if (!Objects.equals(lastVal, text)) {
                  tokens[tokens.length - 1] = new Token(text);
              }
          }
  
          return tokens;
      }
docs: Returns an array of tokens that is optimized.
  Eliminates unnecessary white spaces for the first and last tokens.
  
  @param tokens the tokens before optimizing
  @return the optimized tokens