<commit_before>/*
 * Copyright 2002-2005 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.core.style;

import org.springframework.util.Assert;

/**
 * Utility class that builds pretty-printing <code>toString()</code> methods
 * with pluggable styling conventions. By default, ToStringCreator adheres
 * to Spring's <code>toString()</code> styling conventions.
 * 
 * @author <NAME>
 * @author <NAME>
 * @since 1.2.2
 */
public class ToStringCreator {

	private static ToStringStyler DEFAULT_TO_STRING_STYLER =
			new DefaultToStringStyler(new DefaultValueStyler());

	public static final void load(ToStringStyler defaultStyler) {
		DEFAULT_TO_STRING_STYLER = defaultStyler;
	}


	private StringBuffer buffer = new StringBuffer(512);

	private ToStringStyler styler;

	private Object object;

	private boolean styledFirstField;


	/**
	 * Create a ToStringBuilder for this object.
	 * @param obj the object to be stringified
	 */
	public ToStringCreator(Object obj) {
		this(obj, null);
	}

	/**
	 * Create a ToStringBuilder for this object with the provided style.
	 * @param obj the object to be stringified
	 * @param styler the styler encapsulating pretty-print instructions
	 */
	public ToStringCreator(Object obj, ToStringStyler styler) {
		Assert.notNull(obj, "The object to be styled is required");
		this.object = obj;
		this.styler = (styler != null ? styler : DEFAULT_TO_STRING_STYLER);
		this.styler.styleStart(this.buffer, this.object);
	}


	/**
	 * Append a byte field value.
	 * @param fieldName the name of the field, usually the member variable name
	 * @param value the field value
	 * @return this, to support call-chaining
	 */
	public ToStringCreator append(String fieldName, byte value) {
		return append(fieldName, new Byte(value));
	}

	/**<commit_msg>added public static DEFAULT_VALUE_STYLER reference and convenience constructor that takes a ValueStyler as argument, dropped load method for overriding the global default styler<commit_after>/*
 * Copyright 2002-2005 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.core.style;

import org.springframework.util.Assert;

/**
 * Utility class that builds pretty-printing <code>toString()</code> methods
 * with pluggable styling conventions. By default, ToStringCreator adheres
 * to Spring's <code>toString()</code> styling conventions.
 * 
 * @author <NAME>
 * @author <NAME>
 * @since 1.2.2
 */
public class ToStringCreator {

	/**
	 * Default ValueStyler instance used by this ToStringCreator.
	 * Also available for direct use.
	 */
	public static final ValueStyler DEFAULT_VALUE_STYLER = new DefaultValueStyler();

	/**
	 * Default ToStringStyler instance used by this ToStringCreator.
	 * Also available for direct use.
	 */
	public static final ToStringStyler DEFAULT_TO_STRING_STYLER =
			new DefaultToStringStyler(DEFAULT_VALUE_STYLER);


	private StringBuffer buffer = new StringBuffer(512);

	private ToStringStyler styler;

	private Object object;

	private boolean styledFirstField;


	/**
	 * Create a ToStringBuilder for this object.
	 * @param obj the object to be stringified
	 */
	public ToStringCreator(Object obj) {
		this(obj, (ToStringStyler) null);
	}

	/**
	 * Create a ToStringBuilder for this object with the provided style.
	 * @param obj the object to be stringified
	 * @param styler the ValueStyler encapsulating pretty-print instructions
	 */
	public ToStringCreator(Object obj, ValueStyler styler) {
		this(obj, new DefaultToStringStyler(styler != null ? styler : DEFAULT_VALUE_STYLER));
	}

	/**
	 * Create a ToStringBuilder for this object with the provided style.
	 * @param obj the object to be stringified
	 * @param styler the ToStringStyler encapsulating pretty-print instructions
	 */
	public ToStringCreator(Object obj, ToStringStyler styler) {
		Assert.notNull(obj, "The object to be styled is required");
		this.object = obj;
		this.styler = (styler != null ? styler : DEFAULT_TO_STRING_STYLER);
		this.styler.styleStart(this.buffer, this.object);
	}


	/**
	 * Append a byte field value.
	 * @param fieldName the name of the field, usually the member variable name
	 * @param value the field value
	 * @return this, to support call-chaining
	 */
	public ToStringCreator append(String fieldName, byte value) {
		return append(fieldName, new Byte(value));
	}

	/**
{'fraction_non_alphanumeric': 0.08359418155035905, 'fraction_numerical': 0.006628613515006445, 'mean_word_length': 4.188156638013371, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6076469', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1470, 'n_words': 579}