<commit_before>package org.jaexcel.framework.JAEX.engine;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

public class CellStyleUtils {

	/**
	 * Initialize font.
	 * 
	 * @param wb
	 *            the workbook
	 * @return the {@link Font}.
	 */
	private static Font initializeFont(Workbook wb) {
		return wb.createFont();
	}

	/**
	 * Initialize the data format.
	 * 
	 * @param wb
	 *            the workbook
	 * @return the {@link DataFormat}.
	 */
	private static DataFormat initializeDataFormat(Workbook wb) {
		return wb.createDataFormat();
	}

	/**
	 * Apply the data format to the cell style.
	 * 
	 * @param wb
	 *            the workbook
	 * @param c
	 *            the cell
	 * @param cs
	 *            the cell style
	 * @param formatMask
	 */
	protected static void applyDataFormat(Workbook wb, Cell c, CellStyle cs,
			String formatMask) {
		DataFormat df = initializeDataFormat(wb);
		cs.setDataFormat(df.getFormat(formatMask));
		c.setCellStyle(cs);
	}

	/**
	 * Apply the font to the cell style.
	 * 
	 * @param wb
	 *            the workbook
	 * @param cs
	 *            the cell style
	 * @param b
	 *            is bold format
	 * @param i
	 *            is italic format
	 */
	protected static void applyFont(Workbook wb, CellStyle cs, String name, short size, boolean b, boolean i) {
		Font f = initializeFont(wb);
		f.setFontName(name);
		f.setFontHeightInPoints(size);
		f.setBold(b);
		f.setItalic(i);
		cs.setFont(f);
	}

	/**
	 * Apply the alignment to the cell style.
	 * 
	 * @param cs
	 *            the cell style
	 * @param a
	 *            the horizontal alignment
	 * @param vA
	 *            the vertical alignment
	 */
	protected static void applyAlignment(CellStyle cs, short a, short vA) {
		if(a != 0){
			cs.setAlignment(a);
		}
		if(vA != 0){
			cs.setVerticalAlignment(vA);
		}
	}

	/**
	 * Apply the border to the cell style.
	 * 
	 * @param cs
	 *            the cell style
	 * @param bL
	 *            the cell border left
	 * @param bR
	 *            the cell border right
	 * @param bT
	 *            the cell border top
	 * @param bB
	 *            the cell border bottom
	 */
	protected static void applyBorder(CellStyle cs, short bL, short bR, short bT,
			short bB) {
		cs.setBorderLeft(bL);
		cs.setBorderRight(bR);
		cs.setBorderTop(bT);
		cs.setBorderBottom(bB);
	}

	/**
	 * Apply the background color to the cell style.
	 * 
	 * @param c
	 *            the cell
	 * @param cs
	 *            the cell style
	 * @param bC
	 *            the background color
	 */
	protected static void applyBackgroundColor(Cell c, CellStyle cs, short bC) {
		cs.setFillBackgroundColor(bC);
	}

	// HSSFWorkbook a;
	// XSSFCellStyle x;
	// XSSFWorkbook xw;
	// XSSFFont fx = xw.createFont();
	// fx.set
	// HSSFCellStyle hcs = a.createCellStyle();
	// Font f = wb.createFont();
	// f.setBold(true);
	// f.setItalic(true);
	// f.setFontHeight();
	// f.setFontName()
	// f.setUnderline(FontUnderline.DOUBLE);
	// cs.setFont(f);
	// c.setCellStyle(cs);
	// cs.set
}
<commit_msg>Add constants cell decorator Add constants mask decorator Add mathods : 	- initializeCellStyle 	- applyCellStyle 	- cloneCellStyle<commit_after>package org.jaexcel.framework.JAEX.engine;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

public class CellStyleUtils {
	// cell decorator constants
	public static final String CELL_DECORATOR_DATE = "date";
	public static final String CELL_DECORATOR_BOOLEAN = "boolean";
	public static final String CELL_DECORATOR_NUMERIC = "numeric";
	public static final String CELL_DECORATOR_HEADER = "header";
	// default mask decorators
	public static final String MASK_DECORATOR_DATE = "yyyy-MM-dd";
	public static final String MASK_DECORATOR_INTEGER = "0";
	public static final String MASK_DECORATOR_DOUBLE = "0.00";

	/**
	 * Initialize font.
	 * 
	 * @param wb
	 *            the workbook
	 * @return the {@link Font}.
	 */
	private static Font initializeFont(Workbook wb) {
		return wb.createFont();
	}

	/**
	 * Initialize the data format.
	 * 
	 * @param wb
	 *            the workbook
	 * @return the {@link DataFormat}.
	 */
	private static DataFormat initializeDataFormat(Workbook wb) {
		return wb.createDataFormat();
	}

	/**
	 * Apply the data format to the cell style.
	 * 
	 * @param wb
	 *            the workbook
	 * @param c
	 *            the cell
	 * @param cs
	 *            the cell style
	 * @param formatMask
	 */
	protected static void applyDataFormat(Workbook wb, Cell c, CellStyle cs, String formatMask) {
		DataFormat df = initializeDataFormat(wb);
		cs.setDataFormat(df.getFormat(formatMask));
		c.setCellStyle(cs);
	}

