123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package com.zkh360.api.brand.util;
- import com.zkh360.api.brand.dto.BrandInfoResult;
- import org.apache.commons.lang.StringUtils;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- public class ConversionNum {
- public static List<BrandInfoResult> getCollectionsResult(List<BrandInfoResult> brands){
- Comparator<BrandInfoResult> brandComparator = new Comparator<BrandInfoResult>() {
- @Override
- public int compare(BrandInfoResult o1, BrandInfoResult o2) {
- if (o1 == o2) {
- return 0;
- }
- String firstWord1 = o1.getFirstWord();
- String firstWord2 = o2.getFirstWord();
- String brandName1 = o1.getBrandName();
- String brandName2 = o2.getBrandName();
- int result = stringCompare(firstWord1, firstWord2);
- if (result == 0) {
- return stringCompare(brandName1, brandName2);
- } else {
- return result;
- }
- }
- };
- Collections.sort(brands, brandComparator);
- return brands;
- }
- public static int stringCompare(String str1, String str2) {
- if (str1 == str2) {
- return 0;
- }
- if (str1 == null && str2 != null) {
- return -1;
- }
- if (str1 != null && str2 == null) {
- return 1;
- }
- return str1.compareTo(str2);
- }
- }
|