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

网站开发如何搭建框架公路建设市场信用信息系统网站

网站开发如何搭建框架,公路建设市场信用信息系统网站,设计之家app,汕头网页网站制作常见的问题是检测并显示两个文本#xff08;尤其是几百行或几千行#xff09;的差异。 使用纯java.lang.String类方法可能是一种解决方案#xff0c;但是对于此类操作最重要的问题是#xff0c;“性能”将不能令人满意。 我们需要一种有效的解决方案#xff0c;其可能具有… 常见的问题是检测并显示两个文本尤其是几百行或几千行的差异。 使用纯java.lang.String类方法可能是一种解决方案但是对于此类操作最重要的问题是“性能”将不能令人满意。 我们需要一种有效的解决方案其可能具有以下观点 文字差异工具示例 该问题包含两个部分 检测两个文本的差异为了检测差异在此解决方案中使用了一种有效的LCS最长公共子序列动态算法 。 该解决方案具有Otext1WordCount * text2WordCount复杂度并在下面被编码为“ longestCommonSubsequence”方法。 可视化差异可视化使用基于HTML标记的方法该方法将text2的新单词标记为绿色将text1的旧单词标记为红色。 该解决方案具有OchangedWordsCount *text1WordCount text2WordCount复杂度并在下面被编码为“ markTextDifferences”方法。 注意1为简单起见“ normalizeText”方法用于删除\ n\ t和多个空格字符。 注意2此类创建为Vaadin组件。 但是“ longestCommonSubsequence”是纯通用的“ markTextDifferences”方法是基于HTML的可视组件的通用因此它们也可以用于不同的框架。 import java.util.ArrayList; import com.vaadin.ui.CustomComponent; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; import com.vaadin.ui.VerticalLayout;/** * Text comparison component which marks differences of two texts with colors. * * author cb */ public class TextCompareComponent extends CustomComponent {private Layout mainLayout new VerticalLayout();private ArrayListString longestCommonSubsequenceList;private static final String INSERT_COLOR #99FFCC;private static final String DELETE_COLOR #CB6D6D;public TextCompareComponent(String text1, String text2) {text1 normalizeText(text1);text2 normalizeText(text2);this.longestCommonSubsequenceList longestCommonSubsequence(text1, text2);String result markTextDifferences(text1, text2, longestCommonSubsequenceList, INSERT_COLOR, DELETE_COLOR);Label label new Label(result, Label.CONTENT_XHTML);mainLayout.addComponent(label);setCompositionRoot(mainLayout);}/*** Finds a list of longest common subsequences (lcs) of given two texts.* * param text1* param text2* return - longest common subsequence list*/private ArrayListString longestCommonSubsequence(String text1,String text2){String[] text1Words text1.split( );String[] text2Words text2.split( );int text1WordCount text1Words.length;int text2WordCount text2Words.length;int[][] solutionMatrix new int[text1WordCount 1][text2WordCount 1];for (int i text1WordCount - 1; i 0; i--) {for (int j text2WordCount - 1; j 0; j--) {if (text1Words[i].equals(text2Words[j])){solutionMatrix[i][j] solutionMatrix[i 1][j 1] 1;}else {solutionMatrix[i][j] Math.max(solutionMatrix[i 1][j],solutionMatrix[i][j 1]);}}}int i 0, j 0;ArrayListString lcsResultList new ArrayListString();while (i text1WordCount j text2WordCount) {if (text1Words[i].equals(text2Words[j])) {lcsResultList.add(text2Words[j]);i;j;} else if (solutionMatrix[i 1][j] solutionMatrix[i][j 1]) {i;}else {j;}}return lcsResultList;}/*** Normalizes given string by deleting \n, \t and extra spaces.* * param text - initial string* return - normalized string*/private String normalizeText(String text) {text text.trim();text text.replace(\n, );text text.replace(\t, );while (text.contains( )) {text text.replace( , );}return text;}/*** Returns colored inserted/deleted text representation of given two texts.* Uses longestCommonSubsequenceList to determine colored sections.** param text1* param text2* param lcsList* param insertColor* param deleteColor* return - colored result text*/private String markTextDifferences(String text1, String text2,ArrayListString lcsList, String insertColor, String deleteColor) {StringBuffer stringBuffer new StringBuffer();if (text1 ! null lcsList ! null) {String[] text1Words text1.split( );String[] text2Words text2.split( );int i 0, j 0, word1LastIndex 0, word2LastIndex 0;for (int k 0; k lcsList.size(); k) {for (i word1LastIndex, j word2LastIndex;i text1Words.length j text2Words.length;) {if (text1Words[i].equals(lcsList.get(k)) text2Words[j].equals(lcsList.get(k))) {stringBuffer.append(SPAN lcsList.get(k) /SPAN);word1LastIndex i 1;word2LastIndex j 1;i text1Words.length;j text2Words.length;}else if (!text1Words[i].equals(lcsList.get(k))) {for (; i text1Words.length !text1Words[i].equals(lcsList.get(k)); i) {stringBuffer.append(SPAN styleBACKGROUND-COLOR: deleteColor text1Words[i] /SPAN);}} else if (!text2Words[j].equals(lcsList.get(k))) {for (; j text2Words.length !text2Words[j].equals(lcsList.get(k)), j) {stringBuffer.append(SPAN styleBACKGROUND-COLOR: insertColor text2Words[j] /SPAN);}}}}for (; word1LastIndex text1Words.length; word1LastIndex) {stringBuffer.append(SPAN styleBACKGROUND-COLOR: deleteColor text1Words[word1LastIndex] /SPAN);}for (; word2LastIndex text2Words.length; word2LastIndex) {stringBuffer.append(SPAN styleBACKGROUND-COLOR: insertColor text2Words[word2LastIndex] /SPAN);}}return stringBuffer.toString();} } 参考我们的JCG合作伙伴 Cagdas Basaraner在CodeBuild博客上使用LCS方法实现了通用文本比较工具 。 翻译自: https://www.javacodegeeks.com/2012/05/generic-text-comparison-tool-with-lcs.html
http://www.pierceye.com/news/306791/

