ArrayList<Variable> () { List<Variable> oldVariables = getCurrentVariables(); Set<String> oldVariableNames = ContainerUtil.map2Set(oldVariables, variable -> variable.getName()); Map<String,Variable> newVariableNames = parseVariables(); int oldVariableNumber = 0; for (Map.Entry<String, Variable> entry : newVariableNames.entrySet()) { if(oldVariableNames.contains(entry.getKey())) { Variable oldVariable = null; for(;oldVariableNumber<oldVariables.size(); oldVariableNumber++) { oldVariable = oldVariables.get(oldVariableNumber); if(newVariableNames.get(oldVariable.getName()) != null) { break; } oldVariable = null; } oldVariableNumber++; if(oldVariable != null) { entry.setValue(oldVariable); } } } return new ArrayList<>(newVariableNames.values()); }