<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.toc;

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

import org.eclipse.birt.core.util.IOUtil;

/**
 * A class for building up TOC hierarchy
 */
public class TOCBuilder
{
	/**
	 * the root TOC entry
	 */
	private TOCTree tocTree;
	private TOCEntry rootEntry;

	private static final String VERSION = "__Version : 1.0";
	public static final String TOC_PREFIX = "__TOC";//

	/**
	 * @param tocTree
	 *            the root for the TOC tree
	 */
	public TOCBuilder( TOCTree tocTree )
	{
		this.tocTree = tocTree;
		TOCTreeNode root = tocTree.getTOCRoot( );
		rootEntry = new TOCEntry( null, root, root );
	}

	public TOCEntry startGroupEntry( TOCEntry parent, Object tocValue,
			String bookmark, String hiddenFormats )
	{
		return startEntry( parent, tocValue, bookmark, hiddenFormats, true );
	}

	private String mergeHideFormats( TOCEntry parent, String hiddenFormats )
	{
		String parentHiddenFormats = parent.getHideFormats( );
		if ( hiddenFormats == null )
		{
			return parentHiddenFormats;
		}
		if ( parentHiddenFormats == null )
		{
			return hiddenFormats;
		}
		return hiddenFormats + ", " + parentHiddenFormats ;
	}

	public void closeGroupEntry( TOCEntry group )
	{
	}

	/**
	 * @param displayString
	 *            display string for the TOC entry
	 * @param bookmark
	 */
	public TOCEntry startEntry( TOCEntry parent, Object tocValue,
			String bookmark, String hiddenFormats )
	{
		return startEntry( parent, tocValue, bookmark, hiddenFormats, false );
	}

	public TOCEntry startEntry( TOCEntry parent, Object tocValue,
			String bookmark, String hiddenFormats, boolean isGroupRoot )
	{
		assert tocValue != null;

		if ( parent == null )
		{
			parent = rootEntry;
		}

		TOCTreeNode parentNode = parent.node;
		TOCTreeNode node = new TOCTreeNode( );
		String id = parentNode.getNodeID( );
		if ( id == null )
		{<commit_msg>Fix bug 155010 Remove excessive "assert" statement<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.toc;

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

import org.eclipse.birt.core.util.IOUtil;

/**
 * A class for building up TOC hierarchy
 */
public class TOCBuilder
{
	/**
	 * the root TOC entry
	 */
	private TOCTree tocTree;
	private TOCEntry rootEntry;

	private static final String VERSION = "__Version : 1.0";
	public static final String TOC_PREFIX = "__TOC";//

	/**
	 * @param tocTree
	 *            the root for the TOC tree
	 */
	public TOCBuilder( TOCTree tocTree )
	{
		this.tocTree = tocTree;
		TOCTreeNode root = tocTree.getTOCRoot( );
		rootEntry = new TOCEntry( null, root, root );
	}

	public TOCEntry startGroupEntry( TOCEntry parent, Object tocValue,
			String bookmark, String hiddenFormats )
	{
		return startEntry( parent, tocValue, bookmark, hiddenFormats, true );
	}

	private String mergeHideFormats( TOCEntry parent, String hiddenFormats )
	{
		String parentHiddenFormats = parent.getHideFormats( );
		if ( hiddenFormats == null )
		{
			return parentHiddenFormats;
		}
		if ( parentHiddenFormats == null )
		{
			return hiddenFormats;
		}
		return hiddenFormats + ", " + parentHiddenFormats ;
	}

	public void closeGroupEntry( TOCEntry group )
	{
	}

	/**
	 * @param displayString
	 *            display string for the TOC entry
	 * @param bookmark
	 */
	public TOCEntry startEntry( TOCEntry parent, Object tocValue,
			String bookmark, String hiddenFormats )
	{
		return startEntry( parent, tocValue, bookmark, hiddenFormats, false );
	}

	public TOCEntry startEntry( TOCEntry parent, Object tocValue,
			String bookmark, String hiddenFormats, boolean isGroupRoot )
	{
		if ( parent == null )
		{
			parent = rootEntry;
		}

		TOCTreeNode parentNode = parent.node;
		TOCTreeNode node = new TOCTreeNode( );
		String id = parentNode.getNodeID( );
		if ( id == null )
		{
{'fraction_non_alphanumeric': 0.1483462071697366, 'fraction_numerical': 0.005149534561299267, 'mean_word_length': 3.970472440944882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2502492', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1484, 'n_words': 445}