Java ListIterator Usage makeSortFieldFallbackExpr(List fieldNames)

Here you can find the source of makeSortFieldFallbackExpr(List fieldNames)

Description

make Sort Field Fallback Expr

License

Apache License

Declaration

public static String makeSortFieldFallbackExpr(List<String> fieldNames) 

Method Source Code

//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(")");
    }
}

Related

  1. iteratorBinarySearchGet(ListIterator i, int index)
  2. lastIndexOf(List list, T element)
  3. listEquals(List left, List right)
  4. listHasIdentContent(List list_1, List list_2)
  5. listToStringArray(java.util.List list)
  6. normalizeVersion(String version, int length)
  7. numberToDigits(int num)
  8. overlap(List> lists, int before, int after)
  9. parsePath(String sPath)