<commit_before>/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.exedio.cope;

public final class ReportColumn extends ReportNode
{
	public final String name;
	public final ReportTable table;
	private final String requiredType;
	private boolean exists;
	private String existingType;
		
	ReportColumn(final String name, final String type, final boolean required, final ReportTable table)
	{
		if(name==null)
			throw new RuntimeException(type);
		if(type==null)
			throw new RuntimeException(name);
		if(table==null)
			throw new RuntimeException(name);

		this.name = name;
		this.table = table;
		if(required)
		{
			this.requiredType = type;
			this.existingType = null;
		}
		else
		{
			this.requiredType = null;
			this.existingType = type;
		}
		this.exists = !required;
	}

	void notifyExists(final String existingType)
	{
		if(exists && !this.existingType.equals(existingType))
			throw new RuntimeException(name);

		this.existingType = existingType;
		exists = true;
	}

	protected void finish()
	{
		if(cumulativeColor!=COLOR_NOT_YET_CALC || particularColor!=COLOR_NOT_YET_CALC)
			throw new RuntimeException();

		if(!exists)
		{
			error = "missing";
			particularColor = COLOR_ERROR;
		}
		else if(requiredType==null)
		{
			error = "not used";
			particularColor = COLOR_WARNING;
		}
		else
		{
			if(requiredType!=null &&
				existingType!=null &&
				!requiredType.equals(existingType))
			{
				error = "different type in database: >"+existingType+"<";
				particularColor = COLOR_ERROR;
			}
			else
				particularColor = COLOR_OK;
		}
				
		cumulativeColor = particularColor;
	}
		
	public final boolean required()
	{
		return requiredType!=null;
	}
	
	public final boolean exists()
	{
		return exists;
	}
		
	public final String getDatabaseType()
	{
		if(requiredType!=null)
			return requiredType;
		else<commit_msg>remove ReportColumn#exists, use existingType instead<commit_after>/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.exedio.cope;

public final class ReportColumn extends ReportNode
{
	public final String name;
	public final ReportTable table;
	private final String requiredType;
	private String existingType;
		
	ReportColumn(final String name, final String type, final boolean required, final ReportTable table)
	{
		if(name==null)
			throw new RuntimeException(type);
		if(type==null)
			throw new RuntimeException(name);
		if(table==null)
			throw new RuntimeException(name);

		this.name = name;
		this.table = table;
		if(required)
		{
			this.requiredType = type;
			this.existingType = null;
		}
		else
		{
			this.requiredType = null;
			this.existingType = type;
		}
	}

	void notifyExists(final String existingType)
	{
		if(existingType==null)
			throw new RuntimeException(name);
		if(this.existingType!=null && !this.existingType.equals(existingType))
			throw new RuntimeException(name);

		this.existingType = existingType;
	}

	protected void finish()
	{
		if(cumulativeColor!=COLOR_NOT_YET_CALC || particularColor!=COLOR_NOT_YET_CALC)
			throw new RuntimeException();

		if(existingType==null)
		{
			error = "missing";
			particularColor = COLOR_ERROR;
		}
		else if(requiredType==null)
		{
			error = "not used";
			particularColor = COLOR_WARNING;
		}
		else
		{
			if(requiredType!=null &&
				existingType!=null &&
				!requiredType.equals(existingType))
			{
				error = "different type in database: >"+existingType+"<";
				particularColor = COLOR_ERROR;
			}
			else
				particularColor = COLOR_OK;
		}
				
		cumulativeColor = particularColor;
	}
		
	public final boolean required()
	{
		return requiredType!=null;
	}
	
	public final boolean exists()
	{
		return existingType!=null;
	}
		
	public final String getDatabaseType()
	{
		if(requiredType!=null)
			return requiredType;
		else
{'fraction_non_alphanumeric': 0.08825757575757576, 'fraction_numerical': 0.00909090909090909, 'mean_word_length': 3.871771217712177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3857704', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1541, 'n_words': 518}