io.sphere.sdk.products.CategoryOrderHints Maven / Gradle / Ivy
package io.sphere.sdk.products;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.utils.MapUtils;
import javax.annotation.Nullable;
import java.util.*;
public class CategoryOrderHints extends Base {
@JsonIgnore
private final Map orderHints;
@JsonCreator
private CategoryOrderHints(final Map orderHints) {
this.orderHints = Optional.ofNullable(orderHints)
.map(MapUtils::immutableCopyOf)
.orElseGet(() -> new LinkedHashMap<>());
}
@JsonIgnore
public static CategoryOrderHints of(final String categoryId, final String orderHint) {
final Map entry = Collections.singletonMap(categoryId, orderHint);
return of(entry);
}
@JsonIgnore
public static CategoryOrderHints of(final Map orderHints) {
return new CategoryOrderHints(orderHints);
}
@Nullable
public String get(final String categoryId) {
return orderHints.get(categoryId);
}
@SuppressWarnings("unused")//used by Jackson JSON mapper
@JsonAnySetter
private void set(final String categoryId, final String value) {
orderHints.put(categoryId, value);
}
@JsonAnyGetter//@JsonUnwrap supports not maps, but this construct puts map content on top level
public Map getAsMap() {
return Collections.unmodifiableMap(orderHints);
}
}