-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentDB.java
More file actions
42 lines (33 loc) · 1.04 KB
/
Copy pathDocumentDB.java
File metadata and controls
42 lines (33 loc) · 1.04 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
package turing;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentSkipListSet;
import turing.Message.RESULT;
public class DocumentDB {
private ConcurrentSkipListSet<Document> documents = null;
public DocumentDB(){
if (this.documents == null)
this.documents = new ConcurrentSkipListSet<Document>();
}
//crea un documento nel database
public Message.RESULT addDocumentDB(Document d) {
if (d.getNumOfSections() == 0) return RESULT.SEC_ERR;
if (documents.add(d) == true) return RESULT.OP_OK;
else return RESULT.DOC_EXISTENT;
}
public ConcurrentSkipListSet<Document> getDocuments(){
return this.documents;
}
//preleva un documento
public Document getDocument(String doc){
Document document = null;
try { document = this.documents.stream().filter(d1 -> d1.getDocName().equals(doc)).findFirst().get();
} catch (NoSuchElementException e){
return null;
}
return document;
}
public boolean containsDocumentDB(String doc){
if (getDocument(doc) == null) return false;
return true;
}
}