Source:
public Map<Integer, Integer> checkAndConvertIDRanges(Attribute idRangesAttribute) throws InternalErrorException, WrongAttributeValueException { Map<Integer, Integer> convertedRanges = new HashMap<>(); if(idRangesAttribute == null) throw new InternalErrorException("Can't get value from null attribute!"); Map<String, String> idRanges = (LinkedHashMap) idRangesAttribute.getValue(); if(idRanges == null || idRanges.isEmpty()) return convertedRanges; for(String minimumOfRange: idRanges.keySet()) { if(minimumOfRange == null || minimumOfRange.isEmpty()) throw new WrongAttributeValueException(idRangesAttribute, "Minimum in one of gid ranges is empty!"); String maximumOfRange = idRanges.get(minimumOfRange); if(maximumOfRange == null || maximumOfRange.isEmpty()) throw new WrongAttributeValueException(idRangesAttribute, "Maximum in one of gid ranges is empty!"); Integer minimum; Integer maximum; try { minimum = Integer.valueOf(minimumOfRange); maximum = Integer.valueOf(maximumOfRange); } catch (NumberFormatException ex) { throw new WrongAttributeValueException(idRangesAttribute, "Min or max value of some range is not correct number format."); } if(minimum < 1) throw new WrongAttributeValueException(idRangesAttribute, "Minimum of one of gid ranges is less than 0."); if(minimum>maximum) throw new WrongAttributeValueException(idRangesAttribute, "One of gid ranges is not correct range. Minimum of this range is bigger then it's maximum."); convertedRanges.put(minimum, maximum); } Integer lastMaxValue = 0; for(Integer minValue: convertedRanges.keySet().stream().sorted().collect(Collectors.toList())) { if(minValue <= lastMaxValue) throw new WrongAttributeValueException(idRangesAttribute, "There is an overlap between two gid ranges."); lastMaxValue = convertedRanges.get(minValue); } return convertedRanges; }

Target:
public Map<Integer, Integer> checkAndConvertIDRanges(Attribute idRangesAttribute) throws InternalErrorException, WrongAttributeValueException { Map<Integer, Integer> convertedRanges = new HashMap<>(); if(idRangesAttribute == null) throw new InternalErrorException("Can't get value from null attribute!"); Map<String, String> idRanges = (LinkedHashMap) idRangesAttribute.getValue(); if(idRanges == null || idRanges.isEmpty()) return convertedRanges; for(String minimumOfRange: idRanges.keySet()) { if(minimumOfRange == null || minimumOfRange.isEmpty()) throw new WrongAttributeValueException(idRangesAttribute, "Minimum in one of id ranges is empty!"); String maximumOfRange = idRanges.get(minimumOfRange); if(maximumOfRange == null || maximumOfRange.isEmpty()) throw new WrongAttributeValueException(idRangesAttribute, "Maximum in one of id ranges is empty!"); Integer minimum; Integer maximum; try { minimum = Integer.valueOf(minimumOfRange); maximum = Integer.valueOf(maximumOfRange); } catch (NumberFormatException ex) { throw new WrongAttributeValueException(idRangesAttribute, "Min or max value of some range is not correct number format."); } if(minimum < 1) throw new WrongAttributeValueException(idRangesAttribute, "Minimum of one of id ranges is less than 0."); if(minimum>maximum) throw new WrongAttributeValueException(idRangesAttribute, "One of id ranges is not correct range. Minimum of this range is bigger then it's maximum."); convertedRanges.put(minimum, maximum); } Integer lastMaxValue = 0; for(Integer minValue: convertedRanges.keySet().stream().sorted().collect(Collectors.toList())) { if(minValue <= lastMaxValue) throw new WrongAttributeValueException(idRangesAttribute, "There is an overlap between two id ranges."); lastMaxValue = convertedRanges.get(minValue); } return convertedRanges; }