Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/util/InternalBase.java

Issue 1162033004: Pull cacheinvalidations code directory into chromium repo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.ipc.invalidation.util;
18
19 /**
20 * {@code InternalBase} is a class from which other classes can derive that allo ws an efficient
21 * toString implementation for logging/debugging purposes for those classes. The class is abstract
22 * so that it is never instantiated explicitly.
23 *
24 */
25 public abstract class InternalBase {
26
27 /**
28 * Adds a compact representation of this object to {@code builder}.
29 *
30 * @param builder the builder in which the string representation is added
31 */
32 public abstract void toCompactString(TextBuilder builder);
33
34 /**
35 * Adds a verbose representation of this object to {@code builder}. The
36 * default implementation for toVerboseString is to simply call
37 * toCompactString.
38 *
39 * @param builder the builder in which the string representation is added
40 */
41 public void toVerboseString(TextBuilder builder) {
42 toCompactString(builder);
43 }
44
45 @Override
46 public String toString() {
47 TextBuilder builder = new TextBuilder();
48 toCompactString(builder);
49 return builder.toString();
50 }
51
52 /**
53 * Creates a TextBuilder internally and returns a string based on the {@code
54 * toVerboseString} method described above.
55 */
56 public String toVerboseString() {
57 TextBuilder builder = new TextBuilder();
58 toVerboseString(builder);
59 return builder.toString();
60 }
61
62 /**
63 * Given a set of {@code objects}, calls {@code toCompactString} on each of
64 * them with the {@code builder} and separates each object's output in the
65 * {@code builder} with a comma.
66 */
67 public static void toCompactStrings(TextBuilder builder,
68 Iterable<? extends InternalBase> objects) {
69 boolean first = true;
70 for (InternalBase object : objects) {
71 if (!first) {
72 builder.append(", ");
73 }
74 object.toCompactString(builder);
75 first = false;
76 }
77 }
78
79 /**
80 * Given a set of {@code objects}, calls {@code toString} on each of
81 * them with the {@code builder} and separates each object's output in the
82 * {@code builder} with a comma.
83 */
84 public static void toStrings(TextBuilder builder, Iterable<?> objects) {
85 boolean first = true;
86 for (Object object : objects) {
87 if (!first) {
88 builder.append(", ");
89 }
90 builder.append(object.toString());
91 first = false;
92 }
93 }
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698