all()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
/*
2
 * This file is part of ArakneLangLoader.
3
 *
4
 * ArakneLangLoader is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * ArakneLangLoader is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with ArakneLangLoader.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2020 Vincent Quatrevieux
18
 */
19
20
package fr.arakne.swflangloader.lang.classes;
21
22
import fr.arakne.swflangloader.loader.AbstractSwfFile;
23
import fr.arakne.swflangloader.loader.SwfFileLoader;
24
import fr.arakne.swflangloader.parser.mapper.MapperHydrator;
25
import fr.arakne.swflangloader.parser.mapper.SwfVariable;
26
27
import java.io.File;
28
import java.io.IOException;
29
import java.net.URL;
30
import java.util.Collection;
31
import java.util.HashMap;
32
import java.util.Map;
33
34
/**
35
 * Store classes data
36
 */
37
final public class ClassesFile extends AbstractSwfFile {
38 1
    final static private MapperHydrator<ClassesFile> HYDRATOR = MapperHydrator.parseAnnotations(ClassesFile.class);
39
40 1
    @SwfVariable("G")
41
    final private Map<Integer, DofusClass> classes = new HashMap<>();
42
43 1
    public ClassesFile(URL file, SwfFileLoader loader) throws IOException, InterruptedException {
44 1
        loader.load(file, this, HYDRATOR);
45 1
        init();
46 1
    }
47
48
    public ClassesFile(URL file) throws IOException, InterruptedException {
49 1
        this(file, new SwfFileLoader());
50 1
    }
51
52
    public ClassesFile(File file) throws IOException, InterruptedException {
53
        this(file.toURI().toURL(), new SwfFileLoader());
54
    }
55
56
    /**
57
     * @return All available classes
58
     */
59
    public Collection<DofusClass> all() {
60 1
        return classes.values();
61
    }
62
63
    /**
64
     * Get a class by its id
65
     *
66
     * @param id The class id
67
     *
68
     * @return The class data
69
     */
70
    public DofusClass get(int id) {
71 1
        return classes.get(id);
72
    }
73
74
    private void init() {
75 1
        classes.forEach((id, dofusClass) -> dofusClass.setId(id));
76 1
    }
77
}
78