-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocument.java
More file actions
89 lines (66 loc) · 1.98 KB
/
Copy pathDocument.java
File metadata and controls
89 lines (66 loc) · 1.98 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package turing;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicInteger;
import turing.Message.RESULT;
public class Document implements Comparable<Document> {
private String docName;
private String owner;
private ConcurrentSkipListSet<Section> sections;
private ConcurrentSkipListSet<String> autorizedUsers = null;
private AtomicInteger group_port = new AtomicInteger();
private AtomicInteger numEditing = new AtomicInteger();
public Document (String name, String owner, int numOfSections) {
name = name.trim(); //elimino spazi bianchi
owner = owner.trim();
this.docName = name;
this.owner = owner;
this.sections = new ConcurrentSkipListSet<Section>();
this.autorizedUsers = new ConcurrentSkipListSet<String>();
this.numEditing.set(0);
this.group_port.set(0);
for(int i = 0; i<numOfSections; i++){
Section s = new Section(name,i);
this.sections.add(s);
}
}
public String getOwner(){
return this.owner;
}
public AtomicInteger getNumberOfEditing(){
return numEditing;
}
public String getDocName(){
return this.docName;
}
public Section getSection(int i){
if (this.sections.size() <= i) return null;
return this.sections.stream().filter(s -> s.getNumSec() == i).findFirst().get();
}
public ConcurrentSkipListSet<Section> getSections(){
return this.sections;
}
public int getNumOfSections(){
return this.sections.size();
}
public Set<String> getAutorizedUsers(){
return this.autorizedUsers;
}
public Message.RESULT addAutorizedUser(String user){
if (autorizedUsers.add(user)) return RESULT.OP_OK;
else return RESULT.OP_ERR;
}
public boolean removeAutorizedUser(String user){
return this.autorizedUsers.remove(user);
}
public AtomicInteger getGroupPort(){
return this.group_port;
}
public void setGroupPort(int port){
this.group_port.set(port);
}
@Override
public int compareTo(Document d) {
return this.docName.compareTo(d.getDocName());
}
}