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

什么网站可以卖自己做的东西京东短网址在线生成

什么网站可以卖自己做的东西,京东短网址在线生成,网络运营师,wordpress 安装后梅花备忘录模式是用于保存对象在某个时刻的状态#xff0c;来实现撤销操作。而解释器模式则是将文本按照定义的文法规则解析成对应的命令。 1 备忘录模式 需求#xff1a;保存对象在某个时刻的状态#xff0c;后面可以对该对象实行撤销操作。 1.1 备忘录模式介绍 提供一种状… 备忘录模式是用于保存对象在某个时刻的状态来实现撤销操作。而解释器模式则是将文本按照定义的文法规则解析成对应的命令。 1 备忘录模式 需求保存对象在某个时刻的状态后面可以对该对象实行撤销操作。 1.1 备忘录模式介绍 提供一种状态恢复机制在不破坏封装的前提下捕获对象内部状态并在该对象之外保存这个状态。可以在以后将对象恢复到原先保存的状态。 图 备忘录模式 UML public class MementoPattern {public static void main(String[] args) {String[] colors {red,blue,green,pink,black};Button button new Button();Random random new Random();MementoCareTakerButtonMemento careTaker new MementoCareTaker();for (int i 0; i 10; i) {button.setColor(colors[random.nextInt(colors.length)]);button.setPositionX(random.nextDouble());careTaker.pushMemento(button.createMemento());}button.restoreFromMemento(careTaker.getMemento(2));System.out.println(button);button.restoreFromMemento(careTaker.getMemento(3));System.out.println(button);button.restoreFromMemento(careTaker.getMemento(1));System.out.println(button);}private static class Button {private String color;private Double positionX;public String getColor() {return color;}public void setColor(String color) {this.color color;}public Double getPositionX() {return positionX;}public void setPositionX(Double positionX) {this.positionX positionX;}public ButtonMemento createMemento() {return new ButtonMemento(color,positionX);}public void restoreFromMemento(ButtonMemento memento) {this.color memento.getColor();this.positionX memento.positionX;;}Overridepublic String toString() {return Button{ color color \ , positionX positionX };}}private static class ButtonMemento {private final String color;private final Double positionX;public ButtonMemento(String color, Double positionX) {this.color color;this.positionX positionX;}public String getColor() {return color;}public Double getPositionX() {return positionX;}}private static class MementoCareTakerT {private final StackT stack new Stack();public void pushMemento(T t) {stack.push(t);}public T getMemento(int num) {T t null;while (num-- 0 !stack.isEmpty()) {t stack.pop();}return t;}}} 1.2 优缺点 优点 提供了一种状态恢复机制对象可以方便地回到一个特定的历史步骤状态。 缺点 需要保存不同时刻的对象状态这将耗费许多内存等资源。类的数量增多当对象自带有变动时对应的备忘类也需要修改。 2 解释器模式 需求将文本按照特定的语法规则转换成计算机中特定的命令。 2.1 解释器模式介绍 定义一个语言的文法并建立一个解释器来解释该语言中的句子。这里的“语言”是指使用特定格式和语法的代码。 图 解释器UML 这里的Context 一般用于存储解释器之外的一些全局信息也可以省略这个类。 :: 定义为。 | 或。  ‘{’和‘}’ 组合。 * 出现0或多次。 语言单位 语言构造成分每一条语句所定义的字符串。 终结表达式 组成元素是最基本的语言单位不能在进行分解。 非终结表达式 组成元素仍可以是表达式可进一步分解。 图 文法规则说明 public class InterpreterPattern {/*** 语法规则* value :: a integer* operator :: | - | * | /* expression :: value operator value | complexExpression* complexExpression :: expression operator expression | expression operator (expression)*/public static void main(String[] args) {String[] textArr {14*3,4*53,(34)*23, (324)-(23-8), (2-3)*(242*3), (((12)*(23)))32};for (int i 0; i textArr.length; i) {System.out.print(textArr[i]);System.out.println( new ComplexExpression().interpreter(textArr[i]));}}private static abstract class Expression {abstract int interpreter(String text);protected int compute(int leftNum,int rightNum,char opera) {switch (opera) {case : return leftNum rightNum;case -: return leftNum - rightNum;case *: return leftNum * rightNum;case /: return leftNum / rightNum;}return 0;}}/*** 复杂表达式*/private static class ComplexExpression extends Expression {Overrideint interpreter(String text) { // System.out.println(ComplexExpression: text);int letNum0;int rightNum0;char opera ;Pattern pattern Pattern.compile([\\\\-\\*\\/]);Matcher matcher pattern.matcher(text);if (matcher.find()) {int start matcher.start();opera text.charAt(start);if (text.indexOf(() 0) { // 在操作符前面有括号, 先计算括号的内容int endBracketPos findEndBracketPos(text);letNum new ComplexExpression().interpreter(text.substring(1,endBracketPos));if (endBracketPos text.length() -1 ) {return letNum;}opera text.charAt(endBracketPos1);rightNum new ComplexExpression().interpreter(text.substring(endBracketPos2));} else if ((opera * || opera /) text.charAt(start1) ! () { // 需要先完成左边运算boolean hasNext matcher.find(start 1);if (hasNext) {int pos2 matcher.start();letNum new ComplexExpression().interpreter(text.substring(0,pos2));opera text.charAt(pos2);rightNum new ComplexExpression().interpreter(text.substring(pos21));} else {letNum new TerminalExpression().interpreter(text.substring(0,start));rightNum new ComplexExpression().interpreter(text.substring(start1));}} else {letNum new TerminalExpression().interpreter(text.substring(0,start));rightNum new ComplexExpression().interpreter(text.substring(start1));}return compute(letNum,rightNum,opera);} else { // 终结表达式return new TerminalExpression().interpreter(text);}}private int findEndBracketPos(String text) {int startPos 0,endPos 0;do {endPos text.indexOf(),endPos1);startPos text.indexOf((,startPos1);} while (startPos endPos startPos 0);return endPos;}}/*** 是一个数值 或者 是 (数值) 形式要把text 转换为数值*/private static class TerminalExpression extends Expression {Overrideint interpreter(String text) { // System.out.println(TerminalExpression: text);if (text.indexOf(() 0) {text text.substring(1,text.length() - 1);}return Integer.parseInt(text);}}} 2.2 优缺点 优点 实现文法较为容易。易于改变和扩展文法。增加新的解释表达式较为方便只需增加相关表达式类即可符合开闭原则。 缺点 执行效率较低使用了大量的循环和递归调用调试过程比较麻烦。复杂文法难以维护。如果一种语言包含太多文法规则类的数量将会急剧增加导致系统难以管理和维护。
http://www.hkea.cn/news/14499535/

