Browse Source

RaceList implementation and updating

master
Chris Smith 15 years ago
parent
commit
ce8a959145

+ 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.RaceList;
41 42
 import uk.co.md87.evetool.api.wrappers.ShipList;
42 43
 import uk.co.md87.evetool.api.wrappers.SkillInTraining;
43 44
 import uk.co.md87.evetool.api.wrappers.SkillList;
@@ -191,6 +192,17 @@ public class EveApi implements Cloneable {
191 192
                 + "&published&attributes=requiredSkill%&groups", ShipList.class, false, false);
192 193
     }
193 194
 
195
+    /**
196
+     * Retrieves a list of races in EVE.
197
+     * Does not require an API key.
198
+     *
199
+     * @return A list of races in EVE
200
+     */
201
+    public ApiResponse<RaceList> getRaceList() {
202
+        return getResponse("http://evetool.md87.co.uk/api/races.php",
203
+                RaceList.class, false, false);
204
+    }
205
+
194 206
     /**
195 207
      * Utility method to send a request to the API and manufacture the
196 208
      * appropaite response objects.

+ 56
- 0
src/uk/co/md87/evetool/api/wrappers/RaceList.java View File

@@ -0,0 +1,56 @@
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;
24
+
25
+import java.util.HashMap;
26
+
27
+import uk.co.md87.evetool.api.parser.ApiElement;
28
+import uk.co.md87.evetool.api.wrappers.data.BasicRaceInfo;
29
+
30
+/**
31
+ *
32
+ * TODO: Document RaceList
33
+ * @author chris
34
+ */
35
+public class RaceList extends HashMap<Integer, String> {
36
+
37
+    /**
38
+     * A version number for this class. It should be changed whenever the class
39
+     * structure is changed (or anything else that would prevent serialized
40
+     * objects being unserialized with the new class).
41
+     */
42
+    private static final long serialVersionUID = 10;
43
+
44
+    public RaceList(final ApiElement resultElement) {
45
+        for (ApiElement race : resultElement.getRowset("races")) {
46
+            put(race.getNumericAttribute("raceID"), race.getStringAttribute("raceName"));
47
+        }
48
+    }
49
+
50
+    public void updateRaceNames() {
51
+        for (int id : keySet()) {
52
+            BasicRaceInfo.forID(id).setName(get(id));
53
+        }
54
+    }
55
+
56
+}

+ 24
- 2
src/uk/co/md87/evetool/api/wrappers/data/BasicRaceInfo.java View File

@@ -22,19 +22,24 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25
+import java.util.HashMap;
26
+import java.util.Map;
25 27
 import uk.co.md87.evetool.ui.listable.Retrievable;
26 28
 
27 29
 /**
28 30
  *
29 31
  * TODO: Document BasicRaceInfo
30
- * TODO: Add ability to resolve race
31 32
  * @author chris
32 33
  */
33 34
 public class BasicRaceInfo {
34 35
 
36
+    private static final Map<Integer, BasicRaceInfo> instances
37
+            = new HashMap<Integer, BasicRaceInfo>();
38
+
35 39
     private final int id;
40
+    private String name;
36 41
 
37
-    public BasicRaceInfo(final int id) {
42
+    private BasicRaceInfo(final int id) {
38 43
         this.id = id;
39 44
     }
40 45
 
@@ -43,4 +48,21 @@ public class BasicRaceInfo {
43 48
         return id;
44 49
     }
45 50
 
51
+    @Retrievable
52
+    public String getName() {
53
+        return name;
54
+    }
55
+
56
+    public void setName(final String name) {
57
+        this.name = name;
58
+    }
59
+
60
+    public synchronized static BasicRaceInfo forID(final int id) {
61
+        if (!instances.containsKey(id)) {
62
+            instances.put(id, new BasicRaceInfo(id));
63
+        }
64
+
65
+        return instances.get(id);
66
+    }
67
+
46 68
 }

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

@@ -22,6 +22,8 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25
+import uk.co.md87.evetool.ui.listable.Retrievable;
26
+
25 27
 /**
26 28
  *
27 29
  * TODO: Document BasicShipInfo
@@ -46,6 +48,7 @@ public class BasicShipInfo extends BasicType {
46 48
     }
47 49
 
48 50
 
51
+    @Retrievable(deferred=true, name="Requirements:")
49 52
     public RequirementsList getRequirements() {
50 53
         return requirements;
51 54
     }

Loading…
Cancel
Save