Browse Source

Add requirements list and implement method to expand

master
Chris Smith 15 years ago
parent
commit
3968dd1d3e

+ 2
- 1
src/uk/co/md87/evetool/api/wrappers/CertificateTree.java View File

31
 import uk.co.md87.evetool.api.wrappers.data.CertCategory;
31
 import uk.co.md87.evetool.api.wrappers.data.CertCategory;
32
 import uk.co.md87.evetool.api.wrappers.data.CertClass;
32
 import uk.co.md87.evetool.api.wrappers.data.CertClass;
33
 import uk.co.md87.evetool.api.wrappers.data.CertInfo;
33
 import uk.co.md87.evetool.api.wrappers.data.CertInfo;
34
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
34
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
35
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
35
 
36
 
36
 /**
37
 /**
84
         final int grade = row.getNumericAttribute("grade");
85
         final int grade = row.getNumericAttribute("grade");
85
         final int corp = row.getNumericAttribute("corporationID");
86
         final int corp = row.getNumericAttribute("corporationID");
86
         final String desc = row.getStringAttribute("description");
87
         final String desc = row.getStringAttribute("description");
87
-        final List<SkillRequirement> skillReqs = new ArrayList<SkillRequirement>();
88
+        final RequirementsList skillReqs = new RequirementsList();
88
         final List<Integer> certReqs = new ArrayList<Integer>();
89
         final List<Integer> certReqs = new ArrayList<Integer>();
89
 
90
 
90
         for (ApiElement srow : row.getRowset("requiredSkills")) {
91
         for (ApiElement srow : row.getRowset("requiredSkills")) {

+ 8
- 3
src/uk/co/md87/evetool/api/wrappers/CharacterSheet.java View File

34
 import uk.co.md87.evetool.api.wrappers.data.BasicCloneInfo;
34
 import uk.co.md87.evetool.api.wrappers.data.BasicCloneInfo;
35
 import uk.co.md87.evetool.api.wrappers.data.BasicCorpInfo;
35
 import uk.co.md87.evetool.api.wrappers.data.BasicCorpInfo;
36
 import uk.co.md87.evetool.api.wrappers.data.Implant;
36
 import uk.co.md87.evetool.api.wrappers.data.Implant;
37
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
37
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
38
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
38
 import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
39
 import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
39
 
40
 
244
         return skills;
245
         return skills;
245
     }
246
     }
246
 
247
 
247
-    public boolean hasSkills(final List<SkillRequirement> reqs) {
248
+    public boolean hasSkill(final SkillRequirement req) {
249
+        return skills.containsKey(req.getSkillId()) ||
250
+                skills.get(req.getSkillId()).getLevel() < req.getRequiredLevel();
251
+    }
252
+
253
+    public boolean hasSkills(final RequirementsList reqs) {
248
         for (SkillRequirement req : reqs) {
254
         for (SkillRequirement req : reqs) {
249
-            if (!skills.containsKey(req.getSkillId()) ||
250
-                    skills.get(req.getSkillId()).getLevel() < req.getRequiredLevel()) {
255
+            if (!hasSkill(req)) {
251
                 return false;
256
                 return false;
252
             }
257
             }
253
         }
258
         }

+ 2
- 3
src/uk/co/md87/evetool/api/wrappers/ShipList.java View File

22
 
22
 
23
 package uk.co.md87.evetool.api.wrappers;
23
 package uk.co.md87.evetool.api.wrappers;
24
 
24
 
25
-import java.util.ArrayList;
26
 import java.util.HashMap;
25
 import java.util.HashMap;
27
-import java.util.List;
28
 import java.util.Map;
26
 import java.util.Map;
29
 
27
 
30
 import uk.co.md87.evetool.api.parser.ApiElement;
28
 import uk.co.md87.evetool.api.parser.ApiElement;
31
 import uk.co.md87.evetool.api.wrappers.data.BasicRaceInfo;
29
 import uk.co.md87.evetool.api.wrappers.data.BasicRaceInfo;
32
 import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
30
 import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
31
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
33
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
32
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
34
 import uk.co.md87.evetool.api.wrappers.data.TypeGroup;
33
 import uk.co.md87.evetool.api.wrappers.data.TypeGroup;
35
 
34
 
56
                 final String typeName = ship.getStringAttribute("typeName");
55
                 final String typeName = ship.getStringAttribute("typeName");
57
                 final int graphicID = ship.getNumericAttribute("graphicID");
56
                 final int graphicID = ship.getNumericAttribute("graphicID");
58
                 final int raceID = ship.getNumericAttribute("raceID");
57
                 final int raceID = ship.getNumericAttribute("raceID");
59
-                final List<SkillRequirement> reqs = new ArrayList<SkillRequirement>();
58
+                final RequirementsList reqs = new RequirementsList();
60
                 
59
                 
61
                 final int[][] values = new int[ship.getRowset("attributes").size() / 2][2];
60
                 final int[][] values = new int[ship.getRowset("attributes").size() / 2][2];
62
                 for (ApiElement req : ship.getRowset("attributes")) {
61
                 for (ApiElement req : ship.getRowset("attributes")) {

+ 4
- 3
src/uk/co/md87/evetool/api/wrappers/SkillList.java View File

29
 
29
 
30
 import uk.co.md87.evetool.api.parser.ApiElement;
30
 import uk.co.md87.evetool.api.parser.ApiElement;
31
 import uk.co.md87.evetool.api.wrappers.data.Attribute;
31
 import uk.co.md87.evetool.api.wrappers.data.Attribute;
32
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
32
 import uk.co.md87.evetool.api.wrappers.data.SkillGroup;
33
 import uk.co.md87.evetool.api.wrappers.data.SkillGroup;
33
 import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
34
 import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
34
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
35
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
79
         final int typeId = row.getNumericAttribute("typeID");
80
         final int typeId = row.getNumericAttribute("typeID");
80
         final String desc = row.getChildContent("description");
81
         final String desc = row.getChildContent("description");
81
         final int rank = row.getNumericChildContent("rank");
82
         final int rank = row.getNumericChildContent("rank");
82
-        final List<SkillRequirement> reqs = getReqs(row.getRowset("requiredSkills"));
83
+        final RequirementsList reqs = getReqs(row.getRowset("requiredSkills"));
83
         final Attribute primaryAttribute = Attribute.valueOf(row.getChild("requiredAttributes")
84
         final Attribute primaryAttribute = Attribute.valueOf(row.getChild("requiredAttributes")
84
                 .getChildContent("primaryAttribute").toUpperCase());
85
                 .getChildContent("primaryAttribute").toUpperCase());
85
         final Attribute secondaryAttribute = Attribute.valueOf(row.getChild("requiredAttributes")
86
         final Attribute secondaryAttribute = Attribute.valueOf(row.getChild("requiredAttributes")
90
                 secondaryAttribute, bonuses);
91
                 secondaryAttribute, bonuses);
91
     }
92
     }
92
 
93
 
93
-    protected List<SkillRequirement> getReqs(final List<ApiElement> rowset) {
94
-        final List<SkillRequirement> reqs = new ArrayList<SkillRequirement>();
94
+    protected RequirementsList getReqs(final List<ApiElement> rowset) {
95
+        final RequirementsList reqs = new RequirementsList();
95
 
96
 
96
         for (ApiElement row : rowset) {
97
         for (ApiElement row : rowset) {
97
             reqs.add(new SkillRequirement(row.getNumericAttribute("typeID"),
98
             reqs.add(new SkillRequirement(row.getNumericAttribute("typeID"),

+ 3
- 5
src/uk/co/md87/evetool/api/wrappers/data/BasicShipInfo.java View File

22
 
22
 
23
 package uk.co.md87.evetool.api.wrappers.data;
23
 package uk.co.md87.evetool.api.wrappers.data;
24
 
24
 
25
-import java.util.List;
26
-
27
 /**
25
 /**
28
  *
26
  *
29
  * TODO: Document BasicShipInfo
27
  * TODO: Document BasicShipInfo
32
 public class BasicShipInfo extends BasicType {
30
 public class BasicShipInfo extends BasicType {
33
 
31
 
34
     private final int graphicID;
32
     private final int graphicID;
35
-    private final List<SkillRequirement> requirements;
33
+    private final RequirementsList requirements;
36
 
34
 
37
     public BasicShipInfo(final int id, final String name, final BasicRaceInfo race,
35
     public BasicShipInfo(final int id, final String name, final BasicRaceInfo race,
38
             final TypeGroup group, final int graphicID,
36
             final TypeGroup group, final int graphicID,
39
-            final List<SkillRequirement> requirements) {
37
+            final RequirementsList requirements) {
40
         super(id, name, race, group);
38
         super(id, name, race, group);
41
 
39
 
42
         this.graphicID = graphicID;
40
         this.graphicID = graphicID;
48
     }
46
     }
49
 
47
 
50
 
48
 
51
-    public List<SkillRequirement> getRequirements() {
49
+    public RequirementsList getRequirements() {
52
         return requirements;
50
         return requirements;
53
     }
51
     }
54
 
52
 

+ 4
- 3
src/uk/co/md87/evetool/api/wrappers/data/CertInfo.java View File

23
 package uk.co.md87.evetool.api.wrappers.data;
23
 package uk.co.md87.evetool.api.wrappers.data;
24
 
24
 
25
 import java.util.List;
25
 import java.util.List;
26
+
26
 import uk.co.md87.evetool.ui.listable.Retrievable;
27
 import uk.co.md87.evetool.ui.listable.Retrievable;
27
 
28
 
28
 /**
29
 /**
36
     private final int grade;
37
     private final int grade;
37
     private final int corp;
38
     private final int corp;
38
     private final String desc;
39
     private final String desc;
39
-    private final List<SkillRequirement> skillReqs;
40
+    private final RequirementsList skillReqs;
40
     private final List<Integer> certReqs;
41
     private final List<Integer> certReqs;
41
 
42
 
42
     public CertInfo(final int id, final int grade, final int corp,
43
     public CertInfo(final int id, final int grade, final int corp,
43
-            final String desc, final List<SkillRequirement> skillReqs,
44
+            final String desc, final RequirementsList skillReqs,
44
             final List<Integer> certReqs) {
45
             final List<Integer> certReqs) {
45
         this.id = id;
46
         this.id = id;
46
         this.grade = grade;
47
         this.grade = grade;
74
         return id;
75
         return id;
75
     }
76
     }
76
 
77
 
77
-    public List<SkillRequirement> getSkillReqs() {
78
+    public RequirementsList getSkillReqs() {
78
         return skillReqs;
79
         return skillReqs;
79
     }
80
     }
80
 
81
 

+ 74
- 0
src/uk/co/md87/evetool/api/wrappers/data/RequirementsList.java View File

1
+/*
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.evetool.api.wrappers.data;
24
+
25
+import java.util.ArrayList;
26
+import java.util.HashMap;
27
+import java.util.List;
28
+import java.util.Map;
29
+
30
+import uk.co.md87.evetool.api.wrappers.SkillList;
31
+import uk.co.md87.evetool.ui.listable.Retrievable;
32
+
33
+/**
34
+ *
35
+ * TODO: Document RequirementsList
36
+ * @author chris
37
+ */
38
+public class RequirementsList extends ArrayList<SkillRequirement> {
39
+
40
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 10;
46
+
47
+    public void expandRequirements(final SkillList skillList) {
48
+        final List<SkillRequirement> unprocessed = new ArrayList<SkillRequirement>();
49
+        final Map<Integer, Integer> needed = new HashMap<Integer, Integer>();
50
+        unprocessed.addAll(this);
51
+
52
+        while (!unprocessed.isEmpty()) {
53
+            final SkillRequirement target = unprocessed.remove(0);
54
+
55
+            unprocessed.addAll(skillList.getSkillById(target.getSkillId()).getRequirements());
56
+
57
+            final int level =  Math.max(needed.containsKey(target.getSkillId())
58
+                    ? needed.get(target.getSkillId()) : 0, target.getRequiredLevel());
59
+            needed.put(target.getSkillId(), level);
60
+        }
61
+
62
+        clear();
63
+
64
+        for (Map.Entry<Integer, Integer> entry : needed.entrySet()) {
65
+            add(new SkillRequirement(entry.getKey(), entry.getValue()));
66
+        }
67
+    }
68
+
69
+    @Retrievable(name="total number")
70
+    public int getNumSkills() {
71
+        return size();
72
+    }
73
+
74
+}

