本篇文章給大家分享的是有關dddsample-core中Specification有什么用,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
“專業、務實、高效、創新、把客戶的事當成自己的事”是我們每一個人一直以來堅持追求的企業文化。 創新互聯是您可以信賴的網站建設服務商、專業的互聯網服務提供商! 專注于網站設計、成都網站制作、軟件開發、設計服務業務。我們始終堅持以客戶需求為導向,結合用戶體驗與視覺傳達,提供有針對性的項目解決方案,提供專業性的建議,創新互聯建站將不斷地超越自我,追逐市場,引領市場!
public interface Specification<T> { /** * 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<T> and(Specification<T> 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<T> or(Specification<T> specification); /** * Create a new specification that is the NOT operation of {@code this} specification. * @param specification Specification to NOT. * @return A new specification. */ Specification<T> not(Specification<T> 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 AbstractSpecification<T> implements Specification<T> { /** * {@inheritDoc} */ public abstract boolean isSatisfiedBy(T t); /** * {@inheritDoc} */ public Specification<T> and(final Specification<T> specification) { return new AndSpecification<T>(this, specification); } /** * {@inheritDoc} */ public Specification<T> or(final Specification<T> specification) { return new OrSpecification<T>(this, specification); } /** * {@inheritDoc} */ public Specification<T> not(final Specification<T> specification) { return new NotSpecification<T>(specification); } }
AbstractSpecification聲明實現Specification,它實現了and、or、not方法
public class AndSpecification<T> extends AbstractSpecification<T> { private Specification<T> spec1; private Specification<T> spec2; /** * Create a new AND specification based on two other spec. * * @param spec1 Specification one. * @param spec2 Specification two. */ public AndSpecification(final Specification<T> spec1, final Specification<T> 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 OrSpecification<T> extends AbstractSpecification<T> { private Specification<T> spec1; private Specification<T> spec2; /** * Create a new OR specification based on two other spec. * * @param spec1 Specification one. * @param spec2 Specification two. */ public OrSpecification(final Specification<T> spec1, final Specification<T> 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 NotSpecification<T> extends AbstractSpecification<T> { private Specification<T> spec1; /** * Create a new NOT specification based on another spec. * * @param spec1 Specification instance to not. */ public NotSpecification(final Specification<T> 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有什么用,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創新互聯行業資訊頻道。
名稱欄目:dddsample-core中Specification有什么用
當前URL:http://vcdvsql.cn/article44/pegeee.html
成都網站建設公司_創新互聯,為您提供軟件開發、網站設計公司、自適應網站、虛擬主機、定制網站、靜態網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