commit | author | age
|
786e8c
|
1 |
/* |
U |
2 |
http-base - Extensions to jdk.httpserver |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.httpserver.base; |
|
19 |
|
|
20 |
import java.util.ArrayList; |
|
21 |
import java.util.Iterator; |
|
22 |
import java.util.List; |
|
23 |
|
|
24 |
/** |
|
25 |
* Eine Gruppe aus Ranges |
|
26 |
* |
|
27 |
* @author Ulrich Hilger |
|
28 |
* @version 1, 11.06.2021 |
|
29 |
*/ |
|
30 |
public class RangeGroup { |
|
31 |
private List<Range> ranges; |
|
32 |
private long totalSize; |
|
33 |
|
|
34 |
/** |
|
35 |
* Ein neues Objekt der Klasse RangeGroup erzeugen |
|
36 |
*/ |
|
37 |
public RangeGroup() { |
|
38 |
ranges = new ArrayList(); |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Dieser RangeGroup eine Range hinzufuegen. |
|
43 |
* |
|
44 |
* @param range die Range, die dieser RangeGroup hinzugefuegt werden soll |
|
45 |
*/ |
|
46 |
public void addRange(Range range) { |
|
47 |
ranges.add(range); |
|
48 |
totalSize += range.getEnd() - range.getStart(); |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Die Gesamtgröße dieser RangeGroup ermitteln, also die Summe |
|
53 |
* der Anzahl von Bytes aller ihrer Ranges. |
|
54 |
* |
|
55 |
* @return die Größe dieser RangeGroup in Bytes |
|
56 |
*/ |
|
57 |
public long getSize() { |
|
58 |
return totalSize; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Einen Iterator über die Ranges dieser RangeGroup abrufen |
|
63 |
* |
|
64 |
* @return Iterator über die Ranges dieser RangeGroup |
|
65 |
*/ |
|
66 |
public Iterator<Range> getRanges() { |
|
67 |
return ranges.iterator(); |
|
68 |
} |
|
69 |
} |