-
Notifications
You must be signed in to change notification settings - Fork 3
/
File.java
62 lines (47 loc) · 1.67 KB
/
File.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Copyright 2022 Massimo Santini
This file is part of "Programmazione 2 @ UniMI" teaching material.
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This material is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this file. If not, see <https://www.gnu.org/licenses/>.
*/
/** Classe immutabile che rappresenta un <em>file</em>. */
public class File extends Entry {
/** La dimensione del file. */
// non è pubblico, sebbene immutabile, perché esiste un metodo osservazionale
// (che nelle directory non può essere sostituito da un intero!)
private final int size;
// RI: size > 0
/**
* Costruisce un <em>file</em> dato il suo <em>nome</em> e <em>dimensione</em>.
*
* @param name il nome.
* @param size la dimensione.
* @throws IllegalArgumentException se la dimensione non è positiva, o il nome è {@code null} o
* vuoto.
*/
public File(final String name, final int size) {
super(name);
if (size <= 0) throw new IllegalArgumentException("La dimensione deve essere positiva.");
this.size = size;
}
@Override
public int size() {
return size;
}
@Override
public boolean isDir() {
return false;
}
@Override
public String toString() {
return String.format("%s(%d)", name, size);
}
}