Browse Source

Work on ship list

master
Chris Smith 15 years ago
parent
commit
d84ac48836

+ 1
- 1
src/uk/co/md87/evetool/Main.java View File

@@ -58,7 +58,7 @@ public class Main {
58 58
         initTables();
59 59
 
60 60
         final AccountManager manager = new AccountManager(ApiFactory.getConnection());
61
-        
61
+
62 62
         new MainWindow(manager, new ApiFactory()).setVisible(true);
63 63
     }
64 64
 

+ 12
- 0
src/uk/co/md87/evetool/api/EveApi.java View File

@@ -38,6 +38,7 @@ import uk.co.md87.evetool.api.wrappers.CertificateTree;
38 38
 import uk.co.md87.evetool.api.wrappers.CharacterList;
39 39
 import uk.co.md87.evetool.api.wrappers.CharacterSheet;
40 40
 import uk.co.md87.evetool.api.wrappers.MarketOrders;
41
+import uk.co.md87.evetool.api.wrappers.ShipList;
41 42
 import uk.co.md87.evetool.api.wrappers.SkillInTraining;
42 43
 import uk.co.md87.evetool.api.wrappers.SkillList;
43 44
 
@@ -179,6 +180,17 @@ public class EveApi implements Cloneable {
179 180
         return getResponse("/eve/CertificateTree.xml.aspx", CertificateTree.class, false, false);
180 181
     }
181 182
 
183
+    /**
184
+     * Retrieves a list of ships in EVE.
185
+     * Does not require an API key.
186
+     *
187
+     * @return A list of ships in EVE
188
+     */
189
+    public ApiResponse<ShipList> getShipList() {
190
+        return getResponse("http://evetool.md87.co.uk/api/types.php?category=6"
191
+                + "&published&attributes=requiredSkill%&groups", ShipList.class, false, false);
192
+    }
193
+
182 194
     /**
183 195
      * Utility method to send a request to the API and manufacture the
184 196
      * appropaite response objects.

+ 1
- 1
src/uk/co/md87/evetool/api/db/pagecache.sql View File

@@ -1,6 +1,6 @@
1 1
 CREATE TABLE PageCache (
2 2
     pc_id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
3
-    pc_method VARCHAR(50),
3
+    pc_method VARCHAR(512),
4 4
     pc_args VARCHAR(512),
5 5
     pc_cachedat TIMESTAMP,
6 6
     pc_cacheduntil TIMESTAMP,

+ 63
- 0
src/uk/co/md87/evetool/api/wrappers/ShipList.java View File

@@ -22,16 +22,79 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers;
24 24
 
25
+import java.util.ArrayList;
26
+import java.util.HashMap;
27
+import java.util.List;
28
+import java.util.Map;
29
+
25 30
 import uk.co.md87.evetool.api.parser.ApiElement;
31
+import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
32
+import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
33
+import uk.co.md87.evetool.api.wrappers.data.TypeGroup;
26 34
 
27 35
 /**
28 36
  *
37
+ * TODO: Document ShipList
29 38
  * @author chris
30 39
  */
31 40
 public class ShipList {
32 41
 
42
+    private final Map<Integer, TypeGroup> groups = new HashMap<Integer, TypeGroup>();
43
+    private final Map<Integer, BasicShipInfo> ships = new HashMap<Integer, BasicShipInfo>();
44
+
33 45
     public ShipList(final ApiElement resultElement) {
46
+        for (ApiElement grouprow : resultElement.getRowset("groups")) {
47
+            final int groupID = grouprow.getNumericAttribute("groupID");
48
+            final String groupName = grouprow.getStringAttribute("groupName");
49
+
50
+            final TypeGroup group = new TypeGroup(groupID, groupName);
51
+            groups.put(groupID, group);
52
+
53
+            for (ApiElement ship : grouprow.getRowset("types")) {
54
+                final int typeID = ship.getNumericAttribute("typeID");
55
+                final String typeName = ship.getStringAttribute("typeName");
56
+                final int graphicID = ship.getNumericAttribute("graphicID");
57
+                final List<SkillRequirement> reqs = new ArrayList<SkillRequirement>();
58
+                
59
+                final int[][] values = new int[ship.getRowset("attributes").size()][2];
60
+                for (ApiElement req : ship.getRowset("attributes")) {
61
+                    String atName = req.getStringAttribute("attributeName").substring(13);
62
+
63
+                    int index = 0;
64
+
65
+                    if (atName.endsWith("Level")) {
66
+                        index = 1;
67
+                        
68
+                        atName = atName.substring(0, atName.length() - 5);
69
+                    }
70
+
71
+                    int number = Integer.parseInt(atName);
72
+                    values[number][index] = req.getNumericAttribute("value");
73
+                }
74
+
75
+                for (int[] value : values) {
76
+                    reqs.add(new SkillRequirement(value[0], value[1]));
77
+                }
78
+
79
+                final BasicShipInfo info = new BasicShipInfo(typeID, typeName,
80
+                        group, graphicID, reqs);
81
+                group.add(info);
82
+                ships.put(typeID, info);
83
+            }
84
+        }
85
+    }
86
+
87
+    public Map<Integer, TypeGroup> getGroups() {
88
+        return groups;
89
+    }
90
+
91
+    public Map<Integer, BasicShipInfo> getShips() {
92
+        return ships;
93
+    }
34 94
 
95
+    @Override
96
+    public String toString() {
97
+        return groups.toString();
35 98
     }
36 99
 
37 100
 }

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

@@ -34,9 +34,9 @@ public class BasicShipInfo extends BasicType {
34 34
     private final int graphicID;
35 35
     private final List<SkillRequirement> requirements;
36 36
 
37
-    public BasicShipInfo(final int id, final String name, final int graphicID,
38
-            final List<SkillRequirement> requirements) {
39
-        super(id, name);
37
+    public BasicShipInfo(final int id, final String name, final TypeGroup group,
38
+            final int graphicID, final List<SkillRequirement> requirements) {
39
+        super(id, name, group);
40 40
 
41 41
         this.graphicID = graphicID;
42 42
         this.requirements = requirements;

+ 9
- 1
src/uk/co/md87/evetool/api/wrappers/data/BasicType.java View File

@@ -35,9 +35,17 @@ public class BasicType {
35 35
 
36 36
     private final String name;
37 37
 
38
-    public BasicType(final int id, final String name) {
38
+    private final TypeGroup group;
39
+
40
+    public BasicType(final int id, final String name, final TypeGroup group) {
39 41
         this.id = id;
40 42
         this.name = name;
43
+        this.group = group;
44
+    }
45
+
46
+    @Retrievable(deferred=true,name="group")
47
+    public TypeGroup getGroup() {
48
+        return group;
41 49
     }
42 50
 
43 51
     @Retrievable

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

@@ -0,0 +1,60 @@
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 uk.co.md87.evetool.ui.listable.Retrievable;
27
+
28
+/**
29
+ *
30
+ * TODO: Document TypeGroup
31
+ * @author chris
32
+ */
33
+public class TypeGroup extends ArrayList<BasicType> {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 10;
41
+
42
+    private final int id;
43
+    private final String name;
44
+
45
+    public TypeGroup(final int id, final String name) {
46
+        this.id = id;
47
+        this.name = name;
48
+    }
49
+
50
+    @Retrievable
51
+    public int getId() {
52
+        return id;
53
+    }
54
+
55
+    @Retrievable
56
+    public String getName() {
57
+        return name;
58
+    }
59
+
60
+}

Loading…
Cancel
Save