/** * Find parameter position and the array index * * @param searchKey String * @param parameters ArrayList<Param> * @return ArrayList */ @SafeVarargs static ArrayList<int[]> findParameterPosition(String searchKey, ArrayList<Param>... parameters) { ArrayList<int[]> indexes = new ArrayList<>(); int indexValue = 0; int idArray = 0; for (ArrayList<Param> array : parameters) { for (Param p : array) { if (p.getKey().equals(searchKey)) { indexes.add(new int[] {idArray, indexValue}); } indexValue++; } idArray++; indexValue = 0; } return indexes; }
/** * Return a appended String * * @param key String * @param volatileParams ArrayList<Param> * @param persistentParams ArrayList<Param> * @return String */ static String appendParameterValues( String key, ArrayList<Param> volatileParams, ArrayList<Param> persistentParams) { ArrayList<int[]> indexPositions = Tool.findParameterPosition(key, volatileParams, persistentParams); boolean isFirst = true; String result = ""; for (int[] index : indexPositions) { Param param = index[0] == 0 ? volatileParams.get(index[1]) : persistentParams.get(index[1]); if (isFirst) { result = param.getValue().execute(); isFirst = false; } else if (param.getOptions() != null) { result += param.getOptions().getSeparator() + param.getValue().execute(); } else { result += "," + param.getValue().execute(); } } return result; }