Browse Source

Back out DataFactory changes

master
Chris Smith 15 years ago
parent
commit
3d49493559

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

@@ -28,7 +28,6 @@ import java.sql.SQLException;
28 28
 import java.util.logging.Level;
29 29
 import java.util.logging.Logger;
30 30
 
31
-import uk.co.md87.evetool.api.DataFactory;
32 31
 import uk.co.md87.evetool.api.EveApi;
33 32
 
34 33
 /**
@@ -63,7 +62,7 @@ public class ApiFactory {
63 62
      * @return An instance of the EVE API.
64 63
      */
65 64
     public static EveApi getApi() {
66
-        return new EveApi(createConnection(), new DataFactory());
65
+        return new EveApi(createConnection());
67 66
     }
68 67
 
69 68
 }

+ 0
- 48
src/uk/co/md87/evetool/api/DataFactory.java View File

@@ -1,48 +0,0 @@
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;
24
-
25
-import java.util.List;
26
-import java.util.Map;
27
-import uk.co.md87.evetool.api.wrappers.SkillGroup;
28
-import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
29
-import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
30
-
31
-/**
32
- *
33
- * TODO: Document DataFactory
34
- * TODO: Add other data classes
35
- * @author chris
36
- */
37
-public class DataFactory {
38
-
39
-    public SkillInfo getSkillInfo(final SkillGroup group, final String name,
40
-            final int id, final String description, final int rank,
41
-            final List<SkillRequirement> requirements,
42
-            final String primaryAttribute, final String secondaryAttribute,
43
-            final Map<String, String> bonuses) {
44
-        return new SkillInfo(group, name, id, description, rank, requirements,
45
-                primaryAttribute, secondaryAttribute, bonuses);
46
-    }
47
-
48
-}

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

