<commit_before>package me.doubledutch.lazyjson;

import me.doubledutch.lazyjson.compressor.*;
import java.nio.ByteBuffer;
import java.nio.BufferOverflowException;

public class LazyElement{
	protected LazyNode root;
	protected char[] cbuf;

	// Cache value for length
	private int length=-1;

	protected LazyElement(LazyNode root,char[] source){
		this.root=root;
		this.cbuf=source;
	}

	protected LazyElement() throws LazyException{

	}

	protected char[] getCharBuffer(){
		return cbuf;
	}

	public Template extractTemplate(){
		Template t=new Template();
		root.addSegments(cbuf,t);
		t.compact();
		return t;
	}

	public void writeTemplateValues(ByteBuffer buf,DictionaryCache dict) throws BufferOverflowException{
		root.writeSegmentValues(cbuf,buf,dict);
	}

	/**
	 * Parses a string and returns either a LazyObject or LazyArray
	 *
	 * @param str the source json data
	 * @return either a LazyObject or LazyArray instance
	 * @throws LazyException if the string could not be parsed
	 */
	public static LazyElement parse(String str) throws LazyException{
		int index=0;
		while(index<str.length()){
			char ch=str.charAt(index);
			if(ch=='['){
				return new LazyArray(str);
			}
			if(ch=='{'){
				return new LazyObject(str);
			}
			index++;
		}
		return null;
	}

	public static LazyElement readFromTemplate(Template t,ByteBuffer buf,DictionaryCache dict) throws LazyException{
		String str=t.read(buf,dict);
		// System.out.println(str);
		return parse(str);
	}

	/**
	 * Returns the number of fields on this object
	 *
	 * @return the number of fields<commit_msg>throw exception after unknown element<commit_after>package me.doubledutch.lazyjson;

import me.doubledutch.lazyjson.compressor.*;
import java.nio.ByteBuffer;
import java.nio.BufferOverflowException;

public class LazyElement{
	protected LazyNode root;
	protected char[] cbuf;

	// Cache value for length
	private int length=-1;

	protected LazyElement(LazyNode root,char[] source){
		this.root=root;
		this.cbuf=source;
	}

	protected LazyElement() throws LazyException{

	}

	protected char[] getCharBuffer(){
		return cbuf;
	}

	public Template extractTemplate(){
		Template t=new Template();
		root.addSegments(cbuf,t);
		t.compact();
		return t;
	}

	public void writeTemplateValues(ByteBuffer buf,DictionaryCache dict) throws BufferOverflowException{
		root.writeSegmentValues(cbuf,buf,dict);
	}

	/**
	 * Parses a string and returns either a LazyObject or LazyArray
	 *
	 * @param str the source json data
	 * @return either a LazyObject or LazyArray instance
	 * @throws LazyException if the string could not be parsed
	 */
	public static LazyElement parse(String str) throws LazyException{
		int index=0;
		while(index<str.length()){
			char ch=str.charAt(index);
			if(ch=='['){
				return new LazyArray(str);
			}
			if(ch=='{'){
				return new LazyObject(str);
			}
			index++;
		}
		throw new LazyException("The given string is not a JSON object or array");
	}

	public static LazyElement readFromTemplate(Template t,ByteBuffer buf,DictionaryCache dict) throws LazyException{
		String str=t.read(buf,dict);
		// System.out.println(str);
		return parse(str);
	}

	/**
	 * Returns the number of fields on this object
	 *
	 * @return the number of fields
{'fraction_non_alphanumeric': 0.10617283950617284, 'fraction_numerical': 0.0012345679012345679, 'mean_word_length': 4.35702479338843, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4437303', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1002, 'n_words': 291}