+ 8
- 3
src/uk/co/md87/evetool/api/wrappers/data/SkillInfo.java View File

22
 
22
 
23
 package uk.co.md87.evetool.api.wrappers.data;
23
 package uk.co.md87.evetool.api.wrappers.data;
24
 
24
 
25
-import java.util.List;
26
 import java.util.Map;
25
 import java.util.Map;
26
+
27
 import uk.co.md87.evetool.ui.listable.Retrievable;
27
 import uk.co.md87.evetool.ui.listable.Retrievable;
28
 import uk.co.md87.evetool.ui.listable.formatters.NumberFormatter;
28
 import uk.co.md87.evetool.ui.listable.formatters.NumberFormatter;
29
 
29
 
39
     protected final int id;
39
     protected final int id;
40
     protected final String description;
40
     protected final String description;
41
     protected final int rank;
41
     protected final int rank;
42
-    protected final List<SkillRequirement> requirements;
42
+    protected final RequirementsList requirements;
43
     protected final Attribute primaryAttribute;
43
     protected final Attribute primaryAttribute;
44
     protected final Attribute secondaryAttribute;
44
     protected final Attribute secondaryAttribute;
45
     protected final Map<String, String> bonuses;
45
     protected final Map<String, String> bonuses;
46
 
46
 
47
     public SkillInfo(final SkillGroup group, final String name, final int id,
47
     public SkillInfo(final SkillGroup group, final String name, final int id,
48
             final String description, final int rank,
48
             final String description, final int rank,
49
-            final List<SkillRequirement> requirements,
49
+            final RequirementsList requirements,
50
             final Attribute primaryAttribute, final Attribute secondaryAttribute,
50
             final Attribute primaryAttribute, final Attribute secondaryAttribute,
51
             final Map<String, String> bonuses) {
51
             final Map<String, String> bonuses) {
52
         this.group = group;
52
         this.group = group;
97
         return group;
97
         return group;
98
     }
98
     }
99
 
99
 
100
+    @Retrievable(deferred=true,name="Requirements:")
101
+    public RequirementsList getRequirements() {
102
+        return requirements;
103
+    }
104
+
100
     @Override
105
     @Override
101
     public String toString() {
106
     public String toString() {
102
         return "[" + name + " (" + id + ") | " + bonuses + "]";
107
         return "[" + name + " (" + id + ") | " + bonuses + "]";

Loading…
Cancel
Save