<commit_before>package net.maizegenetics.pal.report;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import net.maizegenetics.util.DoubleFormat;

/**
 * Created by IntelliJ IDEA.
 * User: Ed
 * Date: Dec 7, 2004
 * Time: 2:10:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class TableReportUtils {
    
    public static String toDelimitedString(TableReport theTableSource, String delimit, String headerName, String headerValue) {
        Object[] colNames = theTableSource.getTableColumnNames();
        StringBuilder sb = new StringBuilder();
        
        int cols;
        cols = colNames.length;
        int rows = theTableSource.getRowCount();
        if (headerName != null) {
            sb.append(headerName + delimit);
        }
        for (int j = 0; j < cols; j++) {
            sb.append(colNames[j]);
            if (j < (cols - 1)) {
                sb.append(delimit);
            }
        }
        sb.append("\n");
        if (headerValue != null) {
            sb.append(headerValue + delimit);
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                sb.append(theTableSource.getValueAt(i, j));
                if (j < (cols - 1)) {
                    sb.append(delimit);
                }
            }
            sb.append("\n");
        }
        return sb.toString();
    }
    
    public static String toDelimitedString(TableReport theTableSource, String delimit) {
        return toDelimitedString(theTableSource, delimit, null, null);
    }
    
    public static void saveDelimitedTableReport(TableReport theTableSource, String delimit, File saveFile) {
        
        if (saveFile == null) {
            return;
        }
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            
            fw = new FileWriter(saveFile);
            bw = new BufferedWriter(fw);
            
            Object[] colNames = theTableSource.getTableColumnNames();
            for (int j = 0; j < colNames.length; j++) {
                if (j != 0) {
                    bw.write(delimit);
                }
                bw.write(colNames[j].toString());
            }
            bw.write("\n");
            
            for (int r = 0, n = theTableSource.getRowCount(); r < n; r++) {
                Object[] theRow = theTableSource.getRow(r);
                for (int i = 0; i < theRow.length; i++) {
                    if (i != 0) {
                        bw.write(delimit);
                    }
                    if (theRow[i] instanceof Double) {
                        bw.write(DoubleFormat.format((Double) theRow[i]));
                    } else {
                        bw.write(theRow[i].toString());
                    }
                }
                bw.write("\n");
            }
            
        } catch (Exception e) {
            System.out.println("TableReportUtils: writeReport: problem writing file: " + e.getMessage());
        } finally {
            try {
                bw.close();
                fw.close();
            } catch (Exception e) {
                // do nothing
            }
        }
        
    }
}<commit_msg>Added check if data is null.<commit_after>package net.maizegenetics.pal.report;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import net.maizegenetics.util.DoubleFormat;

/**
 * Created by IntelliJ IDEA.
 * User: Ed
 * Date: Dec 7, 2004
 * Time: 2:10:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class TableReportUtils {

    public static String toDelimitedString(TableReport theTableSource, String delimit, String headerName, String headerValue) {
        Object[] colNames = theTableSource.getTableColumnNames();
        StringBuilder sb = new StringBuilder();

        int cols;
        cols = colNames.length;
        int rows = theTableSource.getRowCount();
        if (headerName != null) {
            sb.append(headerName + delimit);
        }
        for (int j = 0; j < cols; j++) {
            sb.append(colNames[j]);
            if (j < (cols - 1)) {
                sb.append(delimit);
            }
        }
        sb.append("\n");
        if (headerValue != null) {
            sb.append(headerValue + delimit);
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                sb.append(theTableSource.getValueAt(i, j));
                if (j < (cols - 1)) {
                    sb.append(delimit);
                }
            }
            sb.append("\n");
        }
        return sb.toString();
    }

    public static String toDelimitedString(TableReport theTableSource, String delimit) {
        return toDelimitedString(theTableSource, delimit, null, null);
    }

    public static void saveDelimitedTableReport(TableReport theTableSource, String delimit, File saveFile) {

        if (saveFile == null) {
            return;
        }
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {

            fw = new FileWriter(saveFile);
            bw = new BufferedWriter(fw);

            Object[] colNames = theTableSource.getTableColumnNames();
            for (int j = 0; j < colNames.length; j++) {
                if (j != 0) {
                    bw.write(delimit);
                }
                bw.write(colNames[j].toString());
            }
            bw.write("\n");

            for (int r = 0, n = theTableSource.getRowCount(); r < n; r++) {
                Object[] theRow = theTableSource.getRow(r);
                for (int i = 0; i < theRow.length; i++) {
                    if (i != 0) {
                        bw.write(delimit);
                    }
                    if (theRow[i] == null) {
                        // do nothing
                    } else if (theRow[i] instanceof Double) {
                        bw.write(DoubleFormat.format((Double) theRow[i]));
                    } else {
                        bw.write(theRow[i].toString());
                    }
                }
                bw.write("\n");
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("TableReportUtils: writeReport: problem writing file: " + e.getMessage());
        } finally {
            try {
                bw.close();
                fw.close();
            } catch (Exception e) {
                // do nothing
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.11621869273060477, 'fraction_numerical': 0.006108735491753207, 'mean_word_length': 1.3980227023068472, 'pattern_counts': {'":': 0, '<': 19, '<?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': '369123', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1770, 'n_words': 436}