001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.core.style; 018 019/** 020 * A strategy interface for pretty-printing {@code toString()} methods. 021 * Encapsulates the print algorithms; some other object such as a builder 022 * should provide the workflow. 023 * 024 * @author Keith Donald 025 * @since 1.2.2 026 */ 027public interface ToStringStyler { 028 029 /** 030 * Style a {@code toString()}'ed object before its fields are styled. 031 * @param buffer the buffer to print to 032 * @param obj the object to style 033 */ 034 void styleStart(StringBuilder buffer, Object obj); 035 036 /** 037 * Style a {@code toString()}'ed object after it's fields are styled. 038 * @param buffer the buffer to print to 039 * @param obj the object to style 040 */ 041 void styleEnd(StringBuilder buffer, Object obj); 042 043 /** 044 * Style a field value as a string. 045 * @param buffer the buffer to print to 046 * @param fieldName the he name of the field 047 * @param value the field value 048 */ 049 void styleField(StringBuilder buffer, String fieldName, Object value); 050 051 /** 052 * Style the given value. 053 * @param buffer the buffer to print to 054 * @param value the field value 055 */ 056 void styleValue(StringBuilder buffer, Object value); 057 058 /** 059 * Style the field separator. 060 * @param buffer buffer to print to 061 */ 062 void styleFieldSeparator(StringBuilder buffer); 063 064}