相关文章:

  • 怎么把做的页面放到网站上北京首都功能优化
  • php网站的优点西安旅游服务网站建设
  • 做什么网站流量大wap网站现在还有什么用
  • dedecms仿站教程建网站的公司深圳
  • 一般什么行业做网站的多河北建筑培训网实名认证
  • 电脑做网站用word做网站如何可以实现窗口切换功能
  • 网站开发工程师的生活形态手机网站设计要求
  • 环保网站 中企动力建设白云网站建设
  • 建站公司人员配置店铺运营思路
  • 网站关键词优化哪一个深圳腾网站建设
  • wordpress分享可见内容seo网站监测
  • 临沂建网站公司该怎么给做网站的提页面需求
  • 怎么做领券网站北京做网站建设的公司哪家好
  • 福清市城乡建设局网站网络购物网站大全
  • 网站开发哪种语言最好中山网站建设模板招商
  • 做片头网站电脑设计培训学校推荐
  • 青海企业网站建设公司深圳企业名录深圳黄页
  • 胶州建设局网站东莞营销型网站建设公司
  • 请描述网站开发的一般流程图做影视网站需要多大硬盘
  • 高端网站建设定制百度统计数据
  • 网站后台管理系统用什么软件做鄂州网站制作
  • 网站开通宣传怎么写asp做网站安全性
  • 潍坊响应式网站建设系统工具
  • 手机网站seo免费软件郑州高端网站定制公司
  • 网站设计的创新点单人网站制作
  • 好看的个人网站设计wordpress加入HTML失败
  • 网站的备案可以管几年wordpress主题摘要字数
  • 做公司网站需注意什么dw软件代码大全
  • z怎么建设视频网站株洲网站建设联系方式
  • 汕头如何建设网站设计电子商务网站建设子项目