<commit_before>
package org.eclipse.birt.report.engine.content.impl;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Iterator;

import org.eclipse.birt.core.util.IOUtil;
import org.eclipse.birt.report.engine.content.IBandContent;
import org.eclipse.birt.report.engine.content.IContentVisitor;
import org.eclipse.birt.report.engine.content.IGroupContent;
import org.eclipse.birt.report.engine.content.IReportContent;
import org.eclipse.birt.report.engine.ir.GroupDesign;

public class GroupContent extends AbstractContent implements IGroupContent
{

	Boolean headerRepeat;
	
	String groupId;
	
	public int getContentType( )
	{
		return GROUP_CONTENT;
	}
	
	public GroupContent( IReportContent report )
	{
		super( report );
	}

	public IBandContent getHeader( )
	{
		return getBand( IBandContent.BAND_GROUP_HEADER );
	}

	public IBandContent getFooter( )
	{
		return getBand( IBandContent.BAND_GROUP_FOOTER );
	}

	protected IBandContent getBand( int type )
	{
		if ( children == null )
		{
			return null;
		}
		Iterator iter = children.iterator( );
		while ( iter.hasNext( ) )
		{
			Object child = iter.next( );
			if ( child instanceof IBandContent )
			{
				IBandContent band = (IBandContent) child;
				if ( band.getBandType( ) == type )
				{
					return band;
				}
			}
		}
		return null;
	}
	
	public String getGroupID( )
	{
		return groupId;
	}
	
	public void setGroupID(String groupId)
	{
		this.groupId = groupId;
	}

	public boolean isHeaderRepeat( )
	{
		if (headerRepeat != null)
		{
			return headerRepeat.booleanValue( );
		}
		if (generateBy instanceof GroupDesign)
		{
			GroupDesign design = (GroupDesign)generateBy;
			return design.isHeaderRepeat( );
			
		}
		return false;
	}
	
	public int getGroupLevel()
	{
		if (generateBy instanceof GroupDesign)
		{
			GroupDesign design = (GroupDesign)generateBy;
			return design.getGroupLevel( );
		}
		return -1;
	}

	public void setHeaderRepeat( boolean repeat )
	{
		headerRepeat = Boolean.valueOf( repeat );
	}

	public Object accept( IContentVisitor visitor, Object value )
	{
		return visitor.visitGroup( this, value );
	}

	static final protected short FIELD_HEADER_REPEAT = 1500;

	protected void writeFields( DataOutputStream out ) throws IOException
	{
		super.writeFields( out );
		if ( headerRepeat != null )
		{
			IOUtil.writeShort( out, FIELD_HEADER_REPEAT);
			IOUtil.writeBool( out, headerRepeat.booleanValue( ) );
		}
	}

	protected void readField( int version, int filedId, DataInputStream in )
			throws IOException
	{
		switch ( filedId )<commit_msg>fix bug176579, change the getGroupLevel() method.<commit_after>
package org.eclipse.birt.report.engine.content.impl;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Iterator;

import org.eclipse.birt.core.util.IOUtil;
import org.eclipse.birt.report.engine.content.IBandContent;
import org.eclipse.birt.report.engine.content.IContentVisitor;
import org.eclipse.birt.report.engine.content.IGroupContent;
import org.eclipse.birt.report.engine.content.IReportContent;
import org.eclipse.birt.report.engine.ir.GroupDesign;

public class GroupContent extends AbstractContent implements IGroupContent
{

	Boolean headerRepeat;
	
	String groupId;
	
	public int getContentType( )
	{
		return GROUP_CONTENT;
	}
	
	public GroupContent( IReportContent report )
	{
		super( report );
	}

	public IBandContent getHeader( )
	{
		return getBand( IBandContent.BAND_GROUP_HEADER );
	}

	public IBandContent getFooter( )
	{
		return getBand( IBandContent.BAND_GROUP_FOOTER );
	}

	protected IBandContent getBand( int type )
	{
		if ( children == null )
		{
			return null;
		}
		Iterator iter = children.iterator( );
		while ( iter.hasNext( ) )
		{
			Object child = iter.next( );
			if ( child instanceof IBandContent )
			{
				IBandContent band = (IBandContent) child;
				if ( band.getBandType( ) == type )
				{
					return band;
				}
			}
		}
		return null;
	}
	
	public String getGroupID( )
	{
		return groupId;
	}
	
	public void setGroupID(String groupId)
	{
		this.groupId = groupId;
	}

	public boolean isHeaderRepeat( )
	{
		if (headerRepeat != null)
		{
			return headerRepeat.booleanValue( );
		}
		if (generateBy instanceof GroupDesign)
		{
			GroupDesign design = (GroupDesign)generateBy;
			return design.isHeaderRepeat( );
			
		}
		return false;
	}
	
	transient int groupLevel = -1;
	public int getGroupLevel()
	{
		if ( groupLevel == -1 )
		{
			if ( generateBy instanceof GroupDesign )
			{
				GroupDesign design = (GroupDesign) generateBy;
				groupLevel = design.getGroupLevel( );
			}
			else if ( parent instanceof GroupContent )
			{
				groupLevel = ( (GroupContent)parent ).getGroupLevel( );
			}
			else
			{
				return 0;
			}
		}
		return groupLevel;
	}

	public void setHeaderRepeat( boolean repeat )
	{
		headerRepeat = Boolean.valueOf( repeat );
	}

	public Object accept( IContentVisitor visitor, Object value )
	{
		return visitor.visitGroup( this, value );
	}

	static final protected short FIELD_HEADER_REPEAT = 1500;

	protected void writeFields( DataOutputStream out ) throws IOException
	{
		super.writeFields( out );
		if ( headerRepeat != null )
		{
			IOUtil.writeShort( out, FIELD_HEADER_REPEAT);
			IOUtil.writeBool( out, headerRepeat.booleanValue( ) );
		}
	}

	protected void readField( int version, int filedId, DataInputStream in )
			throws IOException
	{
		switch ( filedId )
{'fraction_non_alphanumeric': 0.097953216374269, 'fraction_numerical': 0.003289473684210526, 'mean_word_length': 3.6938250428816466, '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': '988831', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1772, 'n_words': 404}