// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.sps.webcrawler;

import com.google.sps.data.NewsArticle;

/** 
 * Provides a tool for processing textual content.
 */
public class ContentProcessor {

  // @TODO
  public static NewsArticle process(NewsArticle newsArticle) {
    return newsArticle;
  }
}

// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.sps.webcrawler;

import com.google.sps.data.NewsArticle;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/** 
 * Provides a tool for processing textual content.
 */
public class ContentProcessor {
  private final static int MAX_WORD_COUNT = 100;

  // @TODO [Implement more advanced processing methods.]
  /** 
   * Extracts the first {@code MAX_WORD_COUNT} words.
   */
  public static NewsArticle process(NewsArticle newsArticle) {
    List<String> rawContent = newsArticle.getContent();
    List<String> processedContent = new LinkedList<>();
    int remainingWordCount = MAX_WORD_COUNT;
    for (String contentBlock : rawContent) {
      String[] splitContentBlock = contentBlock.split(" ");
      int wordCount = splitContentBlock.length;
      int allowedLength = Math.min(wordCount, remainingWordCount);
      String processedContentBlock =
          String.join(" ", Arrays.asList(splitContentBlock).subList(0, allowedLength));
      processedContent.add(processedContentBlock);
      remainingWordCount -= wordCount;
      if (remainingWordCount <= 0) {
        break;
      }
    }
    newsArticle.setContent(processedContent);
    return newsArticle;
  }
}

Implement simplified ContentProcessor that extracts the first 100 words of the news article.