Debian Codegraph @

debian/patches/21-preserve-tostringhelper.patch

raw symbols SCIP
1 Descriptionscip-debian debian guava-libraries 32.0.1-1 guava-libraries/patches/`21-preserve-tostringhelper.patch`#Description.: Preserves the Objects.toStringHelper() methods which were removed in Guava 21.
2 Authorscip-debian debian guava-libraries 32.0.1-1 guava-libraries/patches/`21-preserve-tostringhelper.patch`#Author.: Emmanuel Bourg <[email protected]scip-debian . . . identity/`[email protected]`.>
3 Forwardedscip-debian debian guava-libraries 32.0.1-1 guava-libraries/patches/`21-preserve-tostringhelper.patch`#Forwarded.: not-needed
4 --- a/guava/src/com/google/common/base/Objects.javascip-debian debian guava-libraries 32.0.1-1 guava-libraries/upstream/`guava/src/com/google/common/base/Objects.java`:
5 +++ b/guava/src/com/google/common/base/Objects.javascip-debian debian guava-libraries 32.0.1-1 guava-libraries/upstream/`guava/src/com/google/common/base/Objects.java`:
6 @@ -14,7 +14,10 @@
7
8 package com.google.common.base;
9
10 +import static com.google.common.base.Preconditions.checkNotNull;
11 +
12 import com.google.common.annotations.GwtCompatible;
13 +import com.google.errorprone.annotations.CanIgnoreReturnValue;
14 import java.util.Arrays;
15 import javax.annotation.CheckForNull;
16 import org.checkerframework.checker.nullness.qual.Nullable;
17 @@ -99,4 +102,333 @@
18 public static <T> T firstNonNull(@Nullable T first, @Nullable T second) {
19 return MoreObjects.firstNonNull(first, second);
20 }
21 +
22 + /**
23 + * Creates an instance of {@link ToStringHelper}.
24 + *
25 + * <p>This is helpful for implementing {@link Object#toString()}. Specification by example:
26 + *
27 + * <pre> {@code
28 + * // Returns "ClassName{}"
29 + * Objects.toStringHelper(this)
30 + * .toString();
31 + *
32 + * // Returns "ClassName{x=1}"
33 + * Objects.toStringHelper(this)
34 + * .add("x", 1)
35 + * .toString();
36 + *
37 + * // Returns "MyObject{x=1}"
38 + * Objects.toStringHelper("MyObject")
39 + * .add("x", 1)
40 + * .toString();
41 + *
42 + * // Returns "ClassName{x=1, y=foo}"
43 + * Objects.toStringHelper(this)
44 + * .add("x", 1)
45 + * .add("y", "foo")
46 + * .toString();
47 + *
48 + * // Returns "ClassName{x=1}"
49 + * Objects.toStringHelper(this)
50 + * .omitNullValues()
51 + * .add("x", 1)
52 + * .add("y", null)
53 + * .toString();
54 + * }}</pre>
55 + *
56 + * <p>Note that in GWT, class names are often obfuscated.
57 + *
58 + * @param self the object to generate the string for (typically {@code this}), used only for its
59 + * class name
60 + * @since 2.0
61 + * @deprecated Use {@link MoreObjects#toStringHelper(Object)} instead. This method is scheduled
62 + * for removal in Guava 21.0.
63 + */
64 + @Deprecated
65 + public static ToStringHelper toStringHelper(Object self) {
66 + return new ToStringHelper(self.getClass().getSimpleName());
67 + }
68 +
69 + /**
70 + * Creates an instance of {@link ToStringHelper} in the same manner as
71 + * {@link Objects#toStringHelper(Object)}, but using the name of {@code clazz} instead of using an
72 + * instance's {@link Object#getClass()}.
73 + *
74 + * <p>Note that in GWT, class names are often obfuscated.
75 + *
76 + * @param clazz the {@link Class} of the instance
77 + * @since 7.0 (source-compatible since 2.0)
78 + * @deprecated Use {@link MoreObjects#toStringHelper(Class)} instead. This method is scheduled for
79 + * removal in Guava 21.0.
80 + */
81 + @Deprecated
82 + public static ToStringHelper toStringHelper(Class<?> clazz) {
83 + return new ToStringHelper(clazz.getSimpleName());
84 + }
85 +
86 + /**
87 + * Creates an instance of {@link ToStringHelper} in the same manner as
88 + * {@link Objects#toStringHelper(Object)}, but using {@code className} instead of using an
89 + * instance's {@link Object#getClass()}.
90 + *
91 + * @param className the name of the instance type
92 + * @since 7.0 (source-compatible since 2.0)
93 + * @deprecated Use {@link MoreObjects#toStringHelper(String)} instead. This method is scheduled
94 + * for removal in Guava 21.0.
95 + */
96 + @Deprecated
97 + public static ToStringHelper toStringHelper(String className) {
98 + return new ToStringHelper(className);
99 + }
100 +
101 + /**
102 + * Support class for {@link Objects#toStringHelper}.
103 + *
104 + * @author Jason Lee
105 + * @since 2.0
106 + * @deprecated Use {@link MoreObjects.ToStringHelper} instead. This class is scheduled for removal
107 + * in Guava 21.0.
108 + */
109 + @Deprecated
110 + public static final class ToStringHelper {
111 + private final String className;
112 + private final ValueHolder holderHead = new ValueHolder();
113 + private ValueHolder holderTail = holderHead;
114 + private boolean omitNullValues = false;
115 +
116 + /**
117 + * Use {@link Objects#toStringHelper(Object)} to create an instance.
118 + */
119 + private ToStringHelper(String className) {
120 + this.className = checkNotNull(className);
121 + }
122 +
123 + /**
124 + * Configures the {@link ToStringHelper} so {@link #toString()} will ignore properties with null
125 + * value. The order of calling this method, relative to the {@code add()}/{@code addValue()}
126 + * methods, is not significant.
127 + *
128 + * @since 12.0
129 + */
130 + @CanIgnoreReturnValue
131 + public ToStringHelper omitNullValues() {
132 + omitNullValues = true;
133 + return this;
134 + }
135 +
136 + /**
137 + * Adds a name/value pair to the formatted output in {@code name=value} format. If {@code value}
138 + * is {@code null}, the string {@code "null"} is used, unless {@link #omitNullValues()} is
139 + * called, in which case this name/value pair will not be added.
140 + */
141 + @CanIgnoreReturnValue
142 + public ToStringHelper add(String name, @Nullable Object value) {
143 + return addHolder(name, value);
144 + }
145 +
146 + /**
147 + * Adds a name/value pair to the formatted output in {@code name=value} format.
148 + *
149 + * @since 11.0 (source-compatible since 2.0)
150 + */
151 + @CanIgnoreReturnValue
152 + public ToStringHelper add(String name, boolean value) {
153 + return addHolder(name, String.valueOf(value));
154 + }
155 +
156 + /**
157 + * Adds a name/value pair to the formatted output in {@code name=value} format.
158 + *
159 + * @since 11.0 (source-compatible since 2.0)
160 + */
161 + @CanIgnoreReturnValue
162 + public ToStringHelper add(String name, char value) {
163 + return addHolder(name, String.valueOf(value));
164 + }
165 +
166 + /**
167 + * Adds a name/value pair to the formatted output in {@code name=value} format.
168 + *
169 + * @since 11.0 (source-compatible since 2.0)
170 + */
171 + @CanIgnoreReturnValue
172 + public ToStringHelper add(String name, double value) {
173 + return addHolder(name, String.valueOf(value));
174 + }
175 +
176 + /**
177 + * Adds a name/value pair to the formatted output in {@code name=value} format.
178 + *
179 + * @since 11.0 (source-compatible since 2.0)
180 + */
181 + @CanIgnoreReturnValue
182 + public ToStringHelper add(String name, float value) {
183 + return addHolder(name, String.valueOf(value));
184 + }
185 +
186 + /**
187 + * Adds a name/value pair to the formatted output in {@code name=value} format.
188 + *
189 + * @since 11.0 (source-compatible since 2.0)
190 + */
191 + @CanIgnoreReturnValue
192 + public ToStringHelper add(String name, int value) {
193 + return addHolder(name, String.valueOf(value));
194 + }
195 +
196 + /**
197 + * Adds a name/value pair to the formatted output in {@code name=value} format.
198 + *
199 + * @since 11.0 (source-compatible since 2.0)
200 + */
201 + @CanIgnoreReturnValue
202 + public ToStringHelper add(String name, long value) {
203 + return addHolder(name, String.valueOf(value));
204 + }
205 +
206 + /**
207 + * Adds an unnamed value to the formatted output.
208 + *
209 + * <p>It is strongly encouraged to use {@link #add(String, Object)} instead and give value a
210 + * readable name.
211 + */
212 + @CanIgnoreReturnValue
213 + public ToStringHelper addValue(@Nullable Object value) {
214 + return addHolder(value);
215 + }
216 +
217 + /**
218 + * Adds an unnamed value to the formatted output.
219 + *
220 + * <p>It is strongly encouraged to use {@link #add(String, boolean)} instead and give value a
221 + * readable name.
222 + *
223 + * @since 11.0 (source-compatible since 2.0)
224 + */
225 + @CanIgnoreReturnValue
226 + public ToStringHelper addValue(boolean value) {
227 + return addHolder(String.valueOf(value));
228 + }
229 +
230 + /**
231 + * Adds an unnamed value to the formatted output.
232 + *
233 + * <p>It is strongly encouraged to use {@link #add(String, char)} instead and give value a
234 + * readable name.
235 + *
236 + * @since 11.0 (source-compatible since 2.0)
237 + */
238 + @CanIgnoreReturnValue
239 + public ToStringHelper addValue(char value) {
240 + return addHolder(String.valueOf(value));
241 + }
242 +
243 + /**
244 + * Adds an unnamed value to the formatted output.
245 + *
246 + * <p>It is strongly encouraged to use {@link #add(String, double)} instead and give value a
247 + * readable name.
248 + *
249 + * @since 11.0 (source-compatible since 2.0)
250 + */
251 + @CanIgnoreReturnValue
252 + public ToStringHelper addValue(double value) {
253 + return addHolder(String.valueOf(value));
254 + }
255 +
256 + /**
257 + * Adds an unnamed value to the formatted output.
258 + *
259 + * <p>It is strongly encouraged to use {@link #add(String, float)} instead and give value a
260 + * readable name.
261 + *
262 + * @since 11.0 (source-compatible since 2.0)
263 + */
264 + @CanIgnoreReturnValue
265 + public ToStringHelper addValue(float value) {
266 + return addHolder(String.valueOf(value));
267 + }
268 +
269 + /**
270 + * Adds an unnamed value to the formatted output.
271 + *
272 + * <p>It is strongly encouraged to use {@link #add(String, int)} instead and give value a
273 + * readable name.
274 + *
275 + * @since 11.0 (source-compatible since 2.0)
276 + */
277 + @CanIgnoreReturnValue
278 + public ToStringHelper addValue(int value) {
279 + return addHolder(String.valueOf(value));
280 + }
281 +
282 + /**
283 + * Adds an unnamed value to the formatted output.
284 + *
285 + * <p>It is strongly encouraged to use {@link #add(String, long)} instead and give value a
286 + * readable name.
287 + *
288 + * @since 11.0 (source-compatible since 2.0)
289 + */
290 + @CanIgnoreReturnValue
291 + public ToStringHelper addValue(long value) {
292 + return addHolder(String.valueOf(value));
293 + }
294 +
295 + /**
296 + * Returns a string in the format specified by {@link Objects#toStringHelper(Object)}.
297 + *
298 + * <p>After calling this method, you can keep adding more properties to later call toString()
299 + * again and get a more complete representation of the same object; but properties cannot be
300 + * removed, so this only allows limited reuse of the helper instance. The helper allows
301 + * duplication of properties (multiple name/value pairs with the same name can be added).
302 + */
303 + @Override
304 + public String toString() {
305 + // create a copy to keep it consistent in case value changes
306 + boolean omitNullValuesSnapshot = omitNullValues;
307 + String nextSeparator = "";
308 + StringBuilder builder = new StringBuilder(32).append(className).append('{');
309 + for (ValueHolder valueHolder = holderHead.next;
310 + valueHolder != null;
311 + valueHolder = valueHolder.next) {
312 + if (!omitNullValuesSnapshot || valueHolder.value != null) {
313 + builder.append(nextSeparator);
314 + nextSeparator = ", ";
315 +
316 + if (valueHolder.name != null) {
317 + builder.append(valueHolder.name).append('=');
318 + }
319 + builder.append(valueHolder.value);
320 + }
321 + }
322 + return builder.append('}').toString();
323 + }
324 +
325 + private ValueHolder addHolder() {
326 + ValueHolder valueHolder = new ValueHolder();
327 + holderTail = holderTail.next = valueHolder;
328 + return valueHolder;
329 + }
330 +
331 + private ToStringHelper addHolder(@Nullable Object value) {
332 + ValueHolder valueHolder = addHolder();
333 + valueHolder.value = value;
334 + return this;
335 + }
336 +
337 + private ToStringHelper addHolder(String name, @Nullable Object value) {
338 + ValueHolder valueHolder = addHolder();
339 + valueHolder.value = value;
340 + valueHolder.name = checkNotNull(name);
341 + return this;
342 + }
343 +
344 + private static final class ValueHolder {
345 + String name;
346 + Object value;
347 + ValueHolder next;
348 + }
349 + }
350 }