	/**
	 * Apply the font to the cell style.
	 * 
	 * @param wb
	 *            the workbook
	 * @param cs
	 *            the cell style
	 * @param b
	 *            is bold format
	 * @param i
	 *            is italic format
	 */
	protected static void applyFont(Workbook wb, CellStyle cs, String name, short size, boolean b, boolean i) {
		Font f = initializeFont(wb);
		f.setFontName(name);
		f.setFontHeightInPoints(size);
		f.setBold(b);
		f.setItalic(i);
		cs.setFont(f);
	}

	/**
	 * Apply the alignment to the cell style.
	 * 
	 * @param cs
	 *            the cell style
	 * @param a
	 *            the horizontal alignment
	 * @param vA
	 *            the vertical alignment
	 */
	protected static void applyAlignment(CellStyle cs, short a, short vA) {
		if (a != 0) {
			cs.setAlignment(a);
		}
		if (vA != 0) {
			cs.setVerticalAlignment(vA);
		}
	}

	/**
	 * Apply the border to the cell style.
	 * 
	 * @param cs
	 *            the cell style
	 * @param bL
	 *            the cell border left
	 * @param bR
	 *            the cell border right
	 * @param bT
	 *            the cell border top
	 * @param bB
	 *            the cell border bottom
	 */
	protected static void applyBorder(CellStyle cs, short bL, short bR, short bT, short bB) {
		cs.setBorderLeft(bL);
		cs.setBorderRight(bR);
		cs.setBorderTop(bT);
		cs.setBorderBottom(bB);
	}

	/**
	 * Apply the background color to the cell style.
	 * 
	 * @param c
	 *            the cell
	 * @param cs
	 *            the cell style
	 * @param bC
	 *            the background color
	 */
	protected static void applyBackgroundColor(Cell c, CellStyle cs, short bC) {
		cs.setFillBackgroundColor(bC);
	}

	/**
	 * Initialize cell style.
	 * 
	 * @param wb
	 *            the workbook
	 * @return the {@link CellStyle}.
	 */
	protected static CellStyle initializeCellStyle(Workbook wb) {
		return wb.createCellStyle();
	}

	protected static void applyCellStyle(Workbook wb, Cell c, CellStyle cs) {
		if (cs == null) {
			cs = initializeCellStyle(wb);
		}
		c.setCellStyle(cs);
	}

	/**
	 * Apply cell style according the one cell style base and format mask.
	 * 
	 * @param wb
	 *            the workbook
	 * @param c
	 *            the cell
	 * @param csBase
	 *            the cell style base
	 * @param formatMask
	 *            the format mask
	 */
	protected static void applyCellStyle(Workbook wb, Cell c, CellStyle csBase, String formatMask) {
		if (StringUtils.isNotBlank(formatMask) && csBase != null) {
			// CASE : if the cell has a formatMask and cell style base
			// clone a cell style
			CellStyle cs = cloneCellStyle(wb, csBase);

			// apply data format
			DataFormat df = initializeDataFormat(wb);
			cs.setDataFormat(df.getFormat(formatMask));

			// apply cell style to a cell
			c.setCellStyle(cs);
		} else {
			if (csBase == null) {
				// CASE : if the cell has no cell style base
				csBase = initializeCellStyle(wb);
			}
			if (StringUtils.isNotBlank(formatMask)) {
				// CASE : if the cell has a formatMask
				DataFormat df = initializeDataFormat(wb);
				csBase.setDataFormat(df.getFormat(formatMask));
			}
			c.setCellStyle(csBase);
		}
	}

	/**
	 * Clone a cell style passed as parameter.
	 * 
	 * @param wb
	 *            the workbook
	 * @param csBase
	 *            the cell style base
	 * @return the new cell style
	 */
	private static CellStyle cloneCellStyle(Workbook wb, CellStyle csBase) {
		CellStyle cs = initializeCellStyle(wb);
		cs.setAlignment(csBase.getAlignment());
		cs.setVerticalAlignment(csBase.getVerticalAlignment());
		cs.setBorderTop(csBase.getBorderTop());
		cs.setBorderBottom(csBase.getBorderBottom());
		cs.setBorderLeft(csBase.getBorderLeft());
		cs.setBorderRight(csBase.getBorderRight());
		cs.setFillForegroundColor(csBase.getFillForegroundColor());
		cs.setFillPattern(csBase.getFillPattern());
		cs.setWrapText(csBase.getWrapText());

		cs.setFont(wb.getFontAt(csBase.getFontIndex()));
		return cs;
	}
}

{'fraction_non_alphanumeric': 0.10763965555310223, 'fraction_numerical': 0.0009935968204901745, 'mean_word_length': 2.4655700076511096, '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': '830985', 'n_tokens_mistral': 3226, 'n_tokens_neox': 2858, 'n_words': 795}