<commit_before>package com.imagepicker.media;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.MimeTypeMap;

import com.facebook.react.bridge.ReadableMap;

import java.io.File;

/**
 * Created by rusfearuth on 15.03.17.
 */

public class ImageConfig
{
    public @Nullable final File original;
    public @Nullable final File resized;
    public final int maxWidth;
    public final int maxHeight;
    public final int quality;
    public final int rotation;
    public final boolean saveToCameraRoll;

    public ImageConfig(@Nullable final File original,
                       @Nullable final File resized,
                       final int maxWidth,
                       final int maxHeight,
                       final int quality,
                       final int rotation,
                       final boolean saveToCameraRoll)
    {
        this.original = original;
        this.resized = resized;
        this.maxWidth = maxWidth;
        this.maxHeight = maxHeight;
        this.quality = quality;
        this.rotation = rotation;
        this.saveToCameraRoll = saveToCameraRoll;
    }

    public @NonNull ImageConfig withMaxWidth(final int maxWidth)
    {
        return new ImageConfig(
                this.original, this.resized, maxWidth,
                this.maxHeight, this.quality, this.rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withMaxHeight(final int maxHeight)
    {
        return new ImageConfig(
                this.original, this.resized, this.maxWidth,
                maxHeight, this.quality, this.rotation,
                this.saveToCameraRoll
        );

    }

    public @NonNull ImageConfig withQuality(final int quality)
    {
        return new ImageConfig(
                this.original, this.resized, this.maxWidth,
                this.maxHeight, quality, this.rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withRotation(final int rotation)
    {
        return new ImageConfig(
                this.original, this.resized, this.maxWidth,
                this.maxHeight, this.quality, rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withOriginalFile(@Nullable final File original)
    {
        //if it is a GIF file, always set quality to 100 to prevent compression
        String extension = MimeTypeMap.getFileExtensionFromUrl(original.getAbsolutePath());
        int quality = this.quality;
        if(extension.contains("gif")){
            quality = 100;
        }

        return new ImageConfig(
                original, this.resized, this.maxWidth,
                this.maxHeight, quality, this.rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withResizedFile(@Nullable final File resized)
    {
        return new ImageConfig(
                this.original, resized, this.maxWidth,<commit_msg>#972: change ImageConfig.withOriginalFile() to address testOnImmutable failure (#973)<commit_after>package com.imagepicker.media;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.MimeTypeMap;

import com.facebook.react.bridge.ReadableMap;

import java.io.File;

/**
 * Created by rusfearuth on 15.03.17.
 */

public class ImageConfig
{
    public @Nullable final File original;
    public @Nullable final File resized;
    public final int maxWidth;
    public final int maxHeight;
    public final int quality;
    public final int rotation;
    public final boolean saveToCameraRoll;

    public ImageConfig(@Nullable final File original,
                       @Nullable final File resized,
                       final int maxWidth,
                       final int maxHeight,
                       final int quality,
                       final int rotation,
                       final boolean saveToCameraRoll)
    {
        this.original = original;
        this.resized = resized;
        this.maxWidth = maxWidth;
        this.maxHeight = maxHeight;
        this.quality = quality;
        this.rotation = rotation;
        this.saveToCameraRoll = saveToCameraRoll;
    }

    public @NonNull ImageConfig withMaxWidth(final int maxWidth)
    {
        return new ImageConfig(
                this.original, this.resized, maxWidth,
                this.maxHeight, this.quality, this.rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withMaxHeight(final int maxHeight)
    {
        return new ImageConfig(
                this.original, this.resized, this.maxWidth,
                maxHeight, this.quality, this.rotation,
                this.saveToCameraRoll
        );

    }

    public @NonNull ImageConfig withQuality(final int quality)
    {
        return new ImageConfig(
                this.original, this.resized, this.maxWidth,
                this.maxHeight, quality, this.rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withRotation(final int rotation)
    {
        return new ImageConfig(
                this.original, this.resized, this.maxWidth,
                this.maxHeight, this.quality, rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withOriginalFile(@Nullable final File original)
    {
        if (original != null) {
            //if it is a GIF file, always set quality to 100 to prevent compression
            String extension = MimeTypeMap.getFileExtensionFromUrl(original.getAbsolutePath());
            int quality = this.quality;
            if(extension.contains("gif")){
                quality = 100;
            }
        }

        return new ImageConfig(
                original, this.resized, this.maxWidth,
                this.maxHeight, quality, this.rotation,
                this.saveToCameraRoll
        );
    }

    public @NonNull ImageConfig withResizedFile(@Nullable final File resized)
    {
        return new ImageConfig(
                this.original, resized, this.maxWidth,
{'fraction_non_alphanumeric': 0.0713128038897893, 'fraction_numerical': 0.004862236628849271, 'mean_word_length': 1.9568758984187828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5042573', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1527, 'n_words': 419}