<commit_before>package com.atlassian.jira.plugins.dvcs.spi.bitbucket.transformers;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;

import com.atlassian.jira.plugins.dvcs.model.ChangesetFile;
import com.atlassian.jira.plugins.dvcs.model.ChangesetFileAction;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketChangesetFile;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketChangesetWithDiffstat;

/**
 * ChangesetFileTransformer
 *
 * @author <NAME> <EMAIL>
 */
public class ChangesetFileTransformer {
    private ChangesetFileTransformer() {}


    @SuppressWarnings("unchecked")
    public static List<ChangesetFile> fromBitbucketChangesetsWithDiffstat(List<BitbucketChangesetWithDiffstat> diffstats)
    {
        return (List<ChangesetFile>) CollectionUtils.collect(diffstats, new Transformer() {

            @Override
            public Object transform(Object input)
            {
                BitbucketChangesetWithDiffstat diffstat = (BitbucketChangesetWithDiffstat) input;

                ChangesetFileAction fileAction = ChangesetFileAction.valueOf(diffstat.getType().toUpperCase());

                return new ChangesetFile(fileAction,
                                         diffstat.getFile(),
                                         diffstat.getDiffstat().getAdded(),
                                         diffstat.getDiffstat().getRemoved());
            }
        });
    }

    @SuppressWarnings("unchecked")
    public static List<ChangesetFile> fromBitbucketChangesetFiles(List<BitbucketChangesetFile> changesetFiles)
    {
        return (List<ChangesetFile>) CollectionUtils.collect(changesetFiles, new Transformer() {

            @Override
            public Object transform(Object input)
            {
                BitbucketChangesetFile changesetFile = (BitbucketChangesetFile) input;

                ChangesetFileAction fileAction = ChangesetFileAction.valueOf(changesetFile.getType().toUpperCase());

                return new ChangesetFile(fileAction,
                                         changesetFile.getFile(),
                                         0,  // zero additions
                                         0); // zero deletions
            }
        });
    }
}<commit_msg>BBC-381 adding checks for NPE<commit_after>package com.atlassian.jira.plugins.dvcs.spi.bitbucket.transformers;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;

import com.atlassian.jira.plugins.dvcs.model.ChangesetFile;
import com.atlassian.jira.plugins.dvcs.model.ChangesetFileAction;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketChangesetFile;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketChangesetWithDiffstat;

/**
 * ChangesetFileTransformer
 *
 * @author <NAME> <EMAIL>
 */
public class ChangesetFileTransformer {
    private ChangesetFileTransformer() {}


    @SuppressWarnings("unchecked")
    public static List<ChangesetFile> fromBitbucketChangesetsWithDiffstat(List<BitbucketChangesetWithDiffstat> diffstats)
    {
        return (List<ChangesetFile>) CollectionUtils.collect(diffstats, new Transformer() {

            @Override
            public Object transform(Object input)
            {
                BitbucketChangesetWithDiffstat diffstat = (BitbucketChangesetWithDiffstat) input;

                ChangesetFileAction fileAction = ChangesetFileAction.valueOf(diffstat.getType().toUpperCase());
                
                int added = 0; 
                int removed = 0;
                if (diffstat.getDiffstat() != null)
                {
                    if (diffstat.getDiffstat().getAdded() != null)
                    {
                        added = diffstat.getDiffstat().getAdded();
                    }
                    if (diffstat.getDiffstat().getRemoved() != null)
                    {
                        removed = diffstat.getDiffstat().getRemoved();
                    }
                }
                return new ChangesetFile(fileAction, diffstat.getFile(), added, removed);
            }
        });
    }
    

    @SuppressWarnings("unchecked")
    public static List<ChangesetFile> fromBitbucketChangesetFiles(List<BitbucketChangesetFile> changesetFiles)
    {
        return (List<ChangesetFile>) CollectionUtils.collect(changesetFiles, new Transformer() {

            @Override
            public Object transform(Object input)
            {
                BitbucketChangesetFile changesetFile = (BitbucketChangesetFile) input;

                ChangesetFileAction fileAction = ChangesetFileAction.valueOf(changesetFile.getType().toUpperCase());

                return new ChangesetFile(fileAction,
                                         changesetFile.getFile(),
                                         0,  // zero additions
                                         0); // zero deletions
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.08724440116845181, 'fraction_numerical': 0.0017526777020447906, 'mean_word_length': 2.218045112781955, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837189', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1265, 'n_words': 197}