Java Code Examples for org.apache.commons.lang3.StringUtils#difference()

The following examples show how to use org.apache.commons.lang3.StringUtils#difference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Contract.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
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");
    }
}
 
Example 2
Source File: PageView.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
/** 上一页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);
	
	
}
 
Example 3
Source File: PageView.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
/** 下一页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);
	}
}
 
Example 4
Source File: Contract.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
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");
    }
}
 
Example 5
Source File: ElementValidations.java    From vividus with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: MembershipCardAction.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 会员卡列表
 * @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";
}
 
Example 7
Source File: MembershipCardAction.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 会员卡订单列表
 * @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";
}
 
Example 8
Source File: HtmlSanitizer.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example 9
Source File: StringDiffBenchmarkUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@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();
}
 
Example 10
Source File: StringUtilsUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@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);
}
 
Example 11
Source File: HelpTypeAction.java    From bbs with GNU Affero General Public License v3.0 4 votes vote down vote up
@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";
}
 
Example 12
Source File: MicroserviceRegisterTask.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}