/** * Adds range to the list of already existing ranges. Added range must be located after * the last range in this map. If added range is adjacent to the last range in the map, * added range will be concatenated to the last one. * * @param range Range to add. */ public void addRange(GridGgfsFileAffinityRange range) { if (range == null || range.empty()) return; // We cannot add range in the middle of the file. if (ranges == null) { ranges = new ArrayList<>(); ranges.add(range); return; } assert !ranges.isEmpty(); GridGgfsFileAffinityRange last = ranges.get(ranges.size() - 1); // Ensure that range being added is located to the right of last range in list. assert last.greater(range.startOffset()) : "Cannot add range to middle of map [last=" + last + ", range=" + range + ']'; // Try to concat last and new range. GridGgfsFileAffinityRange concat = last.concat(range); // Simply add range to the end of the list if they are not adjacent. if (concat == null) ranges.add(range); else ranges.set(ranges.size() - 1, concat); }
/** * Adds range to the list of already existing ranges. Added range must be located after * the last range in this map. If added range is adjacent to the last range in the map, * added range will be concatenated to the last one. * * @param range Range to add. */ public void addRange(GridGgfsFileAffinityRange range) { if (range == null || range.empty()) return; // We cannot add range in the middle of the file. if (ranges == null) { ranges = new ArrayList<>(); ranges.add(range); return; } assert !ranges.isEmpty(); GridGgfsFileAffinityRange last = ranges.get(ranges.size() - 1); // Ensure that range being added is located to the right of last range in list. assert last.greater(range.startOffset()) : "Cannot add range to middle of map [last=" + last + ", range=" + range + ']'; // Try to concat last and new range. GridGgfsFileAffinityRange concat = last.concat(range); // Simply add range to the end of the list if they are not adjacent. if (concat == null) ranges.add(range); else ranges.set(ranges.size() - 1, concat); }