大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇文章给大家分享的是有关dddsample-core中Specification有什么用,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
“专业、务实、高效、创新、把客户的事当成自己的事”是我们每一个人一直以来坚持追求的企业文化。 创新互联是您可以信赖的网站建设服务商、专业的互联网服务提供商! 专注于网站设计、成都网站制作、软件开发、设计服务业务。我们始终坚持以客户需求为导向,结合用户体验与视觉传达,提供有针对性的项目解决方案,提供专业性的建议,创新互联建站将不断地超越自我,追逐市场,引领市场!
public interface Specification{ /** * Check if {@code t} is satisfied by the specification. * * @param t Object to test. * @return {@code true} if {@code t} satisfies the specification. */ boolean isSatisfiedBy(T t); /** * Create a new specification that is the AND operation of {@code this} specification and another specification. * @param specification Specification to AND. * @return A new specification. */ Specification and(Specification specification); /** * Create a new specification that is the OR operation of {@code this} specification and another specification. * @param specification Specification to OR. * @return A new specification. */ Specification or(Specification specification); /** * Create a new specification that is the NOT operation of {@code this} specification. * @param specification Specification to NOT. * @return A new specification. */ Specification not(Specification specification); }
Specification接口定义了isSatisfiedBy、and、or、not方法
/** * Abstract base implementation of composite {@link Specification} with default * implementations for {@code and}, {@code or} and {@code not}. */ public abstract class AbstractSpecificationimplements Specification { /** * {@inheritDoc} */ public abstract boolean isSatisfiedBy(T t); /** * {@inheritDoc} */ public Specification and(final Specification specification) { return new AndSpecification (this, specification); } /** * {@inheritDoc} */ public Specification or(final Specification specification) { return new OrSpecification (this, specification); } /** * {@inheritDoc} */ public Specification not(final Specification specification) { return new NotSpecification (specification); } }
AbstractSpecification声明实现Specification,它实现了and、or、not方法
public class AndSpecificationextends AbstractSpecification { private Specification spec1; private Specification spec2; /** * Create a new AND specification based on two other spec. * * @param spec1 Specification one. * @param spec2 Specification two. */ public AndSpecification(final Specification spec1, final Specification spec2) { this.spec1 = spec1; this.spec2 = spec2; } /** * {@inheritDoc} */ public boolean isSatisfiedBy(final T t) { return spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t); } }
AndSpecification继承了AbstractSpecification,它定义了spec1、spec2属性,其isSatisfiedBy返回的是spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t)
public class OrSpecificationextends AbstractSpecification { private Specification spec1; private Specification spec2; /** * Create a new OR specification based on two other spec. * * @param spec1 Specification one. * @param spec2 Specification two. */ public OrSpecification(final Specification spec1, final Specification spec2) { this.spec1 = spec1; this.spec2 = spec2; } /** * {@inheritDoc} */ public boolean isSatisfiedBy(final T t) { return spec1.isSatisfiedBy(t) || spec2.isSatisfiedBy(t); } }
OrSpecification继承了AbstractSpecification,它定义了spec1、spec2属性,其isSatisfiedBy返回的是spec1.isSatisfiedBy(t) || spec2.isSatisfiedBy(t)
public class NotSpecificationextends AbstractSpecification { private Specification spec1; /** * Create a new NOT specification based on another spec. * * @param spec1 Specification instance to not. */ public NotSpecification(final Specification spec1) { this.spec1 = spec1; } /** * {@inheritDoc} */ public boolean isSatisfiedBy(final T t) { return !spec1.isSatisfiedBy(t); } }
NotSpecification继承了AbstractSpecification,它定义了spec1属性,其isSatisfiedBy返回的是!spec1.isSatisfiedBy(t)
dddsample-core的Specification接口定义了isSatisfiedBy、and、or、not方法;AndSpecification、OrSpecification、NotSpecification继承了AbstractSpecification,实现了Specification接口。
以上就是dddsample-core中Specification有什么用,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。