当前位置: 首页 > news >正文

海外制作网站WordPress维护模式退出

海外制作网站,WordPress维护模式退出,h5页面制作素材,建设部网站建筑工程质保期一、过滤器模式 概述 ​ 过滤器模式#xff08;Filter Pattern#xff09;或标准模式#xff08;Criteria Pattern#xff09;是一种设计模式#xff0c;这种模式允许开发人员使用不同的标准来过滤一组对象#xff0c;通过逻辑运算以解耦的方式把它们连接起来。这种类型的…一、过滤器模式 概述 ​ 过滤器模式Filter Pattern或标准模式Criteria Pattern是一种设计模式这种模式允许开发人员使用不同的标准来过滤一组对象通过逻辑运算以解耦的方式把它们连接起来。这种类型的设计模式属于结构型模式它结合多个标准来获得单一标准 主要解决在众多数据中根据特定的标准在一组数据中筛选出不同标准的数据 优缺点 优点 将对象的过滤、校验逻辑抽离出来降低系统的复杂度过滤规则可实现重复利用 缺点 性能较低每个过滤器对每一个元素都会进行遍历。如果有n个元素m个过滤器则时间复杂度为O(mn) 1. 各个角色介绍 1.1 过滤器接口Filter 定义了过滤器的基本方法具体的实现还要具体过滤器角色去参与在实际应用中可以扩展该接口以适应不同的过滤条件 1.2 具体命过滤器ConcreteFilter 实现了过滤器接口负责执行具体的过滤操作。对数据进行过滤 1.3 过滤链FilterChain 将多个过滤器按照一定的顺序组合起来形成一个过滤器链依次对数据进行过滤 2. UML图 ​ 首先创建一个 Shape 对象作为过滤的接口 IFilter然后实现该接口创建对应的 CornerFilter、CurveFilter、EdgeFilter具体过滤器。然后创建带有过滤器的过滤链 FilterChain基于各种标准和它们的结合来过滤 Shape 对象的列表 ​ 3. 具体例子和代码 角色分配 Shape形状IFilter过滤器接口 CornerFilter角过滤器实现过滤器接口EdgeFilter边过滤器实现过滤器接口CurveFilter曲线过滤器实现过滤器接口 FilterChain过滤链 3.1 形状 Instruction package com.vinjcent.prototype.filter;import io.swagger.annotations.ApiModelProperty;/*** author vinjcent* description 形状*/ public class Shape {ApiModelProperty(形状名称)private String name;ApiModelProperty(是否有角)private Boolean isCorner;ApiModelProperty(边数)private Integer edges;ApiModelProperty(线构成类型)private String type;public Shape(String name, Boolean isCorner, Integer edges, String type) {this.name name;this.isCorner isCorner;this.edges edges;this.type type;}public String getName() {return name;}public void setName(String name) {this.name name;}public Boolean getCorner() {return isCorner;}public void setCorner(Boolean corner) {isCorner corner;}public Integer getEdges() {return edges;}public void setEdges(Integer edges) {this.edges edges;}public String getType() {return type;}public void setType(String type) {this.type type;} } 3.2 过滤接口及其实现类 IFilter package com.vinjcent.prototype.filter;import java.util.List;/*** author vinjcent* description 过滤接口*/ public interface IFilter {/*** 适配标准形状** param shapes 形状列表* return 适配的形状列表*/ListShape adaptFilter(ListShape shapes); } CornerFilter package com.vinjcent.prototype.filter;import java.util.ArrayList; import java.util.List;/*** author vinjcent* /* description 角过滤器*/ public class CornerFilter implements IFilter {Overridepublic ListShape adaptFilter(ListShape shapes) {// 符合具有角的形状ListShape cornerFilter new ArrayList();for (Shape shape : shapes) {if (shape.getIsCorner()) {cornerFilter.add(shape);}}return cornerFilter;}} EdgeFilter package com.vinjcent.prototype.filter;import java.util.ArrayList; import java.util.List;/*** author vinjcent* /* description 边过滤器*/ public class EdgeFilter implements IFilter {Overridepublic ListShape adaptFilter(ListShape shapes) {// 边数大于0的形状ListShape edgeFilter new ArrayList();for (Shape shape : shapes) {if (shape.getEdges() 0) {edgeFilter.add(shape);}}return edgeFilter;}} CurveFilter package com.vinjcent.prototype.filter;import java.util.ArrayList; import java.util.List;/*** author vinjcent* /* description 曲线过滤器*/ public class CurveFilter implements IFilter {Overridepublic ListShape adaptFilter(ListShape shapes) {// 曲线ListShape curveFilter new ArrayList();for (Shape shape : shapes) {if (shape.getType().toLowerCase().contains(curve)) {curveFilter.add(shape);}}return curveFilter;}} 3.3 过滤链 FilterChain package com.vinjcent.prototype.filter;import com.vinjcent.api.utils.CollectionUtils; import io.swagger.annotations.ApiModelProperty; import lombok.Data;import java.util.ArrayList; import java.util.List;/*** author vinjcent* description 过滤链*/ Data public class FilterChain {ApiModelProperty(过滤器集合)private ListIFilter filters;public FilterChain(ListIFilter filters) {this.filters filters;}public ListShape doFilter(ListShape shapes) {if (CollectionUtils.isEmpty(filters) || CollectionUtils.isEmpty(shapes)) {return new ArrayList();}ListShape afterFilterShapes new ArrayList(shapes);// 执行过滤for (IFilter filter : filters) {afterFilterShapes filter.adaptFilter(afterFilterShapes);}return afterFilterShapes;} } 3.4 测试主函数 package com.vinjcent.prototype.filter;import java.util.ArrayList; import java.util.Arrays; import java.util.List;/*** author vinjcent* 过滤模式*/ public class Main {public static void main(String[] args) {ListShape shapes new ArrayList();shapes.add(new Shape(Circle, false, 0, Curve));shapes.add(new Shape(Triangle, true, 3, Straight));shapes.add(new Shape(Rectangle, true, 4, Straight));shapes.add(new Shape(Square, true, 4, Straight));shapes.add(new Shape(Oval, false, 0, Curve));shapes.add(new Shape(Sector, true, 2, Curve and Straight));CornerFilter cornerFilter new CornerFilter();EdgeFilter edgeFilter new EdgeFilter();CurveFilter curveFilter new CurveFilter();// 具有角、边的形状FilterChain cornerAndEdgeFilterChain new FilterChain(Arrays.asList(cornerFilter, edgeFilter));ListShape cornerAndEdgeShapes cornerAndEdgeFilterChain.doFilter(shapes);System.out.println(具有角、边的形状:);printResult(cornerAndEdgeShapes);// 具有角、曲线的形状FilterChain cornerAndCurveFilterChain new FilterChain(Arrays.asList(cornerFilter, curveFilter));ListShape cornerAndCurveShapes cornerAndCurveFilterChain.doFilter(shapes);System.out.println(\n具有角、曲线的形状:);printResult(cornerAndCurveShapes);// 具有边、曲线的形状FilterChain edgeAndCurveFilterChain new FilterChain(Arrays.asList(edgeFilter, curveFilter));ListShape edgeAndCurveShapes edgeAndCurveFilterChain.doFilter(shapes);System.out.println(\n具有边、曲线的形状:);printResult(edgeAndCurveShapes);}public static void printResult(ListShape shapes) {for (Shape shape : shapes) {System.out.println(Shape{ name shape.getName() \ , isCorner shape.getIsCorner() , edges shape.getEdges() , type shape.getType() \ });}}} 测试结果 4. 使用场景 在某些场合比如要对数据进行过滤不仅仅局限于一个标准的情况下进行分组例如数据查询、日志过滤、请求过滤
http://www.w-s-a.com/news/613048/

相关文章:

  • 网站外部优化的4大重点外贸站外推广
  • 宁波网站建设活动德州乐陵德州seo公司
  • 网站网址相对路径如何设置wordpress怎么加快网站打开速度
  • 有没有能帮人快速网站备案的机构网站建设与制作总结
  • 网站不用了怎么办苏州h5模板建站
  • 网站建设制作定制免费网络短剧
  • 建设部建造师强制注销网站h5响应式网站模板下载
  • 蛋糕网站内容规划建设网站需要多少钱济南兴田德润o厉害吗
  • 企业如何建设网站呢做网站的高手
  • 为什么打开网址都是站长工具开发一款网站需要多少钱
  • 做一个网站app需要多少钱分类信息网站建设计划
  • 怎样下载建设部网站建模培训
  • 北流网站建设制作旅游网站开发目的和目标
  • 网站公司怎么做的网站建设论文二稿
  • 网站建设服务商都有哪些html项目答辩
  • 网站上传到万网主机wordpress视频防盗链
  • 西安建设商城类网站广告设计公司文案
  • 如何建设好高校网站麻辣烫配方教授网站怎么做
  • 宁波网站建设计品牌推广策略分析
  • 网站自建设需要买什么时候开始深圳市建筑市场信息公开平台
  • 平台营销型网站建设小城镇建设的网站文献
  • 燕郊个人做网站小企业网站模板
  • 网站ip需要备案新开河街做网站公司
  • 网站定制设计方案wordpress批量传图片
  • 做外贸兼职的网站设计福州网站开发私人
  • 金华建站模板目前国内有哪些网站做家具回收
  • 个人做网站还是公众号赚钱好部门网站建设和维护
  • 系列图标设计网站推荐建商城网站
  • 中牟建设工程信息网站黑龙江 哈尔滨
  • 网站设计基本结构wap自助建论坛网站