@@ -62,9 +62,6 @@ public class EveApi {
62 62
     /** The database connection to use. */
63 63
     private final Connection conn;
64 64
 
65
-    /** The factory to use for constructing data objects. */
66
-    private final DataFactory df;
67
-
68 65
     /** The downloader to use. */
69 66
     private final ApiDownloader downloader;
70 67
     
@@ -82,11 +79,9 @@ public class EveApi {
82 79
      * connection.
83 80
      *
84 81
      * @param sqlConnection A connection to a database to use
85
-     * @param df The factory to use for constructing data objects
86 82
      */
87
-    public EveApi(final Connection sqlConnection, final DataFactory df) {
83
+    public EveApi(final Connection sqlConnection) {
88 84
         this.conn = sqlConnection;
89
-        this.df = df;
90 85
         
91 86
         checkTables();
92 87
 
@@ -182,8 +177,8 @@ public class EveApi {
182 177
         if (result.wasSuccessful()) {
183 178
             try {
184 179
                 return new ApiResponse<T>(type
185
-                        .getConstructor(ApiElement.class, DataFactory.class)
186
-                        .newInstance(result.getResultElement(), df), result);
180
+                        .getConstructor(ApiElement.class)
181
+                        .newInstance(result.getResultElement()), result);
187 182
             } catch (Exception ex) {
188 183
                 LOGGER.log(Level.SEVERE, "Unable to create response object", ex);
189 184
             }

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

@@ -25,7 +25,6 @@ package uk.co.md87.evetool.api.wrappers;
25 25
 import java.util.ArrayList;
26 26
 import java.util.Map;
27 27
 
28
-import uk.co.md87.evetool.api.DataFactory;
29 28
 import uk.co.md87.evetool.api.parser.ApiElement;
30 29
 import uk.co.md87.evetool.api.wrappers.data.BasicCharInfo;
31 30
 import uk.co.md87.evetool.api.wrappers.data.BasicCorpInfo;
@@ -37,7 +36,7 @@ import uk.co.md87.evetool.api.wrappers.data.BasicCorpInfo;
37 36
  */
38 37
 public class CharacterList extends ArrayList<BasicCharInfo> {
39 38
 
40
-    public CharacterList(final ApiElement resultElement, final DataFactory df) {
39
+    public CharacterList(final ApiElement resultElement) {
41 40
         super();
42 41
 
43 42
         for (ApiElement child : resultElement.getChild("rowset").getChildren()) {

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

@@ -27,7 +27,6 @@ import java.util.HashMap;
27 27
 import java.util.List;
28 28
 import java.util.Map;
29 29
 
30
-import uk.co.md87.evetool.api.DataFactory;
31 30
 import uk.co.md87.evetool.api.parser.ApiElement;
32 31
 import uk.co.md87.evetool.api.wrappers.data.Attribute;
33 32
 import uk.co.md87.evetool.api.wrappers.data.BasicCharInfo;
@@ -55,7 +54,7 @@ public class CharacterSheet {
55 54
 
56 55
     private final BasicCharInfo charInfo;
57 56
 
58
-    public CharacterSheet(final ApiElement resultElement, final DataFactory df) {
57
+    public CharacterSheet(final ApiElement resultElement) {
59 58
         super();
60 59
 
61 60
         this.race = resultElement.getChild("race").getContent();

+ 7
- 6
src/uk/co/md87/evetool/api/wrappers/SkillGroup.java View File

@@ -22,12 +22,13 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers;
24 24
 
25
-import uk.co.md87.evetool.api.wrappers.data.*;
26 25
 import java.util.ArrayList;
27 26
 import java.util.List;
28 27
 import java.util.Map;
29
-import uk.co.md87.evetool.api.DataFactory;
28
+
30 29
 import uk.co.md87.evetool.api.parser.ApiElement;
30
+import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
31
+import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
31 32
 
32 33
 /**
33 34
  *
@@ -39,12 +40,12 @@ public class SkillGroup extends ArrayList<SkillInfo> {
39 40
     private final int id;
40 41
     private final String name;
41 42
 
42
-    public SkillGroup(final ApiElement rowElement, final DataFactory df) {
43
+    public SkillGroup(final ApiElement rowElement) {
43 44
         this.name = rowElement.getAttributes().get("groupName");
44 45
         this.id = Integer.parseInt(rowElement.getAttributes().get("groupID"));
45 46
 
46 47
         for (ApiElement row : rowElement.getChild("rowset").getChildren()) {
47
-            addSkill(row, df);
48
+            addSkill(row);
48 49
         }
49 50
     }
50 51
 
@@ -56,7 +57,7 @@ public class SkillGroup extends ArrayList<SkillInfo> {
56 57
         return name;
57 58
     }
58 59
 
59
-    protected void addSkill(final ApiElement row, final DataFactory df) {
60
+    protected void addSkill(final ApiElement row) {
60 61
         final String skillName = row.getAttributes().get("typeName");
61 62
         final int typeId = Integer.parseInt(row.getAttributes().get("typeID"));
62 63
         final String desc = row.getChild("description").getContent();
@@ -68,7 +69,7 @@ public class SkillGroup extends ArrayList<SkillInfo> {
68 69
                 .getChild("secondaryAttribute").getContent();
69 70
         final Map<String, String> bonuses = getBonuses(row.getRowset("skillBonusCollection"));
70 71
 
71
-        add(df.getSkillInfo(this, skillName, typeId, desc, rank, reqs, primaryAttribute,
72
+        add(new SkillInfo(this, skillName, typeId, desc, rank, reqs, primaryAttribute,
72 73
                 secondaryAttribute, bonuses));
73 74
     }
74 75
 

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

@@ -28,7 +28,6 @@ import java.text.SimpleDateFormat;
28 28
 import java.util.Date;
29 29
 import java.util.logging.Level;
30 30
 import java.util.logging.Logger;
31
-import uk.co.md87.evetool.api.DataFactory;
32 31
 import uk.co.md87.evetool.api.EveApi;
33 32
 import uk.co.md87.evetool.api.parser.ApiElement;
34 33
 
@@ -47,7 +46,7 @@ public class SkillInTraining {
47 46
     private int startSP, targetSP;
48 47
     private int targetLevel;
49 48
 
50
-    public SkillInTraining(final ApiElement resultElement, final DataFactory df) {
49
+    public SkillInTraining(final ApiElement resultElement) {
51 50
         super();
52 51
 
53 52
         if ("0".equals(resultElement.getChild("skillInTraining").getContent())) {

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

@@ -24,7 +24,6 @@ package uk.co.md87.evetool.api.wrappers;
24 24
 
25 25
 import java.util.ArrayList;
26 26
 
27
-import uk.co.md87.evetool.api.DataFactory;
28 27
 import uk.co.md87.evetool.api.parser.ApiElement;
29 28
 
30 29
 /**
@@ -34,9 +33,9 @@ import uk.co.md87.evetool.api.parser.ApiElement;
34 33
  */
35 34
 public class SkillList extends ArrayList<SkillGroup> {
36 35
 
37
-    public SkillList(final ApiElement resultElement, final DataFactory df) {
36
+    public SkillList(final ApiElement resultElement) {
38 37
         for (ApiElement row : resultElement.getRowset("skillGroups").getChildren()) {
39
-            add(new SkillGroup(row, df));
38
+            add(new SkillGroup(row));
40 39
         }
41 40
     }
42 41
 

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

@@ -59,6 +59,10 @@ public class SkillInfo {
59 59
         this.bonuses = bonuses;
60 60
     }
61 61
 
62
+    public int getSkillpointsForLevel(final int level) {
63
+        return (int) Math.ceil(250 * rank * Math.pow(32, ((double) level - 1) / 2));
64
+    }
65
+
62 66
     @Override
63 67
     public String toString() {
64 68
         return "[" + name + " (" + id + ")]";

+ 0
- 53
src/uk/co/md87/evetool/data/EnhancedDataFactory.java View File

@@ -1,53 +0,0 @@
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.data;
24
-
25
-import java.util.List;
26
-import java.util.Map;
27
-
28
-import uk.co.md87.evetool.api.DataFactory;
29
-import uk.co.md87.evetool.api.wrappers.SkillGroup;
30
-import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
31
-import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
32
-
33
-/**
34
- * An enhanced {@link DataFactory} which provides concrete classes from the
35
- * <code>data</code> package, which contain extra functionality for use in
36
- * the program.
37
- *
38
- * @author chris
39
- */
40
-public class EnhancedDataFactory extends DataFactory {
41
-
42
-    /** {@inheritDoc} */
43
-    @Override
44
-    public SkillInfo getSkillInfo(final SkillGroup group, final String name,
45
-            final int id, final String description, final int rank,
46
-            final List<SkillRequirement> requirements,
47
-            final String primaryAttribute, final String secondaryAttribute,
48
-            final Map<String, String> bonuses) {
49
-        return new Skill(group, name, id, description, rank, requirements,
50
-                primaryAttribute, secondaryAttribute, bonuses);
51
-    }
52
-
53
-}

+ 0
- 51
src/uk/co/md87/evetool/data/Skill.java View File

@@ -1,51 +0,0 @@
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.data;
24
-
25
-import java.util.List;
26
-import java.util.Map;
27
-import uk.co.md87.evetool.api.wrappers.SkillGroup;
28
-import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
29
-import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
30
-
31
-/**
32
- *
33
- * TODO: Document Skill
34
- * @author chris
35
- */
36
-public class Skill extends SkillInfo {
37
-
38
-    public Skill(final SkillGroup group, final String name, final int id,
39
-            final String description, final int rank,
40
-            final List<SkillRequirement> requirements,
41
-            final String primaryAttribute, final String secondaryAttribute,
42
-            final Map<String, String> bonuses) {
43
-        super(group, name, id, description, rank, requirements, primaryAttribute,
44
-                secondaryAttribute, bonuses);
45
-    }
46
-
47
-    public int getSkillpointsForLevel(final int level) {        
48
-        return (int) Math.ceil(250 * rank * Math.pow(32, ((double) level - 1) / 2));
49
-    }
50
-
51
-}

+ 1
- 1
test/uk/co/md87/evetool/api/EveApiTest.java View File

@@ -47,7 +47,7 @@ public class EveApiTest {
47 47
             conn.createStatement().execute("DROP TABLE PAGECACHE");
48 48
         }
49 49
         
50
-        final EveApi api = new EveApi(conn, new DataFactory());
50
+        final EveApi api = new EveApi(conn);
51 51
         assertTrue(conn.getMetaData().getTables(null, null, "PAGECACHE", null).next());
52 52
     }
53 53
 

+ 1
- 2
test/uk/co/md87/evetool/api/io/DBCacheTest.java View File

@@ -30,7 +30,6 @@ import java.util.Map;
30 30
 
31 31
 import org.junit.Test;
32 32
 
33
-import uk.co.md87.evetool.api.DataFactory;
34 33
 import uk.co.md87.evetool.api.EveApi;
35 34
 import static org.junit.Assert.*;
36 35
 
@@ -46,7 +45,7 @@ public class DBCacheTest {
46 45
     public void testBasicInsert() throws SQLException {
47 46
         final Map<String, String> args = new HashMap<String, String>();
48 47
         final Connection conn = DriverManager.getConnection(dbURL);
49
-        new EveApi(conn, new DataFactory()); // To create tables
48
+        new EveApi(conn); // To create tables
50 49
         final DBCache cache = new DBCache(conn);
51 50
 
52 51
         args.put("foo", "bar");

test/uk/co/md87/evetool/data/SkillTest.java → test/uk/co/md87/evetool/api/wrappers/data/SkillInfoTest.java View File

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package uk.co.md87.evetool.data;
23
+package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25 25
 import org.junit.Test;
26 26
 import static org.junit.Assert.*;
@@ -29,7 +29,7 @@ import static org.junit.Assert.*;
29 29
  *
30 30
  * @author chris
31 31
  */
32
-public class SkillTest {
32
+public class SkillInfoTest {
33 33
 
34 34
     @Test
35 35
     public void testGetSkillpointsForLevel() {
@@ -44,7 +44,7 @@ public class SkillTest {
44 44
         };
45 45
 
46 46
         for (int[] datum : data) {
47
-            final Skill skill = new Skill(null, null, 0, null, datum[0],
47
+            final SkillInfo skill = new SkillInfo(null, null, 0, null, datum[0],
48 48
                     null, null, null, null);
49 49
             assertEquals(datum[2], skill.getSkillpointsForLevel(datum[1]));
50 50
         }

Loading…
Cancel
Save