-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMozillaOSModelBuilder.java
More file actions
83 lines (75 loc) · 2.77 KB
/
MozillaOSModelBuilder.java
File metadata and controls
83 lines (75 loc) · 2.77 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
/**
* Copyright 2011 OpenDDR LLC
* This software is distributed under the terms of the GNU Lesser General Public License.
*
*
* This file is part of OpenDDR Simple APIs.
* OpenDDR Simple APIs is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* OpenDDR Simple APIs 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.openddr.simpleapi.oddr.builder.os;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openddr.simpleapi.oddr.builder.Builder;
import org.openddr.simpleapi.oddr.builder.os.mozilla.*;
import org.openddr.simpleapi.oddr.model.UserAgent;
import org.openddr.simpleapi.oddr.model.os.OperatingSystem;
public class MozillaOSModelBuilder implements Builder {
private Builder[] builders = {
new IOSMozillaSubBuilder(),
new AndroidMozillaSubBuilder(),
new WinPhoneMozillaSubBuilder(),
new BlackBerryMozillaSubBuilder(),
new SymbianMozillaSubBuilder(),
new WinCEMozillaSubBuilder(),
new BadaMozillaSubBuilder(),
new BrewMozillaSubBuilder(),
new WebOSMozillaSubBuilder(),
new LinuxMozillaSubBuilder(),
new MacOSXMozillaSubBuilder(),
new WinNTMozillaSubBuilder()
};
public boolean canBuild(UserAgent userAgent) {
if (userAgent.hasMozillaPattern()) {
return true;
}
return false;
}
public OperatingSystem build(UserAgent userAgent, int confidenceTreshold) {
List<OperatingSystem> founds = new ArrayList<OperatingSystem>();
OperatingSystem found = null;
for (Builder builder : builders) {
if (builder.canBuild(userAgent)) {
OperatingSystem builded = (OperatingSystem) builder.build(userAgent, confidenceTreshold);
if (builded != null) {
founds.add(builded);
if (builded.getConfidence() >= confidenceTreshold) {
found = builded;
break;
}
}
}
}
if (found != null) {
return found;
} else {
if (founds.isEmpty()) {
return null;
}
Collections.sort(founds, Collections.reverseOrder());
return founds.get(0);
}
}
}