Source:
public static Map<String,ArrayList<Long>> evaluateExpression(String expression) { Map<String, ArrayList<Long>> cyclePeriods = new HashMap<>(); for (String periodExpression : expression.split(" ")) { String period = periodExpression.split("\\(")[0]; ArrayList<Long> periodIds = new ArrayList<>(); String cycleDays = periodExpression.split("\\(")[1]; if (period.indexOf('-') >= 0) { Long start = Long.valueOf(period.substring(0,1)); Long end = Long.valueOf(period.substring(2,3)); for (long i = start; i <= end; i++) { periodIds.add(i); } } else if (period.indexOf(',') >= 0) { String[] periods = period.split(","); for (String splitPeriod: periods) { if (splitPeriod.length() > 1) { Long start = Long.valueOf(splitPeriod.substring(0,1)); Long end = Long.valueOf(splitPeriod.substring(2,3)); for (long i = start; i <= end; i++) { periodIds.add(i); } } else { periodIds.add(Long.valueOf(splitPeriod)); } } } else { periodIds.add(Long.valueOf(period)); } cycleDays = cycleDays.replace(")", ""); if (cycleDays.indexOf(',') >= 0) { for (String cycle : cycleDays.split(",")) { if (cycle.length() > 1) { PsSection.addDashValues(cycle, periodIds, cyclePeriods); } else { if (null == cyclePeriods.get(cycle)) { ArrayList<Long> listToAdd = new ArrayList<>(); listToAdd.addAll(periodIds); cyclePeriods.put(cycle, listToAdd); } else { cyclePeriods.get(cycle).addAll(periodIds); } } } } else if (cycleDays.indexOf('-') >= 0) { PsSection.addDashValues(cycleDays, periodIds, cyclePeriods); } else { String letter = cycleDays.substring(0,1); if (null == cyclePeriods.get(letter)) { ArrayList<Long> listToAdd = new ArrayList<>(); listToAdd.addAll(periodIds); cyclePeriods.put(letter, listToAdd); } else { cyclePeriods.get(letter).addAll(periodIds); } } } return cyclePeriods; }

Target:
public static Map<String,ArrayList<Long>> evaluateExpression(String expression) { Map<String, ArrayList<Long>> cyclePeriods = new HashMap<>(); for (String periodExpression : expression.split("\\)")) { periodExpression = periodExpression.replace(" ", ""); String period = periodExpression.split("\\(")[0]; ArrayList<Long> periodIds = new ArrayList<>(); String cycleDays = periodExpression.split("\\(")[1]; if (period.indexOf('-') >= 0) { Long start = Long.valueOf(period.substring(0,1)); Long end = Long.valueOf(period.substring(2,3)); for (long i = start; i <= end; i++) { periodIds.add(i); } } else if (period.indexOf(',') >= 0) { String[] periods = period.split(","); for (String splitPeriod: periods) { if (splitPeriod.length() > 1) { Long start = Long.valueOf(splitPeriod.substring(0,1)); Long end = Long.valueOf(splitPeriod.substring(2,3)); for (long i = start; i <= end; i++) { periodIds.add(i); } } else { periodIds.add(Long.valueOf(splitPeriod)); } } } else { periodIds.add(Long.valueOf(period)); } if (cycleDays.indexOf(',') >= 0) { for (String cycle : cycleDays.split(",")) { if (cycle.length() > 1) { PsSection.addDashValues(cycle, periodIds, cyclePeriods); } else { if (null == cyclePeriods.get(cycle)) { ArrayList<Long> listToAdd = new ArrayList<>(); listToAdd.addAll(periodIds); cyclePeriods.put(cycle, listToAdd); } else { cyclePeriods.get(cycle).addAll(periodIds); } } } } else if (cycleDays.indexOf('-') >= 0) { PsSection.addDashValues(cycleDays, periodIds, cyclePeriods); } else { String letter = cycleDays.substring(0,1); if (null == cyclePeriods.get(letter)) { ArrayList<Long> listToAdd = new ArrayList<>(); listToAdd.addAll(periodIds); cyclePeriods.put(letter, listToAdd); } else { cyclePeriods.get(letter).addAll(periodIds); } } } return cyclePeriods; }