Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CertificateTree.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. package uk.co.md87.evetool.api.wrappers;
  23. import java.util.ArrayList;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. import uk.co.md87.evetool.api.parser.ApiElement;
  28. import uk.co.md87.evetool.api.wrappers.data.CertCategory;
  29. import uk.co.md87.evetool.api.wrappers.data.CertClass;
  30. import uk.co.md87.evetool.api.wrappers.data.CertInfo;
  31. import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
  32. import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
  33. /**
  34. *
  35. * TODO: Document CertificateTree
  36. * @author chris
  37. */
  38. public class CertificateTree extends ArrayList<CertCategory> {
  39. /**
  40. * A version number for this class. It should be changed whenever the class
  41. * structure is changed (or anything else that would prevent serialized
  42. * objects being unserialized with the new class).
  43. */
  44. private static final long serialVersionUID = 10;
  45. protected final Map<Integer, CertInfo> certs = new HashMap<Integer, CertInfo>();
  46. public CertificateTree(final ApiElement resultElement) {
  47. for (ApiElement row : resultElement.getRowset("categories")) {
  48. add(getCategory(row));
  49. }
  50. }
  51. protected CertCategory getCategory(final ApiElement row) {
  52. final int id = row.getNumericAttribute("categoryID");
  53. final String name = row.getStringAttribute("categoryName");
  54. final List<CertClass> classes = new ArrayList<CertClass>();
  55. for (ApiElement crow : row.getRowset("classes")) {
  56. classes.add(getClass(crow));
  57. }
  58. return new CertCategory(id, name, classes);
  59. }
  60. protected CertClass getClass(final ApiElement row) {
  61. final int id = row.getNumericAttribute("classID");
  62. final String name = row.getStringAttribute("className");
  63. final List<CertInfo> certificates = new ArrayList<CertInfo>();
  64. for (ApiElement crow : row.getRowset("certificates")) {
  65. certificates.add(getCert(crow));
  66. }
  67. return new CertClass(id, name, certificates);
  68. }
  69. protected CertInfo getCert(final ApiElement row) {
  70. final int id = row.getNumericAttribute("certificateID");
  71. final int grade = row.getNumericAttribute("grade");
  72. final int corp = row.getNumericAttribute("corporationID");
  73. final String desc = row.getStringAttribute("description");
  74. final RequirementsList skillReqs = new RequirementsList();
  75. final List<Integer> certReqs = new ArrayList<Integer>();
  76. for (ApiElement srow : row.getRowset("requiredSkills")) {
  77. skillReqs.add(getSkillReq(srow));
  78. }
  79. for (ApiElement crow : row.getRowset("requiredCertificates")) {
  80. certReqs.add(getCertReq(crow));
  81. }
  82. final CertInfo cert = new CertInfo(id, grade, corp, desc, skillReqs, certReqs);
  83. certs.put(id, cert);
  84. return cert;
  85. }
  86. protected SkillRequirement getSkillReq(final ApiElement row) {
  87. final int id = row.getNumericAttribute("typeID");
  88. final int level = row.getNumericAttribute("level");
  89. return new SkillRequirement(id, level);
  90. }
  91. protected Integer getCertReq(final ApiElement row) {
  92. return row.getNumericAttribute("certificateID");
  93. }
  94. }