001/* 002 * Copyright 2002-2017 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 019import org.springframework.lang.Nullable; 020 021/** 022 * A strategy interface for pretty-printing {@code toString()} methods. 023 * Encapsulates the print algorithms; some other object such as a builder 024 * should provide the workflow. 025 * 026 * @author Keith Donald 027 * @since 1.2.2 028 */ 029public interface ToStringStyler { 030 031 /** 032 * Style a {@code toString()}'ed object before its fields are styled. 033 * @param buffer the buffer to print to 034 * @param obj the object to style 035 */ 036 void styleStart(StringBuilder buffer, Object obj); 037 038 /** 039 * Style a {@code toString()}'ed object after it's fields are styled. 040 * @param buffer the buffer to print to 041 * @param obj the object to style 042 */ 043 void styleEnd(StringBuilder buffer, Object obj); 044 045 /** 046 * Style a field value as a string. 047 * @param buffer the buffer to print to 048 * @param fieldName the he name of the field 049 * @param value the field value 050 */ 051 void styleField(StringBuilder buffer, String fieldName, @Nullable Object value); 052 053 /** 054 * Style the given value. 055 * @param buffer the buffer to print to 056 * @param value the field value 057 */ 058 void styleValue(StringBuilder buffer, Object value); 059 060 /** 061 * Style the field separator. 062 * @param buffer the buffer to print to 063 */ 064 void styleFieldSeparator(StringBuilder buffer); 065 066}