
clarifai2.internal.JSONArrayBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Clarifai Java API Client
The newest version!
package clarifai2.internal;
import clarifai2.Func1;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public final class JSONArrayBuilder {
private final JsonArray inner = new JsonArray();
public JSONArrayBuilder() {
this(Collections.emptyList());
}
public JSONArrayBuilder(@NotNull Iterable startWith) {
for (final JsonElement element : startWith) {
add(element);
}
}
@NotNull public JSONArrayBuilder add(@NotNull JsonElement element) {
inner.add(element);
return this;
}
@NotNull public JSONArrayBuilder add(@NotNull JSONArrayBuilder other) {
return add(other.build());
}
@NotNull public JSONArrayBuilder add(@NotNull JSONObjectBuilder json) {
return add(json.build());
}
@NotNull public JSONArrayBuilder add(@NotNull String value) {
inner.add(value);
return this;
}
@NotNull public JSONArrayBuilder add(@NotNull Boolean value) {
inner.add(value);
return this;
}
@NotNull public JSONArrayBuilder add(@NotNull Character value) {
inner.add(value);
return this;
}
@NotNull public JSONArrayBuilder add(@NotNull Number value) {
inner.add(value);
return this;
}
@NotNull
public JSONArrayBuilder addAll(@NotNull Iterable iterable, @NotNull Func1 mapper) {
for (final T element : iterable) {
add(mapper.call(element));
}
return this;
}
@NotNull public JSONArrayBuilder addStrings(@NotNull Iterable values) {
for (final String value : values) {
add(value);
}
return this;
}
@NotNull public JSONArrayBuilder addBooleans(@NotNull Iterable values) {
for (final Boolean value : values) {
add(value);
}
return this;
}
@NotNull public JSONArrayBuilder addCharacters(@NotNull Iterable values) {
for (final Character value : values) {
add(value);
}
return this;
}
@NotNull public JSONArrayBuilder addNumbers(@NotNull Iterable values) {
for (final Number value : values) {
add(value);
}
return this;
}
@NotNull public JsonArray build() {
return inner;
}
@Override public int hashCode() {
return inner.hashCode();
}
@Override public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj instanceof JSONArrayBuilder) {
final JSONArrayBuilder that = (JSONArrayBuilder) obj;
return this == that || this.inner.equals(that.inner);
}
if (obj instanceof JsonArray) {
final JsonArray that = (JsonArray) obj;
return this.inner.equals(that);
}
return false;
}
@Override public String toString() {
return inner.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy