<commit_before>package com.contentful.java.cda;

import com.contentful.java.cda.image.ImageOption;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Represents a single asset.
 */
public class CDAAsset extends LocalizedResource {

  /**
   * @return title of this asset.
   */
  public String title() {
    return getField("title");
  }

  /**
   * @return url to the file of this asset.
   */
  public String url() {
    return fileField("url");
  }

  /**
   * Returns a url with the given image manipulation.
   * <p>
   * If the asset is not pointing to an image (as identified by its mimetype) the {@link #url()} is
   * returned. Same happens if the options are empty or non existing, then the url gets returned.
   * <p>
   * In an error case (for instance, using the same option twice), the last option with the same
   * operation will be used.
   *
   * @param options to manipulate the image the returned url will be pointing to.
   * @return an url reflecting all the options given.
   * @see ImageOption
   * @see #url()
   */
  public String urlForImageWith(ImageOption... options) {
    if (options == null || options.length == 0) {
      throw new IllegalArgumentException("Do not use empty options argument. " +
          "If you want to manipulate the url by hand, please use `CDAAsset.url()` instead.");
    }

    if (!mimeType().startsWith("image")) {
      throw new IllegalStateException("Asset has not image mime type. Please make sure it is " +
          "of jpg, png, or webp format.");
    }

    final Map<String, ImageOption> mappedOptions
        = new LinkedHashMap<String, ImageOption>(options.length);

    for (final ImageOption option : options) {
      mappedOptions.put(option.getOperation(), option);
    }<commit_msg>fix: Add defensive assumptions: Do not thow NPE if no mimetype is set<commit_after>package com.contentful.java.cda;

import com.contentful.java.cda.image.ImageOption;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Represents a single asset.
 */
public class CDAAsset extends LocalizedResource {

  /**
   * @return title of this asset.
   */
  public String title() {
    return getField("title");
  }

  /**
   * @return url to the file of this asset.
   */
  public String url() {
    return fileField("url");
  }

  /**
   * Returns a url with the given image manipulation.
   * <p>
   * If the asset is not pointing to an image (as identified by its mimetype) the {@link #url()} is
   * returned. Same happens if the options are empty or non existing, then the url gets returned.
   * <p>
   * In an error case (for instance, using the same option twice), the last option with the same
   * operation will be used.
   *
   * @param options to manipulate the image the returned url will be pointing to.
   * @return an url reflecting all the options given.
   * @throws IllegalArgumentException if no options are given.
   * @throws IllegalArgumentException if no mimetype was set on asset.
   * @throws IllegalArgumentException if mimetype was not an image.
   * @see ImageOption
   * @see #url()
   */
  public String urlForImageWith(ImageOption... options) {
    if (options == null || options.length == 0) {
      throw new IllegalArgumentException("Do not use empty options argument. " +
          "If you want to manipulate the url by hand, please use `CDAAsset.url()` instead.");
    }

    final String mimeType = mimeType();
    if (mimeType == null || !mimeType.startsWith("image")) {
      throw new IllegalStateException("Asset has not image mime type. Please make sure it is " +
          "of jpg, png, or webp format.");
    }

    final Map<String, ImageOption> mappedOptions
        = new LinkedHashMap<String, ImageOption>(options.length);

    for (final ImageOption option : options) {
      mappedOptions.put(option.getOperation(), option);
    }
{'fraction_non_alphanumeric': 0.10249091852620654, 'fraction_numerical': 0.0005189413596263622, 'mean_word_length': 3.0793650793650795, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930183', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1076, 'n_words': 432}