Here you can find the source of makeSortFieldFallbackExpr(List
public static String makeSortFieldFallbackExpr(List<String> fieldNames)
//package com.java2s; //License from project: Apache License import java.util.Arrays; import java.util.List; import java.util.ListIterator; public class Main { public static String makeSortFieldFallbackExpr(List<String> fieldNames) { if (fieldNames.size() == 0) return null; ListIterator<String> it = fieldNames.listIterator(fieldNames.size()); String expr = it.previous(); while (it.hasPrevious()) { String fieldName = it.previous(); expr = makeIfExistsExpr(fieldName, fieldName, expr); }/* www .j a va2 s .c o m*/ return expr; } public static String makeSortFieldFallbackExpr(String... fieldNames) { return makeSortFieldFallbackExpr(Arrays.asList(fieldNames)); } public static String makeIfExistsExpr(String existsExpr, String trueExpr, String falseExpr) { StringBuilder sb = new StringBuilder(); appendIfExistsExpr(sb, existsExpr, trueExpr, falseExpr); return sb.toString(); } public static void appendIfExistsExpr(StringBuilder sb, String existsExpr, String trueExpr, String falseExpr) { sb.append("if(exists("); sb.append(existsExpr); sb.append("),"); sb.append(trueExpr); sb.append(","); sb.append(falseExpr); sb.append(")"); } }