Make cached type lookups case insensitive. Closes #47

This commit is contained in:
Colin McDonald 2016-07-17 16:51:18 -04:00
parent bc1cc8265f
commit c30f11ead4
3 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,7 @@ public final class Rank {
}
public static Rank findById(String id) {
return rankIdCache.get(id);
return rankIdCache.get(id.toLowerCase());
}
static {
@ -57,7 +57,7 @@ public final class Rank {
Map<String, Rank> working = new HashMap<>();
for (Rank rank : ranks) {
working.put(rank.getId(), rank);
working.put(rank.getId().toLowerCase(), rank);
}
rankIdCache = working;
@ -81,13 +81,13 @@ public final class Rank {
public void insert(SingleResultCallback<Void> callback) {
rankCache.add(this);
rankIdCache.put(id, this);
rankIdCache.put(id.toLowerCase(), this);
ranksCollection.insertOne(this, SyncUtils.vertxWrap(callback));
}
public void delete(SingleResultCallback<Void> callback) {
rankCache.remove(this);
rankIdCache.remove(id);
rankIdCache.remove(id.toLowerCase());
ranksCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
}

View File

@ -39,7 +39,7 @@ public final class Server {
}
public static Server findById(String id) {
return serverIdCache.get(id);
return serverIdCache.get(id.toLowerCase());
}
static {
@ -57,7 +57,7 @@ public final class Server {
Map<String, Server> working = new HashMap<>();
for (Server server : servers) {
working.put(server.getId(), server);
working.put(server.getId().toLowerCase(), server);
}
serverIdCache = working;
@ -119,7 +119,7 @@ public final class Server {
public void insert(SingleResultCallback<Void> callback) {
serverCache.add(this);
serverIdCache.put(id, this);
serverIdCache.put(id.toLowerCase(), this);
serversCollection.insertOne(this, SyncUtils.vertxWrap(callback));
}
@ -129,7 +129,7 @@ public final class Server {
public void delete(SingleResultCallback<Void> callback) {
serverCache.remove(this);
serverIdCache.remove(id);
serverIdCache.remove(id.toLowerCase());
serversCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
}

View File

@ -37,7 +37,7 @@ public final class ServerGroup {
}
public static ServerGroup findById(String id) {
return serverGroupIdCache.get(id);
return serverGroupIdCache.get(id.toLowerCase());
}
public static ServerGroup findDefault() {
@ -58,7 +58,7 @@ public final class ServerGroup {
Map<String, ServerGroup> working = new HashMap<>();
for (ServerGroup serverGroup : serverGroups) {
working.put(serverGroup.getId(), serverGroup);
working.put(serverGroup.getId().toLowerCase(), serverGroup);
}
serverGroupIdCache = working;
@ -83,7 +83,7 @@ public final class ServerGroup {
public void insert(SingleResultCallback<Void> callback) {
serverGroupCache.add(this);
serverGroupIdCache.put(id, this);
serverGroupIdCache.put(id.toLowerCase(), this);
serverGroupsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
}
@ -93,7 +93,7 @@ public final class ServerGroup {
public void delete(SingleResultCallback<Void> callback) {
serverGroupCache.remove(this);
serverGroupIdCache.remove(id);
serverGroupIdCache.remove(id.toLowerCase());
serverGroupsCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
}