Add consistency to definition classes.

This commit is contained in:
Major-
2014-01-26 23:38:27 +00:00
parent 6d1af1b3f2
commit 085aea77d5
4 changed files with 19 additions and 9 deletions
@@ -22,6 +22,7 @@ public final class EquipmentDefinition {
* Initialises the equipment definitions.
*
* @param definitions The definitions.
* @throws RuntimeException If there is an id mismatch.
*/
public static void init(EquipmentDefinition[] definitions) {
for (int id = 0; id < definitions.length; id++) {
@@ -79,6 +80,11 @@ public final class EquipmentDefinition {
this.id = id;
}
/**
* Gets the total number of equipment definitions.
*
* @return The count.
*/
public int count() {
return definitions.size();
}
@@ -28,9 +28,9 @@ public final class ItemDefinition {
private static final BiMap<Integer, Integer> notesInverse = notes.inverse();
/**
* Gets the total number of items.
* Gets the total number of item definitions.
*
* @return The total number of items.
* @return The count.
*/
public static int count() {
return definitions.length;
@@ -88,7 +88,8 @@ public final class ItemDefinition {
*/
public static ItemDefinition lookup(int id) {
if (id < 0 || id >= definitions.length) {
throw new IndexOutOfBoundsException("item id is out of bounds");
throw new IndexOutOfBoundsException(ItemDefinition.class.getName() + " lookup index " + id
+ " out of bounds.");
}
return definitions[id];
}
@@ -15,9 +15,9 @@ public final class NpcDefinition {
private static NpcDefinition[] definitions;
/**
* Gets the total number of NPCs.
* Gets the total number of npc definitions.
*
* @return The total number of NPCs.
* @return The count.
*/
public static int count() {
return definitions.length;
@@ -43,7 +43,7 @@ public final class NpcDefinition {
for (int id = 0; id < definitions.length; id++) {
NpcDefinition def = definitions[id];
if (def.getId() != id) {
throw new RuntimeException("npc definition id mismatch");
throw new RuntimeException("Npc definition id mismatch!");
}
}
}
@@ -57,7 +57,8 @@ public final class NpcDefinition {
*/
public static NpcDefinition lookup(int id) {
if (id < 0 || id >= definitions.length) {
throw new IndexOutOfBoundsException("npc id is out of bounds");
throw new IndexOutOfBoundsException(NpcDefinition.class.getName() + " lookup index " + id
+ " out of bounds.");
}
return definitions[id];
}
@@ -15,9 +15,9 @@ public final class ObjectDefinition {
private static ObjectDefinition[] definitions;
/**
* Gets the total number of objects.
* Gets the total number of object definitions.
*
* @return The total number of objects.
* @return The count.
*/
public static int count() {
return definitions.length;
@@ -36,6 +36,7 @@ public final class ObjectDefinition {
* Initialises the object definitions.
*
* @param definitions The decoded definitions.
* @throws RuntimeException If there is an id mismatch.
*/
public static void init(ObjectDefinition[] definitions) {
ObjectDefinition.definitions = definitions;
@@ -53,6 +54,7 @@ public final class ObjectDefinition {
*
* @param id The id of the object.
* @return The definition.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public static ObjectDefinition lookup(int id) {
if (id < 0 || id > definitions.length) {