Serialization improvement

This commit is contained in:
Martijn van Groningen 2013-10-10 17:07:31 +02:00
parent 1792bd6b16
commit 6163c7d8e5
1 changed files with 5 additions and 4 deletions

View File

@ -32,11 +32,12 @@ public enum IndexShardState {
RELOCATED((byte) 4), RELOCATED((byte) 4),
CLOSED((byte) 5); CLOSED((byte) 5);
private static final IndexShardState[] ORDS = new IndexShardState[IndexShardState.values().length]; private static final IndexShardState[] IDS = new IndexShardState[IndexShardState.values().length];
static { static {
for (IndexShardState state : IndexShardState.values()) { for (IndexShardState state : IndexShardState.values()) {
ORDS[state.id()] = state; assert state.id() < IDS.length && state.id() >= 0;
IDS[state.id()] = state;
} }
} }
@ -51,9 +52,9 @@ public enum IndexShardState {
} }
public static IndexShardState fromId(byte id) throws ElasticSearchIllegalArgumentException { public static IndexShardState fromId(byte id) throws ElasticSearchIllegalArgumentException {
if (id < ORDS[0].id && id > ORDS[ORDS.length - 1].id) { if (id < 0 || id >= IDS.length) {
throw new ElasticSearchIllegalArgumentException("No mapping for id [" + id + "]"); throw new ElasticSearchIllegalArgumentException("No mapping for id [" + id + "]");
} }
return ORDS[id]; return IDS[id];
} }
} }