Example

package org.springframework.data.domain;

import org.springframework.data.util.ProxyUtils;

/**
 * Support for query by example (QBE). An {@link Example} takes a {@code probe} to define the example. Matching options
 * and type safety can be tuned using {@link ExampleMatcher}.
 *
 * @author Christoph Strobl
 * @author Mark Paluch
 * @author Oliver Gierke
 * @param  the type of the probe.
 * @since 1.12
 */
public interface Example {

    /**
     * Create a new {@link Example} including all non-null properties by default.
     *
     * @param probe must not be {@literal null}.
     * @return
     */
    static  Example of(T probe) {
        return new TypedExample<>(probe, ExampleMatcher.matching());
    }

    /**
     * Create a new {@link Example} using the given {@link ExampleMatcher}.
     *
     * @param probe must not be {@literal null}.
     * @param matcher must not be {@literal null}.
     * @return
     */
    static  Example of(T probe, ExampleMatcher matcher) {
        return new TypedExample<>(probe, matcher);
    }

    /**
     * Get the example used.
     *
     * @return never {@literal null}.
     */
    T getProbe();

    /**
     * Get the {@link ExampleMatcher} used.
     *
     * @return never {@literal null}.
     */
    ExampleMatcher getMatcher();

    /**
     * Get the actual type for the probe used. This is usually the given class, but the original class in case of a
     * CGLIB-generated subclass.
     *
     * @return
     * @see ProxyUtils#getUserClass(Class)
     */
    @SuppressWarnings("unchecked")
    default Class getProbeType() {
        return (Class) ProxyUtils.getUserClass(getProbe().getClass());
    }
}

你可能感兴趣的:(Example)