Use Validate class from Apache Commons to minify code.

This commit is contained in:
Keir 2016-01-08 15:06:13 +00:00
parent 7ce028203b
commit 710654cd06
5 changed files with 20 additions and 45 deletions

View File

@ -5,6 +5,8 @@ import java.io.FileFilter;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.apache.commons.lang3.Validate;
/**
* @author iKeirNez
*/
@ -20,20 +22,9 @@ public class FilePurger implements Runnable
_dataDir = dataDir;
_logger = logger;
if (_dataDir == null)
{
throw new IllegalArgumentException("dataDir cannot be null.");
}
if (!_dataDir.exists() || !_dataDir.isDirectory())
{
throw new IllegalArgumentException("dataDir must exist and be a directory.");
}
if (_logger == null)
{
throw new IllegalArgumentException("Logger cannot be null.");
}
Validate.notNull(_dataDir, "Data directory cannot be null.");
Validate.isTrue(_dataDir.exists() && dataDir.isDirectory(), "Path non-existant or not a directory: %s", _dataDir.getAbsolutePath());
Validate.notNull(_logger, "Logger cannot be null.");
}
@Override

View File

@ -3,13 +3,11 @@ package mineplex.chatsnap;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -18,6 +16,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.lang3.Validate;
import redis.clients.jedis.JedisPubSub;
/**
@ -41,20 +40,9 @@ public class RedisCommandHandler extends JedisPubSub
_directory = directory;
_logger = logger;
if (_directory == null)
{
throw new IllegalArgumentException("Directory cannot be null.");
}
if (!directory.exists() || !directory.isDirectory())
{
throw new IllegalArgumentException("Path non-existent or not a directory: " + directory.getAbsolutePath());
}
if (_logger == null)
{
throw new IllegalArgumentException("Logger cannot be null.");
}
Validate.notNull(_directory, "Directory cannot be null.");
Validate.isTrue(directory.exists() && directory.isDirectory(), "Path non-existent or not a directory: %s", directory.getPath());
Validate.notNull(_logger, "Logger cannot be null.");
}
@Override

View File

@ -3,6 +3,7 @@ package mineplex.chatsnap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.time.DurationFormatUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
@ -23,16 +24,13 @@ public class RedisConnectionHandler implements Runnable
public RedisConnectionHandler(String name, JedisPool jedisPool, RedisCommandHandler handler, String[] channels, Logger logger)
{
if (channels.length == 0)
{
throw new IllegalArgumentException("Must provide at least one channel.");
}
_name = name;
_jedisPool = jedisPool;
_handler = handler;
_channels = channels;
_logger = logger;
Validate.isTrue(channels.length > 0, "Must provide at least one channel.");
}
@Override

View File

@ -17,6 +17,7 @@ import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.Validate;
import redis.clients.jedis.JedisPool;
/**
@ -77,18 +78,15 @@ public class ReportServer
_dataDirectory = dataDirectory;
_logger = logger;
if (_dataDirectory.exists() && !_dataDirectory.isDirectory())
{
throw new RuntimeException("Not a directory: " + _dataDirectory.getPath());
}
Validate.notNull(_dataDirectory, "Data directory cannot be null.");
if (!_dataDirectory.exists() && !_dataDirectory.mkdir())
{
throw new RuntimeException("Unable to create directory: " + _dataDirectory.getPath());
}
// thrown if path exists but is not a directory
Validate.isTrue(!_dataDirectory.exists() || _dataDirectory.isDirectory(), "Not a directory: %S", _dataDirectory.getPath());
// throws if directory doesn't exist and cannot be created
Validate.isTrue(_dataDirectory.exists() || _dataDirectory.mkdir(), "Unable to create directory: " + _dataDirectory.getPath());
_handler = new RedisCommandHandler(_dataDirectory, _logger);
initializeConnectionsConfig(redisConfig);
schedulePurgeTask();
}

View File

@ -352,7 +352,7 @@ if ($validIdentifier)
$handler = $report->getHandler();
echo $handler != null ? "Staff Member assigned is " . $handler->getUsername() : "No Staff Member assigned";
?>
</span><!-- TODO -->
</span>
<br>
</div>
</div>