blob: 885db34510b90964129db668581c0810d0a04932 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentmodel;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author baldersheim
*/
public class DocumentTypeRepo implements DocumentTypeCollection {
private final Map<Integer, NewDocumentType> typeById = new LinkedHashMap<>();
private final Map<NewDocumentType.Name, NewDocumentType> typeByName = new LinkedHashMap<>();
public final NewDocumentType getDocumentType(String name) {
return typeByName.get(new NewDocumentType.Name(name));
}
public NewDocumentType getDocumentType(NewDocumentType.Name name) {
return typeByName.get(name);
}
public NewDocumentType getDocumentType(int id) {
return typeById.get(id);
}
public Collection<NewDocumentType> getTypes() { return typeById.values(); }
public DocumentTypeRepo add(NewDocumentType type) {
if (typeByName.containsKey(type.getFullName())) {
throw new IllegalArgumentException("Document type " + type + " is already registered");
}
if (typeById.containsKey(type.getFullName().getId())) {
throw new IllegalArgumentException("Document type " + type + " is already registered");
}
typeByName.put(type.getFullName(), type);
typeById.put(type.getFullName().getId(), type);
return this;
}
}
|