Removed generic wildcard type code smell

This commit is contained in:
tastybento 2018-08-03 21:02:55 -07:00
parent 1f4977ae62
commit 1c29dfca6b
7 changed files with 20 additions and 22 deletions

View File

@ -1,4 +0,0 @@
package world.bentobox.bentobox.api.commands.island;
public class IslandInfoCommand {
}

View File

@ -22,16 +22,14 @@ public class BSBConfig<T> {
private AbstractDatabaseHandler<T> handler; private AbstractDatabaseHandler<T> handler;
private Logger logger; private Logger logger;
@SuppressWarnings("unchecked")
public BSBConfig(BentoBox plugin, Class<T> type) { public BSBConfig(BentoBox plugin, Class<T> type) {
this.logger = plugin.getLogger(); this.logger = plugin.getLogger();
handler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(type); handler = new FlatFileDatabase().getHandler(type);
} }
@SuppressWarnings("unchecked")
public BSBConfig(Addon addon, Class<T> type) { public BSBConfig(Addon addon, Class<T> type) {
this.logger = addon.getLogger(); this.logger = addon.getLogger();
handler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(type); handler = new FlatFileDatabase().getHandler(type);
} }
/** /**

View File

@ -20,16 +20,14 @@ public class BSBDatabase<T> {
private AbstractDatabaseHandler<T> handler; private AbstractDatabaseHandler<T> handler;
private Logger logger; private Logger logger;
@SuppressWarnings("unchecked")
public BSBDatabase(BentoBox plugin, Class<T> type) { public BSBDatabase(BentoBox plugin, Class<T> type) {
this.logger = plugin.getLogger(); this.logger = plugin.getLogger();
handler = (AbstractDatabaseHandler<T>) BSBDbSetup.getDatabase().getHandler(type); handler = BSBDbSetup.getDatabase().getHandler(type);
} }
@SuppressWarnings("unchecked")
public BSBDatabase(Addon addon, Class<T> type) { public BSBDatabase(Addon addon, Class<T> type) {
this.logger = addon.getLogger(); this.logger = addon.getLogger();
handler = (AbstractDatabaseHandler<T>) BSBDbSetup.getDatabase().getHandler(type); handler = BSBDbSetup.getDatabase().getHandler(type);
} }

View File

@ -35,9 +35,10 @@ public abstract class BSBDbSetup {
/** /**
* Gets a database handler that will store and retrieve classes of type dataObjectClass * Gets a database handler that will store and retrieve classes of type dataObjectClass
* @param <T> - Class type
* @param dataObjectClass - class of the object to be stored in the database * @param dataObjectClass - class of the object to be stored in the database
* @return handler for this database object * @return handler for this database object
*/ */
public abstract AbstractDatabaseHandler<?> getHandler(Class<?> dataObjectClass); public abstract <T> AbstractDatabaseHandler<T> getHandler(Class<T> dataObjectClass);
} }

View File

@ -6,18 +6,19 @@ import world.bentobox.bentobox.database.BSBDbSetup;
public class FlatFileDatabase extends BSBDbSetup{ public class FlatFileDatabase extends BSBDbSetup{
@Override
public AbstractDatabaseHandler<?> getHandler(Class<?> type) {
return new FlatFileDatabaseHandler<>(BentoBox.getInstance(), type, new FlatFileDatabaseConnecter(BentoBox.getInstance()));
}
/** /**
* Get the config * Get the config
* @param <T> - Class type
* @param type - config object type * @param type - config object type
* @return - the config handler * @return - the config handler
*/ */
public AbstractDatabaseHandler<?> getConfig(Class<?> type) { public <T> AbstractDatabaseHandler<T> getConfig(Class<T> type) {
return new ConfigHandler<>(BentoBox.getInstance(), type, new FlatFileDatabaseConnecter(BentoBox.getInstance())); return new ConfigHandler<>(BentoBox.getInstance(), type, new FlatFileDatabaseConnecter(BentoBox.getInstance()));
} }
@Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
return new FlatFileDatabaseHandler<>(BentoBox.getInstance(), type, new FlatFileDatabaseConnecter(BentoBox.getInstance()));
}
} }

View File

@ -8,7 +8,7 @@ import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
public class MongoDBDatabase extends BSBDbSetup{ public class MongoDBDatabase extends BSBDbSetup{
@Override @Override
public AbstractDatabaseHandler<?> getHandler(Class<?> type) { public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
BentoBox plugin = BentoBox.getInstance(); BentoBox plugin = BentoBox.getInstance();
// Check if the MongoDB plugin exists // Check if the MongoDB plugin exists
if (plugin.getServer().getPluginManager().getPlugin("BsbMongo") == null) { if (plugin.getServer().getPluginManager().getPlugin("BsbMongo") == null) {

View File

@ -7,8 +7,12 @@ import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
public class MySQLDatabase extends BSBDbSetup{ public class MySQLDatabase extends BSBDbSetup{
/* (non-Javadoc)
* @see world.bentobox.bentobox.database.BSBDbSetup#getHandler(java.lang.Class)
*/
@Override @Override
public AbstractDatabaseHandler<?> getHandler(Class<?> type) { public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
BentoBox plugin = BentoBox.getInstance(); BentoBox plugin = BentoBox.getInstance();
return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl( return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl(
plugin.getSettings().getDbHost(), plugin.getSettings().getDbHost(),