Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; public class Main { public static String assembleSignString(Map<String, Object> paramValueMap, List<String> ignoreParamNameList, String secret, boolean isHeadSecret) { List<String> filteredAndSortedParamNames = filterAndSortedParamNames(paramValueMap, ignoreParamNameList); StringBuilder assembledString = new StringBuilder(); if (isHeadSecret) { assembledString.append(secret); } for (String paramName : filteredAndSortedParamNames) { Object paramValue = paramValueMap.get(paramName); if (paramValue != null) { assembledString.append(paramName).append(paramValue); } } assembledString.append(secret); return assembledString.toString(); } private static List<String> filterAndSortedParamNames(Map<String, Object> paramValueMap, List<String> ignoreParamNameList) { List<String> filteredParamNames = filterParamNames(paramValueMap, ignoreParamNameList); Collections.sort(filteredParamNames); return filteredParamNames; } private static List<String> filterParamNames(Map<String, Object> paramValueMap, List<String> ignoreParamNameList) { List<String> filteredParamNames = new ArrayList<>(paramValueMap.size()); filteredParamNames.addAll(paramValueMap.keySet()); if (ignoreParamNameList != null && ignoreParamNameList.size() > 0) { for (String ignoreParamName : ignoreParamNameList) { filteredParamNames.remove(ignoreParamName); } } return filteredParamNames; } }