io.sphere.sdk.messages.MessageDerivateHint Maven / Gradle / Ivy
package io.sphere.sdk.messages;
import com.fasterxml.jackson.databind.JavaType;
import io.sphere.sdk.json.SphereJsonUtils;
import io.sphere.sdk.messages.queries.MessageQuery;
import io.sphere.sdk.messages.queries.MessageQueryModel;
import io.sphere.sdk.queries.QueryPredicate;
import java.util.function.Supplier;
/**
* TypeReference container used by query to get only messages of a certain type.
* @param the type of the message the type hint is about
* @see MessageQuery#forMessageType(io.sphere.sdk.messages.MessageDerivateHint)
*/
public class MessageDerivateHint {
private final JavaType javaType;
private final Supplier> predicateSupplier;
private MessageDerivateHint(final JavaType javaType, final Supplier> predicateSupplier) {
this.javaType = javaType;
this.predicateSupplier = predicateSupplier;
}
public QueryPredicate predicate() {
return predicateSupplier.get();
}
private static MessageDerivateHint ofSingleMessageType(final String type, final JavaType javaType) {
return new MessageDerivateHint<>(javaType, () -> MessageQueryModel.of().type().is(type));
}
public static MessageDerivateHint ofSingleMessageType(final String type, final Class clazz) {
return ofSingleMessageType(type, SphereJsonUtils.convertToJavaType(clazz));
}
public static MessageDerivateHint ofResourceType(final String resourceId, final Class clazz) {
return new MessageDerivateHint<>(SphereJsonUtils.convertToJavaType(clazz), () -> MessageQueryModel.of().resource().typeId().is(resourceId));
}
public JavaType javaType() {
return javaType;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy