org.apache.commons.lang3.StringUtils#difference ( )源码实例Demo

下面列出了org.apache.commons.lang3.StringUtils#difference ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bisq-core   文件: Contract.java
public void printDiff(@Nullable String peersContractAsJson) {
    final String json = Utilities.objectToJson(this);
    String diff = StringUtils.difference(json, peersContractAsJson);
    if (!diff.isEmpty()) {
        log.warn("Diff of both contracts: \n" + diff);
        log.warn("\n\n------------------------------------------------------------\n"
                + "Contract as json\n"
                + json
                + "\n------------------------------------------------------------\n");

        log.warn("\n\n------------------------------------------------------------\n"
                + "Peers contract as json\n"
                + peersContractAsJson
                + "\n------------------------------------------------------------\n");
    } else {
        log.debug("Both contracts are the same");
    }
}
 
源代码2 项目: bbs   文件: PageView.java
/** 上一页URL **/
public String getOnUrl(){
	String uri = "";
	//删除系统虚拟路径
	if(this.getRequestURI()!= null && !"".equals(this.getRequestURI())){
		//删除第一个
		uri = StringUtils.difference(Configuration.getPath()+"/", this.getRequestURI());
	}

	String queryString = this.queryString();
	if(queryString != null && !"".equals(queryString.trim())){
		return uri+"?"+queryString+"&page="+(this.getCurrentpage()-1);
	}
	return uri+"?page="+(this.getCurrentpage()-1);
	
	
}
 
源代码3 项目: bbs   文件: PageView.java
/** 下一页URL **/
public String getNextUrl(){
	String uri = "";
	//删除系统虚拟路径
	if(this.getRequestURI()!= null && !"".equals(this.getRequestURI())){
		//删除第一个
		uri = StringUtils.difference(Configuration.getPath()+"/", this.getRequestURI());

	}
	String queryString = this.queryString();
	if(queryString != null && !"".equals(queryString.trim())){
		return uri+"?"+queryString+"&page="+(this.getCurrentpage()+1);
	}else{
		return uri+"?page="+(this.getCurrentpage()+1);
	}
}
 
源代码4 项目: bisq   文件: Contract.java
public void printDiff(@Nullable String peersContractAsJson) {
    final String json = Utilities.objectToJson(this);
    String diff = StringUtils.difference(json, peersContractAsJson);
    if (!diff.isEmpty()) {
        log.warn("Diff of both contracts: \n" + diff);
        log.warn("\n\n------------------------------------------------------------\n"
                + "Contract as json\n"
                + json
                + "\n------------------------------------------------------------\n");

        log.warn("\n\n------------------------------------------------------------\n"
                + "Peers contract as json\n"
                + peersContractAsJson
                + "\n------------------------------------------------------------\n");
    } else {
        log.debug("Both contracts are the same");
    }
}
 
源代码5 项目: vividus   文件: ElementValidations.java
@Override
public boolean assertIfElementContainsText(WebElement element, String text, boolean isTrue)
{
    if (element != null)
    {
        StringBuilder description = new StringBuilder("Element ");
        description = isTrue ? description.append("contains") : description.append("does not contain");
        description.append(" text");
        Matcher<String> matcher = isTrue ? containsString(text) : not(containsString(text));
        String actualText = element.getText();
        if (actualText.contains(text) != isTrue)
        {
            String pseudoElementContent = webElementActions.getPseudoElementContent(element);
            if (!pseudoElementContent.isEmpty())
            {
                actualText = pseudoElementContent;
            }
            String difference = StringUtils.difference(actualText, text);
            if (!difference.isEmpty())
            {
                description.append(" (Difference in substring: \"").append(difference).append("\")");
            }
        }
        return softAssert.withHighlightedElement(element).assertThat(description.toString(), actualText,
                matcher);
    }
    return false;
}
 
源代码6 项目: bbs   文件: MembershipCardAction.java
/**
 * 会员卡列表
 * @param pageForm
 * @param model
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/control/membershipCard/list") 
public String execute(PageForm pageForm,ModelMap model,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	StringBuffer jpql = new StringBuffer("");
	//存放参数值
	List<Object> params = new ArrayList<Object>();
	
	
	PageView<MembershipCard> pageView = new PageView<MembershipCard>(settingService.findSystemSetting_cache().getBackstagePageNumber(),pageForm.getPage(),10);
	//当前页
	int firstindex = (pageForm.getPage()-1)*pageView.getMaxresult();;	
	//排序
	LinkedHashMap<String,String> orderby = new LinkedHashMap<String,String>();
	
	orderby.put("id", "desc");//根据id字段降序排序
	
	
	//删除第一个and
	String jpql_str = StringUtils.difference(" and", jpql.toString());
	
	//调用分页算法类
	QueryResult<MembershipCard> qr = membershipCardService.getScrollData(MembershipCard.class, firstindex, pageView.getMaxresult(), jpql_str, params.toArray(),orderby);		
	
	pageView.setQueryResult(qr);
	model.addAttribute("pageView", pageView);
	
	return "jsp/membershipCard/membershipCardList";
}
 
源代码7 项目: bbs   文件: MembershipCardAction.java
/**
 * 会员卡订单列表
 * @param pageForm
 * @param model
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/control/membershipCardOrder/list") 
public String queryMembershipCardOrderList(PageForm pageForm,ModelMap model,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	StringBuffer jpql = new StringBuffer("");
	//存放参数值
	List<Object> params = new ArrayList<Object>();
	
	PageView<MembershipCardOrder> pageView = new PageView<MembershipCardOrder>(settingService.findSystemSetting_cache().getBackstagePageNumber(),pageForm.getPage(),10);
	//当前页
	int firstindex = (pageForm.getPage()-1)*pageView.getMaxresult();;	
	//排序
	LinkedHashMap<String,String> orderby = new LinkedHashMap<String,String>();
	
	orderby.put("createDate", "desc");//根据id字段降序排序
	
	
	//删除第一个and
	String jpql_str = StringUtils.difference(" and", jpql.toString());
	
	//调用分页算法类
	QueryResult<MembershipCardOrder> qr = membershipCardService.getScrollData(MembershipCardOrder.class, firstindex, pageView.getMaxresult(), jpql_str, params.toArray(),orderby);		
	
	pageView.setQueryResult(qr);
	model.addAttribute("pageView", pageView);
	
	return "jsp/membershipCard/membershipCardOrderList";
}
 
public static SanitizeInfos isSafe(String content) {

        if (content == null || content.isEmpty()) {
            return new SanitizeInfos(true);
        }

        String toSanitize = htmlRenderer.render(mdParser.parse(content));
        String initialHtml = AllowAllSanitizer.sanitize(toSanitize);
        String sanitizedHtml = HtmlSanitizer.sanitize(toSanitize);

        String[] initialLines = initialHtml.split("\n");
        String[] sanitizedLines = sanitizedHtml.split("\n");


        String diffMessage = null;

        for (int i = 0; i < initialLines.length; i++) {

            if (i < sanitizedLines.length) {
                String difference = StringUtils.difference(sanitizedLines[i], initialLines[i]);

                if (!difference.isEmpty()) {
                    diffMessage = "The content [" + difference + "] is not allowed (~line " + (i + 1)+ ")";
                }
            } else {
                diffMessage = "The content [" + initialLines[i] + "] is not allowed";
            }

            if(diffMessage != null) {
                break;
            }
        }

        if (diffMessage == null) {
            return new SanitizeInfos(true);
        }

        return new SanitizeInfos(false, diffMessage);
    }
 
源代码9 项目: tutorials   文件: StringDiffBenchmarkUnitTest.java
@Benchmark
public int stringUtils() {
    for (int i = 0; i < inputs.size() - 1; i++) {
        StringUtils.difference(inputs.get(i), inputs.get(i + 1));
    }
    return inputs.size();
}
 
源代码10 项目: tutorials   文件: StringUtilsUnitTest.java
@Test
public void givenTwoStrings_whenComparing_thenCorrect() {
    String tutorials = "Baeldung Tutorials";
    String courses = "Baeldung Courses";
    String diff1 = StringUtils.difference(tutorials, courses);
    String diff2 = StringUtils.difference(courses, tutorials);
    assertEquals("Courses", diff1);
    assertEquals("Tutorials", diff2);
}
 
源代码11 项目: bbs   文件: HelpTypeAction.java
@RequestMapping("/control/helpType/list") 
public String execute(PageForm pageForm,ModelMap model,Long parentId,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	StringBuffer jpql = new StringBuffer("");
	//存放参数值
	List<Object> params = new ArrayList<Object>();
	

	//如果所属父类有值
	if(parentId != null && parentId >0L){
			jpql.append(" and o.parentId=?"+ (params.size()+1));//所属父类的ID;(params.size()+1)是为了和下面的条件参数兼容
		params.add(parentId);//设置o.parentId=?2参数
	}else{//如果没有父类
	//	jpql.append(" and o.parent is null");
		jpql.append(" and o.parentId=?"+ (params.size()+1));
		params.add(0L);
	}
	
	PageView<HelpType> pageView = new PageView<HelpType>(settingService.findSystemSetting_cache().getBackstagePageNumber(),pageForm.getPage(),10);
	//当前页
	int firstindex = (pageForm.getPage()-1)*pageView.getMaxresult();;	
	//排序
	LinkedHashMap<String,String> orderby = new LinkedHashMap<String,String>();
	
	orderby.put("sort", "desc");//根据typeid字段降序排序
	
	
	//删除第一个and
	String jpql_str = StringUtils.difference(" and", jpql.toString());
	
	//调用分页算法类
	QueryResult<HelpType> qr = helpTypeService.getScrollData(HelpType.class, firstindex, pageView.getMaxresult(), jpql_str, params.toArray(),orderby);		
	
	pageView.setQueryResult(qr);
	model.addAttribute("pageView", pageView);
	
	
	//分类导航
	if(parentId != null && parentId >0L){
		Map<Long,String> navigation = new LinkedHashMap<Long,String>();
		HelpType helpType = helpTypeService.findById(parentId);
		if(helpType != null){
			List<HelpType> parentHelpTypeList = helpTypeService.findAllParentById(helpType);
			for(HelpType p : parentHelpTypeList){
				navigation.put(p.getId(), p.getName());
			}
			navigation.put(helpType.getId(), helpType.getName());
			model.addAttribute("navigation", navigation);//分类导航
		}
		
	}
	
	return "jsp/help/helpTypeList";
}
 
/**
 * Compare schema summary and determine whether to re-register schema or throw exception.
 * @param localSchemaEntry local schema
 * @param scSchema schema in service center
 * @return true if the two copies of schema are the same, or local schema is re-registered successfully,
 * false if the local schema is re-registered to service center but failed.
 * @throws IllegalStateException The two copies of schema are different and the environment is not modifiable.
 */
