Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Add copyright and format
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Dec 4, 2018
1 parent 00bbe10 commit e23c638
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package org.matrix.androidsdk.util;
/*
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.androidsdk.util;

import java.io.IOException;
import java.lang.annotation.Annotation;
Expand All @@ -13,14 +28,15 @@

public final class PolymorphicRequestBodyConverter<T> implements Converter<T, RequestBody> {
public static final Factory FACTORY = new Factory() {
@Override public Converter<?, RequestBody> requestBodyConverter(
Type type,
Annotation[] parameterAnnotations,
Annotation[] methodAnnotations,
Retrofit retrofit
@Override
public Converter<?, RequestBody> requestBodyConverter(
Type type,
Annotation[] parameterAnnotations,
Annotation[] methodAnnotations,
Retrofit retrofit
) {
return new PolymorphicRequestBodyConverter<>(
this, parameterAnnotations, methodAnnotations, retrofit
this, parameterAnnotations, methodAnnotations, retrofit
);
}
};
Expand All @@ -32,25 +48,26 @@ public final class PolymorphicRequestBodyConverter<T> implements Converter<T, Re
private final Map<Class<?>, Converter<T, RequestBody>> cache = new LinkedHashMap<>();

PolymorphicRequestBodyConverter(
Factory skipPast,
Annotation[] parameterAnnotations,
Annotation[] methodsAnnotations,
Retrofit retrofit) {
Factory skipPast,
Annotation[] parameterAnnotations,
Annotation[] methodsAnnotations,
Retrofit retrofit) {
this.skipPast = skipPast;
this.parameterAnnotations = parameterAnnotations;
this.methodsAnnotations = methodsAnnotations;
this.retrofit = retrofit;
}

@Override public RequestBody convert(T value) throws IOException {
@Override
public RequestBody convert(T value) throws IOException {
Class<?> cls = value.getClass();
Converter<T, RequestBody> requestBodyConverter;
synchronized (cache) {
requestBodyConverter = cache.get(cls);
}
if (requestBodyConverter == null) {
requestBodyConverter = retrofit.nextRequestBodyConverter(
skipPast, cls, parameterAnnotations, methodsAnnotations
skipPast, cls, parameterAnnotations, methodsAnnotations
);
synchronized (cache) {
cache.put(cls, requestBodyConverter);
Expand Down

0 comments on commit e23c638

Please sign in to comment.