aboutsummaryrefslogtreecommitdiff
path: root/java/core/src/main/java/com/google/protobuf/RpcUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/RpcUtil.java')
-rw-r--r--java/core/src/main/java/com/google/protobuf/RpcUtil.java50
1 files changed, 20 insertions, 30 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/RpcUtil.java b/java/core/src/main/java/com/google/protobuf/RpcUtil.java
index f7d555ae..7bd056a5 100644
--- a/java/core/src/main/java/com/google/protobuf/RpcUtil.java
+++ b/java/core/src/main/java/com/google/protobuf/RpcUtil.java
@@ -39,14 +39,13 @@ public final class RpcUtil {
private RpcUtil() {}
/**
- * Take an {@code RpcCallback<Message>} and convert it to an
- * {@code RpcCallback} accepting a specific message type. This is always
- * type-safe (parameter type contravariance).
+ * Take an {@code RpcCallback<Message>} and convert it to an {@code RpcCallback} accepting a
+ * specific message type. This is always type-safe (parameter type contravariance).
*/
@SuppressWarnings("unchecked")
- public static <Type extends Message> RpcCallback<Type>
- specializeCallback(final RpcCallback<Message> originalCallback) {
- return (RpcCallback<Type>)originalCallback;
+ public static <Type extends Message> RpcCallback<Type> specializeCallback(
+ final RpcCallback<Message> originalCallback) {
+ return (RpcCallback<Type>) originalCallback;
// The above cast works, but only due to technical details of the Java
// implementation. A more theoretically correct -- but less efficient --
// implementation would be as follows:
@@ -58,15 +57,13 @@ public final class RpcUtil {
}
/**
- * Take an {@code RpcCallback} accepting a specific message type and convert
- * it to an {@code RpcCallback<Message>}. The generalized callback will
- * accept any message object which has the same descriptor, and will convert
- * it to the correct class before calling the original callback. However,
- * if the generalized callback is given a message with a different descriptor,
- * an exception will be thrown.
+ * Take an {@code RpcCallback} accepting a specific message type and convert it to an {@code
+ * RpcCallback<Message>}. The generalized callback will accept any message object which has the
+ * same descriptor, and will convert it to the correct class before calling the original callback.
+ * However, if the generalized callback is given a message with a different descriptor, an
+ * exception will be thrown.
*/
- public static <Type extends Message>
- RpcCallback<Message> generalizeCallback(
+ public static <Type extends Message> RpcCallback<Message> generalizeCallback(
final RpcCallback<Type> originalCallback,
final Class<Type> originalClass,
final Type defaultInstance) {
@@ -85,25 +82,21 @@ public final class RpcUtil {
}
/**
- * Creates a new message of type "Type" which is a copy of "source". "source"
- * must have the same descriptor but may be a different class (e.g.
- * DynamicMessage).
+ * Creates a new message of type "Type" which is a copy of "source". "source" must have the same
+ * descriptor but may be a different class (e.g. DynamicMessage).
*/
@SuppressWarnings("unchecked")
private static <Type extends Message> Type copyAsType(
final Type typeDefaultInstance, final Message source) {
- return (Type) typeDefaultInstance
- .newBuilderForType().mergeFrom(source).build();
+ return (Type) typeDefaultInstance.newBuilderForType().mergeFrom(source).build();
}
/**
- * Creates a callback which can only be called once. This may be useful for
- * security, when passing a callback to untrusted code: most callbacks do
- * not expect to be called more than once, so doing so may expose bugs if it
- * is not prevented.
+ * Creates a callback which can only be called once. This may be useful for security, when passing
+ * a callback to untrusted code: most callbacks do not expect to be called more than once, so
+ * doing so may expose bugs if it is not prevented.
*/
- public static <ParameterType>
- RpcCallback<ParameterType> newOneTimeCallback(
+ public static <ParameterType> RpcCallback<ParameterType> newOneTimeCallback(
final RpcCallback<ParameterType> originalCallback) {
return new RpcCallback<ParameterType>() {
private boolean alreadyCalled = false;
@@ -122,15 +115,12 @@ public final class RpcUtil {
};
}
- /**
- * Exception thrown when a one-time callback is called more than once.
- */
+ /** Exception thrown when a one-time callback is called more than once. */
public static final class AlreadyCalledException extends RuntimeException {
private static final long serialVersionUID = 5469741279507848266L;
public AlreadyCalledException() {
- super("This RpcCallback was already called and cannot be called " +
- "multiple times.");
+ super("This RpcCallback was already called and cannot be called multiple times.");
}
}
}