private boolean compareAndReRegisterSchema(Entry<String, String> localSchemaEntry, GetSchemaResponse scSchema) {
  String scSchemaSummary = getScSchemaSummary(scSchema);

  if (null == scSchemaSummary) {
    // cannot get scSchemaSummary, which means there is no schema content in sc, register schema directly
    return registerSingleSchema(localSchemaEntry.getKey(), localSchemaEntry.getValue());
  }

  String localSchemaSummary = RegistryUtils.calcSchemaSummary(localSchemaEntry.getValue());
  if (!localSchemaSummary.equals(scSchemaSummary)) {
    if (onlineSchemaIsModifiable()) {
      LOGGER.warn(
          "schema[{}]'s content is changed and the current environment is [{}], so re-register it. It's recommended "
              + " to change servicecomb_description.version after schema change, or restart consumer to"
              + " make changes get notified.",
          localSchemaEntry.getKey(),
          microservice.getEnvironment());
      return registerSingleSchema(localSchemaEntry.getKey(), localSchemaEntry.getValue());
    }

    //if local schema and service center schema is different then print the both schemas and print difference in local schema.
    String scSchemaContent = srClient.getSchema(microservice.getServiceId(), scSchema.getSchemaId());
    String localSchemaContent = localSchemaEntry.getValue();

    LOGGER.warn(
        "service center schema and local schema both are different:\n service center schema:\n[{}\n local schema:\n[{}]",
        scSchemaContent,
        localSchemaContent);
    String diffStringLocal = StringUtils.difference(scSchemaContent, localSchemaContent);
    if (diffStringLocal.equals("")) {
      LOGGER.warn("Some APIs are deleted in local schema which are present in service center schema \n");
    } else {
      LOGGER.warn("The difference in local schema:\n[{}]", diffStringLocal);
    }

    // env is not development, throw an exception and break the init procedure
    throw new IllegalStateException(
        "The schema(id=[" + localSchemaEntry.getKey()
            + "]) content held by this instance and the service center is different. "
            + "You need to increment microservice version before deploying. "
            + "Or you can configure service_description.environment="
            + ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV
            + " to work in development environment and ignore this error");
  }

  // summaries are the same
  return true;
}
 
 同类方法