Skip to content

Commit

Permalink
Fixing spotless for all files
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Oct 2, 2023
1 parent 9258aa4 commit 84e6a58
Show file tree
Hide file tree
Showing 1,649 changed files with 271,896 additions and 272,227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@

package org.opensearch.client;

import org.opensearch.client.transport.TransportOptions;
import org.opensearch.client.transport.Transport;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapperBase;

import javax.annotation.Nullable;
import org.opensearch.client.transport.Transport;
import org.opensearch.client.transport.TransportOptions;

public abstract class ApiClient<T extends Transport, Self extends ApiClient<T, Self>> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean ignoreUnknownFields() {
@SuppressWarnings("unchecked")
public <T> T attribute(String name) {
if (this.name.equals(name)) {
return (T)this.value;
return (T) this.value;
} else {
return mapper.attribute(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.client.json;

import jakarta.json.stream.JsonParser;

import java.util.function.Function;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.client.json;

import jakarta.json.stream.JsonParser;

import java.util.EnumSet;

public abstract class DelegatingDeserializer<T, U> implements JsonpDeserializer<T> {
Expand Down Expand Up @@ -68,7 +67,7 @@ public T deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event eve
*/
public static JsonpDeserializer<?> unwrap(JsonpDeserializer<?> deserializer) {
while (deserializer instanceof DelegatingDeserializer) {
deserializer = ((DelegatingDeserializer<?,?>) deserializer).unwrap();
deserializer = ((DelegatingDeserializer<?, ?>) deserializer).unwrap();
}
return deserializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonLocation;
import jakarta.json.stream.JsonParser;

import java.math.BigDecimal;
import java.util.Map;
import java.util.stream.Stream;
Expand Down Expand Up @@ -134,4 +133,4 @@ public void skipObject() {
public void close() {
parser.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,20 @@

package org.opensearch.client.json;

import org.opensearch.client.util.TaggedUnion;

import static jakarta.json.stream.JsonParser.Event;

import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParsingException;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

import javax.annotation.Nullable;

import static jakarta.json.stream.JsonParser.Event;
import org.opensearch.client.util.TaggedUnion;

/**
* Utilities for union types whose discriminant is not directly part of the structure, either as an enclosing property name or as
Expand All @@ -71,15 +67,17 @@ public static class Deserializer<Union extends TaggedUnion<?, ?>, Member> {
@Nullable
private final BiFunction<String, JsonData, Union> unKnownUnionCtor;

public Deserializer(Map<String, JsonpDeserializer<? extends Member>> deserializers,
Function<Member, Union> unionCtor) {
public Deserializer(Map<String, JsonpDeserializer<? extends Member>> deserializers, Function<Member, Union> unionCtor) {
this.deserializers = deserializers;
this.unionCtor = unionCtor;
this.unKnownUnionCtor = null;
}

public Deserializer(Map<String, JsonpDeserializer<? extends Member>> deserializers,
Function<Member, Union> unionCtor, BiFunction<String, JsonData, Union> unKnownUnionCtor) {

public Deserializer(
Map<String, JsonpDeserializer<? extends Member>> deserializers,
Function<Member, Union> unionCtor,
BiFunction<String, JsonData, Union> unKnownUnionCtor
) {
this.deserializers = deserializers;
this.unionCtor = unionCtor;
this.unKnownUnionCtor = unKnownUnionCtor;
Expand Down Expand Up @@ -127,9 +125,9 @@ public void deserializeEntry(String key, JsonParser parser, JsonpMapper mapper,
int hashPos = key.indexOf('#');
if (hashPos == -1) {
throw new JsonParsingException(
"Property name '" + key
+ "' is not in the 'type#name' format. Make sure the request has 'typed_keys' set.",
parser.getLocation());
"Property name '" + key + "' is not in the 'type#name' format. Make sure the request has 'typed_keys' set.",
parser.getLocation()
);
}

String type = key.substring(0, hashPos);
Expand All @@ -138,43 +136,44 @@ public void deserializeEntry(String key, JsonParser parser, JsonpMapper mapper,
targetMap.put(name, deserializer.deserialize(type, parser, mapper, parser.next()));
}
}

public static <T extends TaggedUnion<?, ?>> JsonpDeserializer<Map<String, List<T>>> arrayDeserializer(
TypedKeysDeserializer<T> deserializer) {
return JsonpDeserializer.of(
EnumSet.of(Event.START_OBJECT),
(parser, mapper, event) -> {
Map<String, List<T>> result = new HashMap<>();
String key = null;
while ((event = parser.next()) != Event.END_OBJECT) {
JsonpUtils.expectEvent(parser, event, Event.KEY_NAME);
// Split key and type
key = parser.getString();
int hashPos = key.indexOf('#');

String type = key.substring(0, hashPos);
String name = key.substring(hashPos + 1);

List<T> list = new ArrayList<>();
JsonpUtils.expectNextEvent(parser, Event.START_ARRAY);
try {
while ((event = parser.next()) != Event.END_ARRAY) {
list.add(deserializer.deserializer.deserialize(type, parser, mapper, event));
}
} catch (Exception e) {
throw e;
}
result.put(name, list);
}
return result;
});
TypedKeysDeserializer<T> deserializer
) {
return JsonpDeserializer.of(EnumSet.of(Event.START_OBJECT), (parser, mapper, event) -> {
Map<String, List<T>> result = new HashMap<>();
String key = null;
while ((event = parser.next()) != Event.END_OBJECT) {
JsonpUtils.expectEvent(parser, event, Event.KEY_NAME);
// Split key and type
key = parser.getString();
int hashPos = key.indexOf('#');

String type = key.substring(0, hashPos);
String name = key.substring(hashPos + 1);

List<T> list = new ArrayList<>();
JsonpUtils.expectNextEvent(parser, Event.START_ARRAY);
try {
while ((event = parser.next()) != Event.END_ARRAY) {
list.add(deserializer.deserializer.deserialize(type, parser, mapper, event));
}
} catch (Exception e) {
throw e;
}
result.put(name, list);
}
return result;
});
}

/**
* Serialize an externally tagged union using the typed keys encoding.
*/
public static <T extends JsonpSerializable & TaggedUnion<? extends JsonEnum, ?>> void serializeTypedKeys(
Map<String, T> map, JsonGenerator generator, JsonpMapper mapper
Map<String, T> map,
JsonGenerator generator,
JsonpMapper mapper
) {
generator.writeStartObject();
serializeTypedKeysInner(map, generator, mapper);
Expand All @@ -185,9 +184,11 @@ public void deserializeEntry(String key, JsonParser parser, JsonpMapper mapper,
* Serialize an externally tagged union using the typed keys encoding, without the enclosing start/end object.
*/
public static <T extends JsonpSerializable & TaggedUnion<? extends JsonEnum, ?>> void serializeTypedKeysInner(
Map<String, T> map, JsonGenerator generator, JsonpMapper mapper
Map<String, T> map,
JsonGenerator generator,
JsonpMapper mapper
) {
for (Map.Entry<String, T> entry: map.entrySet()) {
for (Map.Entry<String, T> entry : map.entrySet()) {
T value = entry.getValue();
generator.writeKey(value._kind().jsonValue() + "#" + entry.getKey());
value.serialize(generator, mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;

import java.util.EnumSet;

/**
Expand Down Expand Up @@ -71,19 +70,19 @@ public interface JsonData extends JsonpSerializable {
/**
* Converts this object to a target class.
*/
<T> T to(Class<T> clazz, JsonpMapper mapper);
<T> T to(Class<T> clazz, JsonpMapper mapper);

/**
* Converts this object using a deserializer. A mapper must have been provided at creation time.
*
* @throws IllegalStateException if no mapper was provided at creation time.
*/
<T> T deserialize(JsonpDeserializer<T> deserializer);
<T> T deserialize(JsonpDeserializer<T> deserializer);

/**
* Converts this object using a deserializer.
*/
<T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper);
<T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper);

/**
* Creates a raw JSON value from an existing object. A mapper will be needed to convert the result.
Expand All @@ -109,7 +108,5 @@ static JsonData from(JsonParser parser, JsonpMapper mapper) {
return of(parser.getValue(), mapper);
}

JsonpDeserializer<JsonData> _DESERIALIZER = JsonpDeserializer.of(
EnumSet.allOf(JsonParser.Event.class), JsonData::from
);
JsonpDeserializer<JsonData> _DESERIALIZER = JsonpDeserializer.of(EnumSet.allOf(JsonParser.Event.class), JsonData::from);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;

import java.io.StringReader;
import java.io.StringWriter;

Expand Down Expand Up @@ -67,8 +66,9 @@ public JsonValue toJson(JsonpMapper mapper) {
// Provided mapper has precedence over the one that was optionally set at creation time
mapper = mapper != null ? mapper : this.mapper;
if (mapper == null) {
throw new IllegalStateException("Contains a '" + value.getClass().getName() +
"' that cannot be converted to a JsonValue without a mapper");
throw new IllegalStateException(
"Contains a '" + value.getClass().getName() + "' that cannot be converted to a JsonValue without a mapper"
);
}

final JsonParser parser = getParser(mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParsingException;

import javax.annotation.Nullable;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;

/**
* Base interface for enumerations in API types. Members have a JSON representation and also accept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* Indicates that a class has a {@link JsonpDeserializer} as a static field.
*/
@Target({ElementType.TYPE})
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface JsonpDeserializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@

package org.opensearch.client.json;

import org.opensearch.client.util.TriFunction;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParser.Event;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import org.opensearch.client.util.TriFunction;

public interface JsonpDeserializer<V> {

Expand Down Expand Up @@ -98,13 +97,13 @@ default V deserialize(JsonParser parser, JsonpMapper mapper) {
*/
V deserialize(JsonParser parser, JsonpMapper mapper, Event event);

//---------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------

/**
* Creates a deserializer for a class that delegates to the mapper provided to
* {@link #deserialize(JsonParser, JsonpMapper)}.
*/
static <T>JsonpDeserializer<T> of (Class<T> clazz) {
static <T> JsonpDeserializer<T> of(Class<T> clazz) {
return new JsonpDeserializerBase<T>(EnumSet.allOf(JsonParser.Event.class)) {
@Override
public T deserialize(JsonParser parser, JsonpMapper mapper) {
Expand Down Expand Up @@ -145,7 +144,7 @@ static <T> JsonpDeserializer<T> lazy(Supplier<JsonpDeserializer<T>> ctor) {
return new LazyDeserializer<>(ctor);
}

//----- Builtin types
// ----- Builtin types

static <T> JsonpDeserializer<T> fixedValue(T value) {
return new JsonpDeserializerBase<T>(EnumSet.noneOf(Event.class)) {
Expand Down Expand Up @@ -229,7 +228,8 @@ static <T> JsonpDeserializer<Map<String, T>> stringMapDeserializer(JsonpDeserial
}

static <K extends JsonEnum, V> JsonpDeserializer<Map<K, V>> enumMapDeserializer(
JsonpDeserializer<K> keyDeserializer, JsonpDeserializer<V> valueDeserializer
JsonpDeserializer<K> keyDeserializer,
JsonpDeserializer<V> valueDeserializer
) {
return new JsonpDeserializerBase.EnumMapDeserializer<K, V>(keyDeserializer, valueDeserializer);
}
Expand Down
Loading

0 comments on commit 84e6a58

Please sign in to comment.