相关文章:

  • 苏州专业高端网站建设机构建网站公司下载快手
  • 中堂仿做网站个人网站设计论文道客巴巴
  • 怎么用ps做网站效果图24什么网站建设
  • 网站开发技术有网站建设方案 pdf
  • 网站建设教程浩森宇特福州医院网站建设公司
  • 怎样在网站上做超链接网站商城是用什么框架做的
  • 网站建设增城wordpress新文章类型
  • 广州市招投标中心官网上海网站关键词优化
  • 很多网站开发没有框架如何制作的长沙旅游景点大全排名
  • 云南网站推广的目的做动画的网站有哪些
  • 网站建设公司在哪里找资源模拟建设网站
  • 如何盗用网站模板哈尔滨公告
  • 管理咨询网站焦作专业做网站公司哪家好
  • 在国内做跨境电商怎么上外国网站网站不收录
  • 网站介绍ppt怎么做屏蔽网站ip
  • it公论 是建立在什么网站wordpress搬迁数据库连接失败
  • 南县建设局网站营销型网站开发流程包括
  • 有关应用网站申请免费网站空间
  • 二手书交易网站开发现状营销型网站建设推荐乐云seo
  • 山西网站建设怎么样seo优化网站多少钱
  • 网站建设设计模板磁力链最佳的搜索引擎
  • 单位外部网站建设价格哪些网站可以做视频直播
  • 广州黄埔网站建设公司国外做调灵风暴的网站
  • 珠海附近交友平台软件广州网站优化推广方案
  • cgi做网站如何将网站加入百度图 推广
  • 小贷做网站深圳手机app软件开发
  • 上海平台网站建设费用页面模板不存在怎么办
  • 西安网站排名公司上海工商网查询官网
  • 网站建设协调机制建网站 可以看到访客吗
  • 学生做网站的工作室南和住房和城乡建设局网站