<commit_before>package com.exedio.cope.lib;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;


public final class ReportTable extends ReportNode
{
	public final Report report;
	public final String name;
	private final Table table;
	private boolean exists = false;
	private ReportLastAnalyzed lastAnalyzed = null;

	private final HashMap columnMap = new HashMap();
	private final ArrayList columnList = new ArrayList();

	private final HashMap constraintMap = new HashMap();
	private final ArrayList constraintList = new ArrayList();

	ReportTable(final Report report, final com.exedio.cope.lib.Table table)
	{
		this.report = report;
		this.name = table.id;
		this.table = table;
		this.exists = false;
	}

	ReportTable(final Report report, final String name)
	{
		this.report = report;
		this.name = name;
		this.table = null;
		this.exists = true;
	}
		
	final void setLastAnalyzed(final Date lastAnalyzed)
	{
		if(this.lastAnalyzed!=null)
			throw new RuntimeException();

		this.lastAnalyzed = new ReportLastAnalyzed(lastAnalyzed, this);
	}
	
	final void notifyExists()
	{
		exists = true;
	}
		
	final ReportColumn notifyRequiredColumn(final Column column)
	{
		final ReportColumn result = new ReportColumn(column, this);
		if(columnMap.put(result.name, result)!=null)
			throw new RuntimeException(column.toString());
		columnList.add(result);
		return result;
	}
		
	final ReportColumn notifyExistentColumn(final String columnName, final String existingType)
	{
		ReportColumn result = (ReportColumn)columnMap.get(columnName);
		if(result==null)
		{
			result = new ReportColumn(columnName, existingType, this);
			columnMap.put(columnName, result);
			columnList.add(result);
		}
		else
		{
			result.notifyExists(existingType);
		}

		return result;
	}
	
	private final void addRequiredConstraint(final ReportConstraint constraint)
	{
		if(constraintMap.put(constraint.name, constraint)!=null)
			throw new RuntimeException(constraint.name);
		constraintList.add(constraint);
		constraint.notifyRequired();
	}
	
	final ReportConstraint notifyRequiredConstraint(final String constraintName)
	{
		final ReportConstraint result = new ReportConstraint(constraintName, this);
		addRequiredConstraint(result);
		return result;
	}
	
	final ReportConstraint notifyRequiredCheckConstraint(final String constraintName, final String condition)
	{
		final ReportConstraint result = new ReportConstraint(constraintName, this, condition);
		addRequiredConstraint(result);
		return result;
	}
	
	private final ReportConstraint getOrCreateExistentConstraint(final String constraintName)
	{
		ReportConstraint result = (ReportConstraint)constraintMap.get(constraintName);
		if(result==null)
		{
			result = new ReportConstraint(constraintName, this);
			constraintMap.put(constraintName, result);
			constraintList.add(result);
		}
		return result;
	}
		
	final ReportConstraint notifyExistentConstraint(final String constraintName)
	{
		final ReportConstraint result = getOrCreateExistentConstraint(constraintName);
		result.notifyExists();
		return result;
	}
	
	final ReportConstraint notifyExistentCheckConstraint(final String constraintName, final String condition)
	{
		final ReportConstraint result = getOrCreateExistentConstraint(constraintName);
		result.notifyExistsCheck(condition);
		return result;
	}
	
	public final boolean required()
	{
		return table!=null;
	}
	
	public final boolean exists()
	{
		return exists;
	}
		
	public final ReportLastAnalyzed getLastAnalyzed()
	{
		return lastAnalyzed;
	}
		
	public final Collection getColumns()
	{
		return columnList;
	}
		
	public final ReportColumn getColumn(final String columnName)
	{
		return (ReportColumn)columnMap.get(columnName);
	}
		
	public final Collection getConstraints()
	{
		return constraintList;
	}
		
	protected void finish()
	{
		if(cumulativeColor!=COLOR_NOT_YET_CALC || particularColor!=COLOR_NOT_YET_CALC)
			throw new RuntimeException();

		if(!exists)
		{
			error = "MISSING !!!";
			particularColor = COLOR_RED;
		}
		else if(table==null)
		{
			error = "not used";
			particularColor = COLOR_YELLOW;
		}
		else
			particularColor = COLOR_OK;
				
		cumulativeColor = particularColor;
			
		if(lastAnalyzed!=null)
		{
			lastAnalyzed.finish();
			cumulativeColor = Math.max(cumulativeColor, lastAnalyzed.cumulativeColor);
		}
			
		for(Iterator i = columnList.iterator(); i.hasNext(); )
		{
			final ReportColumn column = (ReportColumn)i.next();
			column.finish();<commit_msg>add getConstraint<commit_after>package com.exedio.cope.lib;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;


public final class ReportTable extends ReportNode
{
	public final Report report;
	public final String name;
	private final Table table;
	private boolean exists = false;
	private ReportLastAnalyzed lastAnalyzed = null;

	private final HashMap columnMap = new HashMap();
	private final ArrayList columnList = new ArrayList();

	private final HashMap constraintMap = new HashMap();
	private final ArrayList constraintList = new ArrayList();

	ReportTable(final Report report, final com.exedio.cope.lib.Table table)
	{
		this.report = report;
		this.name = table.id;
		this.table = table;
		this.exists = false;
	}

	ReportTable(final Report report, final String name)
	{
		this.report = report;
		this.name = name;
		this.table = null;
		this.exists = true;
	}
		
	final void setLastAnalyzed(final Date lastAnalyzed)
	{
		if(this.lastAnalyzed!=null)
			throw new RuntimeException();

		this.lastAnalyzed = new ReportLastAnalyzed(lastAnalyzed, this);
	}
	
	final void notifyExists()
	{
		exists = true;
	}
		
	final ReportColumn notifyRequiredColumn(final Column column)
	{
		final ReportColumn result = new ReportColumn(column, this);
		if(columnMap.put(result.name, result)!=null)
			throw new RuntimeException(column.toString());
		columnList.add(result);
		return result;
	}
		
	final ReportColumn notifyExistentColumn(final String columnName, final String existingType)
	{
		ReportColumn result = (ReportColumn)columnMap.get(columnName);
		if(result==null)
		{
			result = new ReportColumn(columnName, existingType, this);
			columnMap.put(columnName, result);
			columnList.add(result);
		}
		else
		{
			result.notifyExists(existingType);
		}

		return result;
	}
	
	private final void addRequiredConstraint(final ReportConstraint constraint)
	{
		if(constraintMap.put(constraint.name, constraint)!=null)
			throw new RuntimeException(constraint.name);
		constraintList.add(constraint);
		constraint.notifyRequired();
	}
	
	final ReportConstraint notifyRequiredConstraint(final String constraintName)
	{
		final ReportConstraint result = new ReportConstraint(constraintName, this);
		addRequiredConstraint(result);
		return result;
	}
	
	final ReportConstraint notifyRequiredCheckConstraint(final String constraintName, final String condition)
	{
		final ReportConstraint result = new ReportConstraint(constraintName, this, condition);
		addRequiredConstraint(result);
		return result;
	}
	
	private final ReportConstraint getOrCreateExistentConstraint(final String constraintName)
	{
		ReportConstraint result = (ReportConstraint)constraintMap.get(constraintName);
		if(result==null)
		{
			result = new ReportConstraint(constraintName, this);
			constraintMap.put(constraintName, result);
			constraintList.add(result);
		}
		return result;
	}
		
	final ReportConstraint notifyExistentConstraint(final String constraintName)
	{
		final ReportConstraint result = getOrCreateExistentConstraint(constraintName);
		result.notifyExists();
		return result;
	}
	
	final ReportConstraint notifyExistentCheckConstraint(final String constraintName, final String condition)
	{
		final ReportConstraint result = getOrCreateExistentConstraint(constraintName);
		result.notifyExistsCheck(condition);
		return result;
	}
	
	public final boolean required()
	{
		return table!=null;
	}
	
	public final boolean exists()
	{
		return exists;
	}
		
	public final ReportLastAnalyzed getLastAnalyzed()
	{
		return lastAnalyzed;
	}
		
	public final Collection getColumns()
	{
		return columnList;
	}
		
	public final ReportColumn getColumn(final String columnName)
	{
		return (ReportColumn)columnMap.get(columnName);
	}
		
	public final Collection getConstraints()
	{
		return constraintList;
	}
		
	public final ReportConstraint getConstraint(final String constraintName)
	{
		return (ReportConstraint)constraintMap.get(constraintName);
	}
		
	protected void finish()
	{
		if(cumulativeColor!=COLOR_NOT_YET_CALC || particularColor!=COLOR_NOT_YET_CALC)
			throw new RuntimeException();

		if(!exists)
		{
			error = "MISSING !!!";
			particularColor = COLOR_RED;
		}
		else if(table==null)
		{
			error = "not used";
			particularColor = COLOR_YELLOW;
		}
		else
			particularColor = COLOR_OK;
				
		cumulativeColor = particularColor;
			
		if(lastAnalyzed!=null)
		{
			lastAnalyzed.finish();
			cumulativeColor = Math.max(cumulativeColor, lastAnalyzed.cumulativeColor);
		}
			
		for(Iterator i = columnList.iterator(); i.hasNext(); )
		{
			final ReportColumn column = (ReportColumn)i.next();
			column.finish();
{'fraction_non_alphanumeric': 0.09005303604286179, 'fraction_numerical': 0.0, 'mean_word_length': 4.866666666666666, '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': '1205417', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2632, 'n_words': 646}