diff --git a/.gitignore b/.gitignore
index fd621eb..3a29440 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-Zutil.jar
/build/
/bin/
/target/
diff --git a/Jenkinsfile b/Jenkinsfile
index 09d756f..ded85db 100755
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -28,7 +28,9 @@ node {
stage('Deploy') {
// Figure out Pom version
- def version = (readFile('pom.xml') =~ '(.+?)')[0][1]
+ def pom = readFile('pom.xml')
+ def versionMatch = pom =~ "(.+?)"
+ def version = versionMatch[0][1]
// Start deployment
sh 'mvn -DskipStatic -DskipTests deploy'
diff --git a/src/zutil/ByteUtil.java b/src/zutil/ByteUtil.java
index 4b046db..6f5413e 100755
--- a/src/zutil/ByteUtil.java
+++ b/src/zutil/ByteUtil.java
@@ -54,8 +54,7 @@ public class ByteUtil {
* @return a new byte containing a sub byte defined by the index and length
*/
public static byte getBits(byte data, int index, int length){
- byte ret = (byte) (data & getBitMask(index, length));
- return ret;
+ return (byte) (data & getBitMask(index, length));
}
/**
@@ -153,7 +152,7 @@ public class ByteUtil {
if (shiftBy == 0)
return data;
- byte rest = 0;
+ byte rest;
for (int i=0; i>> shiftBy);
@@ -207,7 +206,7 @@ public class ByteUtil {
* @return A multiline String with human readable HEX and ASCII
*/
public static String toFormattedString(byte[] data, int offset, int length){
- StringBuffer output = new StringBuffer();
+ StringBuilder output = new StringBuilder();
//000 XX XX XX XX XX XX XX XX '........'
int maxOffset = (""+length).length();
diff --git a/src/zutil/ClassUtil.java b/src/zutil/ClassUtil.java
index 8be10f2..2139105 100755
--- a/src/zutil/ClassUtil.java
+++ b/src/zutil/ClassUtil.java
@@ -39,7 +39,7 @@ public class ClassUtil {
/** A Set that contains possible wrapper objects for primitives **/
private static final HashSet> wrappers;
static {
- wrappers = new HashSet>();
+ wrappers = new HashSet<>();
wrappers.add(Boolean.class);
wrappers.add(Character.class);
wrappers.add(Byte.class);
@@ -54,7 +54,7 @@ public class ClassUtil {
/** A Set that contains possible primitives **/
private static final HashSet> primitives;
static {
- primitives = new HashSet>();
+ primitives = new HashSet<>();
primitives.add(boolean.class);
primitives.add(char.class);
primitives.add(byte.class);
diff --git a/src/zutil/CronTimer.java b/src/zutil/CronTimer.java
index 18c5a8c..8bd0229 100755
--- a/src/zutil/CronTimer.java
+++ b/src/zutil/CronTimer.java
@@ -96,10 +96,8 @@ public class CronTimer implements Iterator, Iterable{
String[] divisionArr = str.split("/", 2);
if (divisionArr.length == 2) {
float divider = Integer.parseInt(divisionArr[1]);
- Iterator it = getRange(divisionArr[0], from, to).iterator();
- while (it.hasNext()) {
- Integer i = it.next();
- if (i%divider == 0)
+ for (Integer i : getRange(divisionArr[0], from, to)) {
+ if (i % divider == 0)
list.add(i);
}
}
diff --git a/src/zutil/Encrypter.java b/src/zutil/Encrypter.java
index 3ddce27..5cea8a5 100644
--- a/src/zutil/Encrypter.java
+++ b/src/zutil/Encrypter.java
@@ -166,8 +166,8 @@ public class Encrypter {
public byte[] encrypt(byte[] data){
try {
byte[] encryption = new byte[encipher.getOutputSize(data.length)];
- int ctLength = encipher.update(data, 0, data.length, encryption, 0);
+ int ctLength = encipher.update(data, 0, data.length, encryption, 0);
ctLength += encipher.doFinal(encryption, ctLength);
return encryption;
} catch (Exception e) {
diff --git a/src/zutil/Hasher.java b/src/zutil/Hasher.java
index 58f577a..296cfc2 100755
--- a/src/zutil/Hasher.java
+++ b/src/zutil/Hasher.java
@@ -47,9 +47,9 @@ public class Hasher {
public static String hash(File file, String hashType) throws NoSuchAlgorithmException, IOException {
MessageDigest digest = MessageDigest.getInstance(hashType); //"MD5"
InputStream is = new FileInputStream(file);
- String output = "";
+ String output;
byte[] buffer = new byte[8192];
- int read = 0;
+ int read;
try {
while( (read = is.read(buffer)) > 0) {
digest.update(buffer, 0, read);
@@ -165,14 +165,14 @@ public class Hasher {
try {
// Get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(key, algo);
-
+
// Get a MAC instance and initialize with the signing key
Mac mac = Mac.getInstance(algo);
mac.init(signingKey);
-
+
// Compute the HMAC on input data bytes
byte[] raw = mac.doFinal( data );
-
+
return Converter.toHexString(raw);
} catch (Exception e) {
e.printStackTrace();
@@ -225,10 +225,9 @@ public class Hasher {
* @param data is the byte array to hash
* @param hashType is the hash method (MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512 )
* @return an String containing the hash
- * @throws Exception
*/
public static String hash(byte[] data, String hashType) throws Exception {
- MessageDigest md = null;
+ MessageDigest md;
md = MessageDigest.getInstance(hashType); //MD5 || SHA
md.update(data);
diff --git a/src/zutil/OneInstance.java b/src/zutil/OneInstance.java
index 7b87bcc..9989545 100644
--- a/src/zutil/OneInstance.java
+++ b/src/zutil/OneInstance.java
@@ -27,7 +27,7 @@ package zutil;
/**
* This interface is used to look if another instance of the
* application is running
- *
+ *
* @author Ziver
*
*/
@@ -37,12 +37,12 @@ public interface OneInstance {
*
* @return True if the file is locked else false
*/
- public boolean check();
+ boolean check();
/**
* Locks the application so that another one can not run
*
* @return False if there are a error else true
*/
- public boolean lockApp();
+ boolean lockApp();
}
diff --git a/src/zutil/OneInstanceNetwork.java b/src/zutil/OneInstanceNetwork.java
index 62997e7..90c8232 100644
--- a/src/zutil/OneInstanceNetwork.java
+++ b/src/zutil/OneInstanceNetwork.java
@@ -33,7 +33,7 @@ import java.net.Socket;
/**
* This class checks if the app is alredy running
* by Locking a port
- *
+ *
* @author Ziver Koc
*/
public class OneInstanceNetwork extends Thread implements OneInstance{
@@ -63,8 +63,8 @@ public class OneInstanceNetwork extends Thread implements OneInstance{
* should not be cald outside the class
*/
public void run() {
- ServerSocket serverSocket = null;
- Socket clientSocket = null;
+ ServerSocket serverSocket;
+ Socket clientSocket;
try {
// Create the server socket
serverSocket = new ServerSocket(port, 1);
diff --git a/src/zutil/ProgressListener.java b/src/zutil/ProgressListener.java
index d842d49..a764f7c 100644
--- a/src/zutil/ProgressListener.java
+++ b/src/zutil/ProgressListener.java
@@ -27,7 +27,7 @@ package zutil;
/**
* This interface is used in some classes to handle the progress
* of some action
- *
+ *
* @author Ziver
*
*/
@@ -40,5 +40,5 @@ public interface ProgressListener {
* @param info is some information from the source object
* @param percent is the progress of the object (0-100)
*/
- public void progressUpdate(S source, D info, double percent);
+ void progressUpdate(S source, D info, double percent);
}
diff --git a/src/zutil/StringUtil.java b/src/zutil/StringUtil.java
index ca3ba0b..4001c92 100755
--- a/src/zutil/StringUtil.java
+++ b/src/zutil/StringUtil.java
@@ -31,7 +31,7 @@ import java.util.List;
/**
* This is a class whit utility methods.
- *
+ *
* @author Ziver *
*/
public class StringUtil {
@@ -57,7 +57,7 @@ public class StringUtil {
public static String formatTimeToString(long milisec){
StringBuilder str = new StringBuilder();
- long tmp = 0;
+ long tmp;
// Years
if( milisec >= 31557032762.3361d ){
@@ -69,9 +69,9 @@ public class StringUtil {
str.append(tmp).append(" year ");
}
// Months
- if( milisec >= 2629743830l ){
- tmp = (long) (milisec / 2629743830l);
- milisec -= tmp * 2629743830l;
+ if( milisec >= 2629743830L){
+ tmp = milisec / 2629743830L;
+ milisec -= tmp * 2629743830L;
if( tmp > 1 )
str.append(tmp).append(" months ");
else
@@ -79,7 +79,7 @@ public class StringUtil {
}
// Days
if( milisec >= 86400000 ){
- tmp = (long) (milisec / 86400000);
+ tmp = milisec / 86400000;
milisec -= tmp * 86400000;
if( tmp > 1 )
str.append(tmp).append(" days ");
@@ -88,7 +88,7 @@ public class StringUtil {
}
// Hours
if( milisec >= 3600000 ){
- tmp = (long) (milisec / 3600000);
+ tmp = milisec / 3600000;
milisec -= tmp * 3600000;
if( tmp > 1 )
str.append(tmp).append(" hours ");
@@ -97,13 +97,13 @@ public class StringUtil {
}
// Minutes
if( milisec >= 60000 ){
- tmp = (long) (milisec / 60000);
+ tmp = milisec / 60000;
milisec -= tmp * 60000;
str.append(tmp).append(" min ");
}
// sec
if( milisec >= 1000 ){
- tmp = (long) (milisec / 1000);
+ tmp = milisec / 1000;
milisec -= tmp * 1000;
str.append(tmp).append(" sec ");
}
@@ -118,8 +118,6 @@ public class StringUtil {
* Generates a String where the number has been prefixed
* with zeros until the string has the wanted size.
*
- * @param number
- * @param length
* @return a new String with the given length or longer if the number has more characters.
*/
public static String prefixInt(int number, int length){
@@ -135,6 +133,7 @@ public class StringUtil {
* @param array a array of object that toString() will be called on
* @return a String containing all entries in the list with the specified delimiter in between entries
*/
+ @SafeVarargs
public static String join(String delimiter, T... array){
return join(delimiter, Arrays.asList(array));
}
diff --git a/src/zutil/algo/EuclideansAlgo.java b/src/zutil/algo/EuclideansAlgo.java
index 6f14145..3e53ed5 100644
--- a/src/zutil/algo/EuclideansAlgo.java
+++ b/src/zutil/algo/EuclideansAlgo.java
@@ -30,9 +30,9 @@ import java.math.BigInteger;
import java.util.LinkedList;
/**
- * Euclidean algorithm is an algorithm to determine
+ * Euclidean algorithm is an algorithm to determine
* the greatest common divisor (GCD)
- *
+ *
* @author Ziver
*
*/
@@ -40,7 +40,6 @@ public class EuclideansAlgo {
/**
* Simple Test
- * @param args
*/
public static void main(String[] args){
MultiPrintStream.out.println("*** Correct Answer: ");
@@ -104,7 +103,7 @@ public class EuclideansAlgo {
* @return a list of integers that is generators for a and b
*/
public static LinkedList calcGenerators(int a, int b){
- LinkedList list = new LinkedList();
+ LinkedList list = new LinkedList<>();
int t;
while( b != 0 ){
@@ -126,7 +125,7 @@ public class EuclideansAlgo {
* @return a list of BigIntegers that is generators of a and b
*/
public static LinkedList calcGenerators(BigInteger a, BigInteger b){
- LinkedList list = new LinkedList();
+ LinkedList list = new LinkedList<>();
BigInteger t;
while( !b.equals(BigInteger.ZERO) ){
diff --git a/src/zutil/algo/ShanksTonelliAlgo.java b/src/zutil/algo/ShanksTonelliAlgo.java
index e39da39..c2d7037 100644
--- a/src/zutil/algo/ShanksTonelliAlgo.java
+++ b/src/zutil/algo/ShanksTonelliAlgo.java
@@ -22,16 +22,13 @@
* THE SOFTWARE.
*/
-/**
- *
- */
package zutil.algo;
import java.math.BigInteger;
/**
* The algorithm solves the discreet log equation x^2 = n mod p
- *
+ *
* @author Ziver
* @see Wikipedia
*/
diff --git a/src/zutil/algo/WienersAlgo.java b/src/zutil/algo/WienersAlgo.java
index fc3784d..d7e1058 100644
--- a/src/zutil/algo/WienersAlgo.java
+++ b/src/zutil/algo/WienersAlgo.java
@@ -33,7 +33,7 @@ import java.util.LinkedList;
* The Wieners algorithm factorizes two big numbers a and b.
* It uses the Euclidien algorithm to calculate the generator of the
* numbers and then uses them to calculate the factorization.
- *
+ *
* @author Ziver
*
*/
@@ -49,7 +49,7 @@ public class WienersAlgo {
* If no value was found then it returns null.
*/
public static BigInteger[] calc(BigInteger n, BigInteger e){
- BigInteger[] ret = null;
+ BigInteger[] ret;
LinkedList gen = EuclideansAlgo.calcGenerators(e, n);
diff --git a/src/zutil/algo/path/BreadthFirstSearch.java b/src/zutil/algo/path/BreadthFirstSearch.java
index 90d5f6f..166f084 100644
--- a/src/zutil/algo/path/BreadthFirstSearch.java
+++ b/src/zutil/algo/path/BreadthFirstSearch.java
@@ -43,8 +43,8 @@ public class BreadthFirstSearch implements PathFinder{
* @return A list with the path
*/
public LinkedList find(PathNode start, PathNode stop){
- Queue queue = new LinkedList();
- HashSet visited = new HashSet();
+ Queue queue = new LinkedList<>();
+ HashSet visited = new HashSet<>();
queue.add(start);
visited.add( start );
diff --git a/src/zutil/algo/path/DepthFirstSearch.java b/src/zutil/algo/path/DepthFirstSearch.java
index 197323d..8bbb765 100644
--- a/src/zutil/algo/path/DepthFirstSearch.java
+++ b/src/zutil/algo/path/DepthFirstSearch.java
@@ -29,11 +29,11 @@ import java.util.LinkedList;
/**
* A PathFinder class implemented with DFS
- *
+ *
* @author Ziver
*/
public class DepthFirstSearch {
- private HashSet visited = new HashSet();
+ private HashSet visited = new HashSet<>();
/**
* Returns the first path to the destination
diff --git a/src/zutil/algo/path/DynamicProgramming.java b/src/zutil/algo/path/DynamicProgramming.java
index aa550a9..366c0bb 100644
--- a/src/zutil/algo/path/DynamicProgramming.java
+++ b/src/zutil/algo/path/DynamicProgramming.java
@@ -26,116 +26,62 @@ package zutil.algo.path;
public class DynamicProgramming {
public static char[][] words = new char[][]{
- "bibba".toCharArray(),
- "bitas".toCharArray(),
- "brott".toCharArray(),
- "bl�ja".toCharArray(),
- "boson".toCharArray()
+ "bibba".toCharArray(),
+ "bitas".toCharArray(),
+ "brott".toCharArray(),
+ "blaja".toCharArray(),
+ "boson".toCharArray()
};
- public static void main(String[] args){
+ public static void main(String[] args) {
new DynamicProgramming().search();
}
- /*
-int search(words[][][])
- matrix[][][] = 0
- shortest = -1
-
- for w=0->length(words)
- for y=0->length(words)
- for x=0->length(words)
- // f�rsta raden i matrisen
- if y == 0
- // finns f�rsta bokstaven i r�tt position i f�rsta ordet?
- if words[0][x] != words[w][0]
- matrix[w][y][x] = -1
- else
- matrix[w][y][x] = 0
- else
- // om f�reg�ende �r negativ s�tt nuvarande till negativ
- if matrix[w][y-1][x] < 0
- matrix[w][y-1][x] = -1
- // h�r s� h�nder det riktiga i algoritmen
- else
- tmp = minstaForskjutning(words[y], words[w][y], x)
- if tmp >= 0
- matrix[w][y][x] = matrix[w][y-1][x] + tmp
- else
- matrix[w][y][x] = -1
- // kolla om det �r sista raden i matrisen
- if y == length(matrix)
- if (tmp < shortest || shortest < 0) && tmp >= 0
- shortest = tmp;
-
- return shortest
-
-int minstaForskjutning(word[], find, index){
- minsta = -1
- for i=0->length(word)
- if word[i] == cfind && (abs(index-i) < minsta || minsta < 0)
- minsta = abs(index-i)
-
- return minsta
-
- */
-
- public int search(){
+ public int search() {
int[][][] matrix = new int[words.length][words.length][words.length];
int shortest = -1;
- for(int w=0; w= 0){
- matrix[w][y][x] = matrix[w][y-1][x] + tmp;
- }
- else{
+ } else {
+ int tmp = smallestChange(words[y], words[w][y], x);
+ if (tmp >= 0) {
+ matrix[w][y][x] = matrix[w][y - 1][x] + tmp;
+ } else {
matrix[w][y][x] = -1;
}
}
}
- if(y == words.length-1){
+ if (y == words.length - 1) {
int tmp = matrix[w][y][x];
- if((tmp= 0){
+ if ((tmp < shortest || shortest < 0)
+ && tmp >= 0) {
shortest = tmp;
}
}
- System.out.print(" "+matrix[w][y][x]);
}
}
}
- System.out.println("\n\nKortaste f�rflyttningen: "+shortest);
return shortest;
}
- private int minstaForskjutning(char[] word, char cfind, int index){
- int minsta = -1;
- for(int i=0; i find(PathNode start, PathNode goal);
+ LinkedList find(PathNode start, PathNode goal);
}
diff --git a/src/zutil/algo/path/PathNode.java b/src/zutil/algo/path/PathNode.java
index 13e94e1..89b09ea 100644
--- a/src/zutil/algo/path/PathNode.java
+++ b/src/zutil/algo/path/PathNode.java
@@ -32,23 +32,23 @@ public interface PathNode {
/**
* @return an Iterator with all its neighbors
*/
- public Iterable getNeighbors();
+ Iterable getNeighbors();
/**
* @param neighbor is the neighbor
* @return the cost to the neighbor
*/
- public int getNeighborCost(PathNode neighbor);
+ int getNeighborCost(PathNode neighbor);
/**
* Sets the parent node to this one
*/
- public void setParentNeighbor(PathNode parent);
+ void setParentNeighbor(PathNode parent);
/**
* @return the parent node
*/
- public PathNode getParentNeighbor();
+ PathNode getParentNeighbor();
/**
* Traverses the parent tree and returns the path.
@@ -56,5 +56,5 @@ public interface PathNode {
* @param goal is the node to reach
* @return the path to the goal, empty list if there is no goal
*/
- public LinkedList traversTo(PathNode goal);
+ LinkedList traversTo(PathNode goal);
}
diff --git a/src/zutil/algo/path/StandardPathNode.java b/src/zutil/algo/path/StandardPathNode.java
index e828e6c..b7cb5db 100644
--- a/src/zutil/algo/path/StandardPathNode.java
+++ b/src/zutil/algo/path/StandardPathNode.java
@@ -37,7 +37,7 @@ public class StandardPathNode implements PathNode{
private PathNode parent;
public StandardPathNode(){
- neighbors = new HashMap();
+ neighbors = new HashMap<>();
}
public int getNeighborCost(PathNode neighbor) {
@@ -57,7 +57,7 @@ public class StandardPathNode implements PathNode{
}
public LinkedList traversTo(PathNode goal) {
- LinkedList path = new LinkedList();
+ LinkedList path = new LinkedList<>();
PathNode current = this;
while(current != null){
path.addFirst(current);
@@ -66,8 +66,8 @@ public class StandardPathNode implements PathNode{
path.addFirst( goal );
return path;
}
- }
- return new LinkedList();
+ }
+ return new LinkedList<>();
}
}
diff --git a/src/zutil/algo/sort/ExternalSort.java b/src/zutil/algo/sort/ExternalSort.java
index 3765ba5..1aee6f7 100644
--- a/src/zutil/algo/sort/ExternalSort.java
+++ b/src/zutil/algo/sort/ExternalSort.java
@@ -33,7 +33,7 @@ import java.util.LinkedList;
* Sort very big files that doesn't fit in ram
* Inspiration:
* http://www.codeodor.com/index.cfm/2007/5/14/Re-Sorting-really-BIG-files---the-Java-source-code/1208
- *
+ *
* @author Ziver
*/
public class ExternalSort {
@@ -48,7 +48,6 @@ public class ExternalSort {
*
* @param orgFile File to sort
* @param sortedFile The sorted file
- * @throws FileNotFoundException
*/
public ExternalSort(File orgFile, File sortedFile) throws FileNotFoundException{
in = new BufferedReader(new FileReader(orgFile));
@@ -62,7 +61,6 @@ public class ExternalSort {
* @param orgFile File to sort
* @param sortedFile The sorted file
* @param chunk The chunk size
- * @throws FileNotFoundException
*/
public ExternalSort(File orgFile, File sortedFile, int chunk) throws FileNotFoundException{
in = new BufferedReader(new FileReader(orgFile));
@@ -88,7 +86,8 @@ public class ExternalSort {
/**
* Merges all the files to one
- * @param files
+ *
+ * @param files a list of files to be merged
*/
private void mergeFiles(LinkedList files){
try {
@@ -116,7 +115,7 @@ public class ExternalSort {
String row;
while (someFileStillHasRows){
String min;
- int minIndex = 0;
+ int minIndex;
row = rows[0];
if (row!=null) {
@@ -208,8 +207,8 @@ public class ExternalSort {
* @throws IOException Some kind of error
*/
private LinkedList sortChunks() throws IOException{
- LinkedList chunkFiles = new LinkedList();
- LinkedList chunk = new LinkedList();
+ LinkedList chunkFiles = new LinkedList<>();
+ LinkedList chunk;
do{
chunk = readChunk(in);
@@ -227,13 +226,11 @@ public class ExternalSort {
/**
* Reads in a chunk of rows into a LinkedList
*
- * @param list The list to populate
* @param in The BufferedReader to read from
- * @return The LinkeList with the chunk
- * @throws IOException Some kind of error
+ * @return a LinkedList with the chunks
*/
private LinkedList readChunk(BufferedReader in) throws IOException{
- LinkedList list = new LinkedList();
+ LinkedList list = new LinkedList<>();
String tmp;
for(int i=0; i list, File file) throws IOException{
BufferedWriter out = new BufferedWriter(new FileWriter(file));
- Iterator it = list.iterator();
- while(it.hasNext()){
- out.write(it.next());
+ for (String str : list) {
+ out.write(str);
out.newLine();
}
out.close();
}
private void removeFiles(LinkedList list){
- Iterator it = list.iterator();
- while(it.hasNext()){
- it.next().delete();
+ for (File file : list) {
+ file.delete();
}
}
}
diff --git a/src/zutil/algo/sort/MergeSort.java b/src/zutil/algo/sort/MergeSort.java
index 55195f8..5925050 100644
--- a/src/zutil/algo/sort/MergeSort.java
+++ b/src/zutil/algo/sort/MergeSort.java
@@ -73,9 +73,7 @@ public class MergeSort{
int length = pivot-start;
int[] tmp = new int[stop-start];
- for(int i=0; i
*
* @param list is the list to merge
* @param start is the start of the first sublist
diff --git a/src/zutil/chart/AbstractChart.java b/src/zutil/chart/AbstractChart.java
index 4c0162d..d671233 100755
--- a/src/zutil/chart/AbstractChart.java
+++ b/src/zutil/chart/AbstractChart.java
@@ -87,7 +87,7 @@ public abstract class AbstractChart extends JPanel{
*
* @param x is the x data value
* @param scale is the data scale
- * @param bound is the drawing boundds
+ * @param bound is the drawing bounds
* @return a x pixel coordinate
*/
static protected double getXCoordinate(double x, double scale, Rectangle bound){
@@ -99,7 +99,7 @@ public abstract class AbstractChart extends JPanel{
*
* @param y is the y data value
* @param scale is the data scale
- * @param bound is the drawing boundds
+ * @param bound is the drawing bounds
* @return a y pixel coordinate
*/
static protected double getYCoordinate(double y, double scale, Rectangle bound){
diff --git a/src/zutil/chart/ChartData.java b/src/zutil/chart/ChartData.java
index 5d159df..8a86ec6 100755
--- a/src/zutil/chart/ChartData.java
+++ b/src/zutil/chart/ChartData.java
@@ -42,10 +42,10 @@ public class ChartData {
public ChartData(){
- xStrings = new HashMap();
- yStrings = new HashMap();
+ xStrings = new HashMap<>();
+ yStrings = new HashMap<>();
- points = new ArrayList();
+ points = new ArrayList<>();
}
public void setXValueString(int x, String name){
diff --git a/src/zutil/converter/Converter.java b/src/zutil/converter/Converter.java
index 33df967..30f4393 100755
--- a/src/zutil/converter/Converter.java
+++ b/src/zutil/converter/Converter.java
@@ -205,7 +205,7 @@ public class Converter {
* @return a hex String
*/
public static String toHexString(byte[][] raw){
- StringBuffer ret = new StringBuffer();
+ StringBuilder ret = new StringBuilder();
for(byte[] a : raw){
for(byte b : a){
@@ -218,7 +218,7 @@ public class Converter {
}
public static String toHexStringByColumn(byte[][] raw){
- StringBuffer ret = new StringBuffer();
+ StringBuilder ret = new StringBuilder();
for(int col=0; col>> 0x04)& 0x0F ]);
@@ -267,8 +267,8 @@ public class Converter {
* @return a String with 1's and 0's
*/
public static String toString(byte raw){
- StringBuffer ret = new StringBuffer();
- for(int i=128; i>0 ;i=( i<1 ? i=0 : i/2 ) ){
+ StringBuilder ret = new StringBuilder();
+ for(int i=128; i>0 ;i=( i<1 ? 0 : i/2 ) ){
ret.append(( (raw & i) == 0 ? '0' : '1'));
}
return ret.toString();
@@ -281,9 +281,9 @@ public class Converter {
* @return a String with 1's and 0's
*/
public static String toString(byte[] raw){
- StringBuffer ret = new StringBuffer();
+ StringBuilder ret = new StringBuilder();
for(byte b : raw){
- for(int i=128; i>0 ;i=( i<1 ? i=0 : i/2 ) ){
+ for(int i=128; i>0 ;i=( i<1 ? 0 : i/2 ) ){
ret.append(( (b & i) == 0 ? '0' : '1'));
}
}
@@ -419,8 +419,8 @@ public class Converter {
else if(c == float.class) return (T) new Float(data);
else if(c == Double.class) return (T) new Double(data);
else if(c == double.class) return (T) new Double(data);
- else if(c == Boolean.class) return (T) new Boolean(data);
- else if(c == boolean.class) return (T) new Boolean(data);
+ else if(c == Boolean.class) return (T) Boolean.valueOf(data);
+ else if(c == boolean.class) return (T) Boolean.valueOf(data);
else if(c == Byte.class) return (T) new Byte(data);
else if(c == byte.class) return (T) new Byte(data);
else if(byte[].class.isAssignableFrom(c))
diff --git a/src/zutil/converter/NumberToWordsConverter.java b/src/zutil/converter/NumberToWordsConverter.java
index 390a177..7482c2b 100755
--- a/src/zutil/converter/NumberToWordsConverter.java
+++ b/src/zutil/converter/NumberToWordsConverter.java
@@ -38,39 +38,39 @@ public class NumberToWordsConverter {
private static final HashMap NUMERIC_STRINGS;
static{
NUMERIC_STRINGS = new HashMap<>();
- NUMERIC_STRINGS.put(1l, "one");
- NUMERIC_STRINGS.put(2l, "two");
- NUMERIC_STRINGS.put(3l, "three");
- NUMERIC_STRINGS.put(4l, "four");
- NUMERIC_STRINGS.put(5l, "five");
- NUMERIC_STRINGS.put(6l, "six");
- NUMERIC_STRINGS.put(7l, "seven");
- NUMERIC_STRINGS.put(8l, "eight");
- NUMERIC_STRINGS.put(9l, "nine");
- NUMERIC_STRINGS.put(10l, "ten");
- NUMERIC_STRINGS.put(11l, "eleven");
- NUMERIC_STRINGS.put(12l, "twelve");
- NUMERIC_STRINGS.put(13l, "thirteen");
- NUMERIC_STRINGS.put(14l, "fourteen");
- NUMERIC_STRINGS.put(15l, "fifteen");
- NUMERIC_STRINGS.put(16l, "sixteen");
- NUMERIC_STRINGS.put(17l, "seventeen");
- NUMERIC_STRINGS.put(18l, "eightteen");
- NUMERIC_STRINGS.put(19l, "nineteen");
+ NUMERIC_STRINGS.put(1L, "one");
+ NUMERIC_STRINGS.put(2L, "two");
+ NUMERIC_STRINGS.put(3L, "three");
+ NUMERIC_STRINGS.put(4L, "four");
+ NUMERIC_STRINGS.put(5L, "five");
+ NUMERIC_STRINGS.put(6L, "six");
+ NUMERIC_STRINGS.put(7L, "seven");
+ NUMERIC_STRINGS.put(8L, "eight");
+ NUMERIC_STRINGS.put(9L, "nine");
+ NUMERIC_STRINGS.put(10L, "ten");
+ NUMERIC_STRINGS.put(11L, "eleven");
+ NUMERIC_STRINGS.put(12L, "twelve");
+ NUMERIC_STRINGS.put(13L, "thirteen");
+ NUMERIC_STRINGS.put(14L, "fourteen");
+ NUMERIC_STRINGS.put(15L, "fifteen");
+ NUMERIC_STRINGS.put(16L, "sixteen");
+ NUMERIC_STRINGS.put(17L, "seventeen");
+ NUMERIC_STRINGS.put(18L, "eightteen");
+ NUMERIC_STRINGS.put(19L, "nineteen");
- NUMERIC_STRINGS.put(20l, "twenty");
- NUMERIC_STRINGS.put(30l, "thirty");
- NUMERIC_STRINGS.put(40l, "forty");
- NUMERIC_STRINGS.put(50l, "fifty");
- NUMERIC_STRINGS.put(60l, "sixty");
- NUMERIC_STRINGS.put(70l, "seventy");
- NUMERIC_STRINGS.put(80l, "eighty");
- NUMERIC_STRINGS.put(90l, "ninety");
+ NUMERIC_STRINGS.put(20L, "twenty");
+ NUMERIC_STRINGS.put(30L, "thirty");
+ NUMERIC_STRINGS.put(40L, "forty");
+ NUMERIC_STRINGS.put(50L, "fifty");
+ NUMERIC_STRINGS.put(60L, "sixty");
+ NUMERIC_STRINGS.put(70L, "seventy");
+ NUMERIC_STRINGS.put(80L, "eighty");
+ NUMERIC_STRINGS.put(90L, "ninety");
- NUMERIC_STRINGS.put(100l, "hundred");
- NUMERIC_STRINGS.put(1_000l, "thousand");
- NUMERIC_STRINGS.put(1000_000l, "million");
- NUMERIC_STRINGS.put(1000_000_000l, "billion");
+ NUMERIC_STRINGS.put(100L, "hundred");
+ NUMERIC_STRINGS.put(1_000L, "thousand");
+ NUMERIC_STRINGS.put(1000_000L, "million");
+ NUMERIC_STRINGS.put(1000_000_000L, "billion");
}
diff --git a/src/zutil/converter/WGS84Converter.java b/src/zutil/converter/WGS84Converter.java
index 9e14f53..12a59d7 100755
--- a/src/zutil/converter/WGS84Converter.java
+++ b/src/zutil/converter/WGS84Converter.java
@@ -56,7 +56,7 @@ public class WGS84Converter {
}
}
// 3444.0000S 13521.0000E
- else if(coordinate.matches("[0-9]{4,5}.[0-9]*[NSEW]{1}")){
+ else if(coordinate.matches("[0-9]{4,5}.[0-9]*[NSEW]")){
coordinate = coordinate.replaceAll("[NS EW]", "");
float tmpf = Float.parseFloat(coordinate);
deg = (int)(tmpf/100);
diff --git a/src/zutil/db/DBConnection.java b/src/zutil/db/DBConnection.java
index fffbf36..1bf9e58 100755
--- a/src/zutil/db/DBConnection.java
+++ b/src/zutil/db/DBConnection.java
@@ -129,7 +129,7 @@ public class DBConnection implements Closeable{
*/
public long getLastInsertID(){
try{
- return exec("SELECT LAST_INSERT_ID()", new SimpleSQLResult());
+ return exec("SELECT LAST_INSERT_ID()", new SimpleSQLResult<>());
}catch(SQLException e){
logger.log(Level.WARNING, null, e);
}
@@ -212,7 +212,6 @@ public class DBConnection implements Closeable{
/**
* Executes an query and cleans up after itself.
*
- * @param
* @param query is the query
* @param handler is the result handler
* @return update count or -1 if the query is not an update query
@@ -229,7 +228,7 @@ public class DBConnection implements Closeable{
* @param handler is the result handler that will be called with the output of the execution
* @return the object from the handler
*/
- public static T exec(PreparedStatement stmt, SQLResultHandler handler) throws SQLException {
+ public static T exec(PreparedStatement stmt, SQLResultHandler handler) {
try{
// Execute
boolean isResultSet = stmt.execute();
@@ -253,7 +252,6 @@ public class DBConnection implements Closeable{
} catch (SQLException e) {
logger.log(Level.WARNING, null, e);
}
- result = null;
}
}
}
@@ -267,7 +265,6 @@ public class DBConnection implements Closeable{
} catch (SQLException e) {
logger.log(Level.WARNING, null, e);
}
- stmt = null;
}
}
return null;
@@ -293,7 +290,6 @@ public class DBConnection implements Closeable{
} catch (SQLException e) {
logger.log(Level.WARNING, null, e);
}
- stmt = null;
}
}
return new int[0];
diff --git a/src/zutil/db/DBConnectionPool.java b/src/zutil/db/DBConnectionPool.java
index 8c0b24d..8b98133 100644
--- a/src/zutil/db/DBConnectionPool.java
+++ b/src/zutil/db/DBConnectionPool.java
@@ -33,7 +33,7 @@ import java.util.TimerTask;
/**
* This class is an connection pool
- *
+ *
* @author Ziver
*/
public class DBConnectionPool extends TimerTask implements Closeable{
@@ -74,15 +74,15 @@ public class DBConnectionPool extends TimerTask implements Closeable{
* @param user is the user name to the DB
* @param password is the password to the DB
*/
- public DBConnectionPool(DBMS dbms, String url, String db, String user, String password) throws Exception{
+ public DBConnectionPool(DBMS dbms, String url, String db, String user, String password) {
this.dbms = dbms;
this.url = url;
this.db = db;
this.user = user;
this.password = password;
- inusePool = new LinkedList();
- readyPool = new LinkedList();
+ inusePool = new LinkedList<>();
+ readyPool = new LinkedList<>();
this.setTimeout(DEFAULT_TIMEOUT);
this.setMaxSize(DEFAULT_MAX_SIZE);
diff --git a/src/zutil/db/DBUpgradeHandler.java b/src/zutil/db/DBUpgradeHandler.java
index 763de7a..4661d03 100755
--- a/src/zutil/db/DBUpgradeHandler.java
+++ b/src/zutil/db/DBUpgradeHandler.java
@@ -87,7 +87,7 @@ public class DBUpgradeHandler {
* But if forced upgrade is set to true then the upgrade handler will
* create a new table and migrate the data from the old one to the new table.
*
- * @param enable
+ * @param enable true to enable forced upgrade
*/
public void setForcedDBUpgrade(boolean enable){
this.forceUpgradeEnabled = enable;
@@ -240,7 +240,7 @@ public class DBUpgradeHandler {
private List getTableList(DBConnection db) throws SQLException {
return db.exec("SELECT name FROM sqlite_master WHERE type='table';", new SQLResultHandler>() {
public List handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList<>();
while( result.next() ) {
String table = result.getString(1);
if(!ignoredTablesSet.contains(table))
@@ -253,7 +253,7 @@ public class DBUpgradeHandler {
private static String getTableSql(DBConnection db, String table) throws SQLException {
PreparedStatement stmt = db.getPreparedStatement("SELECT sql FROM sqlite_master WHERE name == ?");
stmt.setString(1, table);
- return DBConnection.exec(stmt, new SimpleSQLResult());
+ return DBConnection.exec(stmt, new SimpleSQLResult<>());
}
private static List getColumnList(DBConnection db, String table) throws SQLException {
return db.exec(
diff --git a/src/zutil/db/SQLQuery.java b/src/zutil/db/SQLQuery.java
index 7c22e6c..ab885d2 100644
--- a/src/zutil/db/SQLQuery.java
+++ b/src/zutil/db/SQLQuery.java
@@ -24,11 +24,12 @@
package zutil.db;
+import java.util.Collections;
import java.util.LinkedList;
/**
* A class that generates a query by objects, minimizes errors
- *
+ *
* @author Ziver
*/
public class SQLQuery {
@@ -157,13 +158,12 @@ public class SQLQuery {
//*******************************************
// Sub Types
public static class SQLFrom extends SQLQueryItem{
- LinkedList tables = new LinkedList();
+ LinkedList tables = new LinkedList<>();
SQLQueryItem next;
protected SQLFrom(SQLQueryItem root, String ...tables){
setRoot(root);
- for( String table : tables )
- this.tables.add(table);
+ Collections.addAll(this.tables, tables);
}
public SQLFrom NATURAL_JOIN(String table){
@@ -190,8 +190,7 @@ public class SQLQuery {
private SQLFrom joinLastTable(String type, String table){
String last = tables.getLast();
tables.removeLast();
- tables.add(
- new StringBuilder(last).append(" ").append(type).append(" ").append(table).toString());
+ tables.add(last + " " + type + " " + table);
return this;
}
@@ -238,7 +237,7 @@ public class SQLQuery {
//*******************************************
// Condition Types
public static class SQLWhere extends SQLQueryItem{
- LinkedList conds = new LinkedList();
+ LinkedList conds = new LinkedList<>();
SQLQueryItem next;
protected SQLWhere(SQLQueryItem root){
@@ -283,9 +282,7 @@ public class SQLQuery {
}
private SQLWhere cond(String cond, String arg1, String arg2){
- conds.add(
- //new StringBuilder(arg1).append(cond).append('\"').append(arg2).append('\"').toString());
- new StringBuilder(arg1).append(cond).append(arg2).toString());
+ conds.add(arg1 + cond + arg2);
return this;
}
diff --git a/src/zutil/db/SQLResultHandler.java b/src/zutil/db/SQLResultHandler.java
index c734aa4..3c16577 100644
--- a/src/zutil/db/SQLResultHandler.java
+++ b/src/zutil/db/SQLResultHandler.java
@@ -35,5 +35,5 @@ public interface SQLResultHandler {
* @param stmt is the query
* @param result is the ResultSet
*/
- public T handleQueryResult(Statement stmt, ResultSet result) throws SQLException;
+ T handleQueryResult(Statement stmt, ResultSet result) throws SQLException;
}
diff --git a/src/zutil/db/bean/DBBean.java b/src/zutil/db/bean/DBBean.java
index c4c045a..57c6e5a 100755
--- a/src/zutil/db/bean/DBBean.java
+++ b/src/zutil/db/bean/DBBean.java
@@ -42,12 +42,12 @@ import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
-/**
+/**
* The class that extends this will be able to save its state to a database.
- * Fields that are transient will be ignored, and fields that extend
- * DBBean will be replaced with the an id which corresponds to the field
+ * Fields that are transient will be ignored, and fields that extend
+ * DBBean will be replaced with the an id which corresponds to the field
* of that object.
- *
+ *
*
* Supported fields:
* *Boolean
@@ -335,8 +335,7 @@ public abstract class DBBean {
logger.finest("Load all Beans("+c.getName()+") query: "+sql);
PreparedStatement stmt = db.getPreparedStatement( sql );
// Run query
- List list = DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(c, db) );
- return list;
+ return DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(c, db) );
}
/**
@@ -369,7 +368,7 @@ public abstract class DBBean {
// Generate the SQL
StringBuilder query = new StringBuilder();
- query.append("CREATE TABLE "+config.getTableName()+" ( ");
+ query.append("CREATE TABLE ").append(config.getTableName()).append(" ( ");
// ID
query.append(" ").append(config.getIdColumnName()).append(" ");
diff --git a/src/zutil/db/bean/DBBeanCache.java b/src/zutil/db/bean/DBBeanCache.java
index f997f8f..9057b7d 100755
--- a/src/zutil/db/bean/DBBeanCache.java
+++ b/src/zutil/db/bean/DBBeanCache.java
@@ -126,8 +126,7 @@ class DBBeanCache {
public static DBBean get(Class> c, Long id) {
if(contains(c, id)){
CacheItem cacheItem = cache.get(c).get(id);
- DBBean bean = cacheItem.bean.get();
- return bean;
+ return cacheItem.bean.get();
}
logger.finer("Bean("+c.getName()+") cache miss for id: "+id);
return null;
diff --git a/src/zutil/db/bean/DBBeanConfig.java b/src/zutil/db/bean/DBBeanConfig.java
index a51c212..9e4c7cb 100755
--- a/src/zutil/db/bean/DBBeanConfig.java
+++ b/src/zutil/db/bean/DBBeanConfig.java
@@ -164,7 +164,7 @@ class DBBeanConfig{
else if (field.getType() == Character.TYPE) field.setChar(obj, (char) 0);
else if (field.getType() == Byte.TYPE) field.setByte(obj, (byte) 0);
else if (field.getType() == Short.TYPE) field.setShort(obj, (short) 0);
- else if (field.getType() == Long.TYPE) field.setLong(obj, 0l);
+ else if (field.getType() == Long.TYPE) field.setLong(obj, 0L);
else if (field.getType() == Float.TYPE) field.setFloat(obj, 0f);
else if (field.getType() == Double.TYPE) field.setDouble(obj, 0d);
else if (field.getType() == Boolean.TYPE) field.setBoolean(obj, false);
diff --git a/src/zutil/image/ImageFilterProcessor.java b/src/zutil/image/ImageFilterProcessor.java
index f8eb568..46a01b7 100644
--- a/src/zutil/image/ImageFilterProcessor.java
+++ b/src/zutil/image/ImageFilterProcessor.java
@@ -30,10 +30,10 @@ import java.awt.image.BufferedImage;
/**
* This is a abstract class for all the effects
- *
+ *
* Inspiration:
* http://www.dickbaldwin.com/tocadv.htm
- *
+ *
* @author Ziver
*/
public abstract class ImageFilterProcessor {
@@ -73,7 +73,7 @@ public abstract class ImageFilterProcessor {
* @param img The image to process
* @return The processed image
*/
- public static ImageFilterProcessor getProcessor(String effect, BufferedImage img) throws InstantiationException, IllegalAccessException, ClassNotFoundException, InterruptedException{
+ public static ImageFilterProcessor getProcessor(String effect, BufferedImage img) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
ImageFilterProcessor processor = (ImageFilterProcessor)Class.forName(effect).newInstance();
processor.img = img;
return processor;
diff --git a/src/zutil/image/RAWImageUtil.java b/src/zutil/image/RAWImageUtil.java
index 4402b8d..166719e 100644
--- a/src/zutil/image/RAWImageUtil.java
+++ b/src/zutil/image/RAWImageUtil.java
@@ -127,8 +127,7 @@ public class RAWImageUtil {
}
}
int meanSquare = (int)(accum/pixelCount);
- int rms = (int)(Math.sqrt(meanSquare));
- return rms;
+ return (int)(Math.sqrt(meanSquare));
}
/**
diff --git a/src/zutil/image/filter/MedianFilter.java b/src/zutil/image/filter/MedianFilter.java
index cebfac4..ccee8ea 100755
--- a/src/zutil/image/filter/MedianFilter.java
+++ b/src/zutil/image/filter/MedianFilter.java
@@ -33,7 +33,7 @@ import java.awt.image.BufferedImage;
/**
* The MedianFilter is used for noise reduction and things
- *
+ *
* @author Ziver
*/
public class MedianFilter extends ImageFilterProcessor{
@@ -92,7 +92,7 @@ public class MedianFilter extends ImageFilterProcessor{
int edgeY = windowSize / 2;
int[][] tmpArray = new int[4][256*2];
- int pixelCount = 0;
+ int pixelCount;
for(int y=startY; y 0 && buffer[lineend-1] == '\r'){
- str = new String(buffer, buf_pos, lineend - buf_pos -1);
+ if(lineEnd > 0 && buffer[lineEnd-1] == '\r'){
+ str = new String(buffer, buf_pos, lineEnd - buf_pos -1);
}
else {
- str = new String(buffer, buf_pos, lineend - buf_pos);
+ str = new String(buffer, buf_pos, lineEnd - buf_pos);
}
- buf_pos = lineend +1;
+ buf_pos = lineEnd +1;
return str;
}
diff --git a/src/zutil/io/DynamicByteArrayStream.java b/src/zutil/io/DynamicByteArrayStream.java
index 95b6e0b..52b3a64 100644
--- a/src/zutil/io/DynamicByteArrayStream.java
+++ b/src/zutil/io/DynamicByteArrayStream.java
@@ -45,7 +45,7 @@ public class DynamicByteArrayStream extends InputStream{
* Create a new instance of DynamicByteArrayStream
*/
public DynamicByteArrayStream(){
- bytes = new ArrayList();
+ bytes = new ArrayList<>();
globalPos = 0;
globalSize = 0;
globalArrayIndex = 0;
@@ -78,7 +78,7 @@ public class DynamicByteArrayStream extends InputStream{
}
@Override
- public synchronized int read() throws IOException {
+ public synchronized int read() {
if(globalPos >= globalSize) return -1;
int ret = bytes.get(globalArrayIndex)[localArrayOffset] & 0xff;
diff --git a/src/zutil/io/IOUtil.java b/src/zutil/io/IOUtil.java
index a4226d4..d2ddf74 100755
--- a/src/zutil/io/IOUtil.java
+++ b/src/zutil/io/IOUtil.java
@@ -28,7 +28,7 @@ import java.io.*;
/**
* Utility class for streams and general IO stuff
- *
+ *
* @author Ziver
*
*/
@@ -38,7 +38,6 @@ public class IOUtil {
* Reads and returns all the content of a stream.
* The InputStream will not be closed
*
- * @param stream
* @return a byte array with the stream contents
*/
public static byte[] readContent(InputStream stream) throws IOException{
@@ -48,14 +47,13 @@ public class IOUtil {
/**
* Reads and returns all the content of a stream.
*
- * @param stream
* @param close true if the stream should be closed at the end
* @return a byte array with the stream contents
*/
public static byte[] readContent(InputStream stream, boolean close) throws IOException{
DynamicByteArrayStream dyn_buff = new DynamicByteArrayStream();
byte[] buff = new byte[8192];
- int len = 0;
+ int len;
while((len = stream.read(buff)) != -1){
dyn_buff.append(buff, 0, len);
}
@@ -68,7 +66,6 @@ public class IOUtil {
* Reads and returns all the content of a stream as a String.
* The InputStream will not be closed
*
- * @param stream
* @return a String with the content of the stream
*/
public static String readContentAsString(InputStream stream) throws IOException{
@@ -77,7 +74,6 @@ public class IOUtil {
/**
* Reads and returns all the content of a stream as a String.
*
- * @param stream
* @param close true if the stream should be closed at the end
* @return a String with the content of the stream
*/
@@ -89,7 +85,6 @@ public class IOUtil {
* Reads and returns all the content of a stream as a String.
* The Reader will not be closed
*
- * @param reader
* @return a String with the content of the stream
*/
public static String readContentAsString(Reader reader) throws IOException{
@@ -98,13 +93,12 @@ public class IOUtil {
/**
* Reads and returns all the content of a stream as a String.
*
- * @param reader
* @param close true if the stream should be closed at the end
* @return a String with the content of the stream
*/
public static String readContentAsString(Reader reader, boolean close) throws IOException{
StringBuilder str = new StringBuilder();
- BufferedReader in = null;
+ BufferedReader in;
if(reader instanceof BufferedReader)
in = (BufferedReader) reader;
else
@@ -131,7 +125,7 @@ public class IOUtil {
*/
public static String readLine(InputStream in) throws IOException {
StringBuilder str = new StringBuilder(80);
- int c = 0;
+ int c;
while ((c=in.read()) >= 0 && (c != '\n') && (c != '\r'))
str.append((char)c);
if (c == '\r')
@@ -150,7 +144,7 @@ public class IOUtil {
*/
public static String readLine(Reader in) throws IOException {
StringBuilder str = new StringBuilder(80);
- int c = 0;
+ int c;
while ((c=in.read()) >= 0 && (c != '\n') && (c != '\r'))
str.append((char)c);
if (c == '\r')
diff --git a/src/zutil/io/MultiPrintStream.java b/src/zutil/io/MultiPrintStream.java
index b624da4..06ca0eb 100755
--- a/src/zutil/io/MultiPrintStream.java
+++ b/src/zutil/io/MultiPrintStream.java
@@ -31,10 +31,7 @@ import java.io.*;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
/**
* @author Ziver
@@ -48,7 +45,7 @@ public class MultiPrintStream extends PrintStream {
public MultiPrintStream(){
super(new PrintStream(System.out));
- streams = new ArrayList();
+ streams = new ArrayList<>();
streams.add(new PrintStream(System.out));
}
@@ -59,7 +56,7 @@ public class MultiPrintStream extends PrintStream {
public MultiPrintStream(String file){
super(new PrintStream(System.out));
try {
- streams = new ArrayList();
+ streams = new ArrayList<>();
streams.add(new PrintStream(System.out));
streams.add(new PrintStream(new File(file)));
} catch (FileNotFoundException e) {
@@ -74,10 +71,8 @@ public class MultiPrintStream extends PrintStream {
*/
public MultiPrintStream(PrintStream[] streams){
super(streams[0]);
- this.streams = new ArrayList();
- for(int i=0; i();
+ Collections.addAll(this.streams, streams);
}
/**
@@ -238,7 +233,7 @@ public class MultiPrintStream extends PrintStream {
private static String dumpToString(Object o , String head, int depth) {
if(o == null)
return "NULL";
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
Class> oClass = o.getClass();
buffer.append( oClass.getName() );
String nextHead = head + "\t";
diff --git a/src/zutil/io/NullWriter.java b/src/zutil/io/NullWriter.java
index 329b911..7099cb8 100755
--- a/src/zutil/io/NullWriter.java
+++ b/src/zutil/io/NullWriter.java
@@ -1,6 +1,5 @@
package zutil.io;
-import java.io.IOException;
import java.io.Writer;
/**
@@ -17,7 +16,7 @@ public class NullWriter extends Writer{
@Override
public void write(char cbuf[], int off, int len) { }
@Override
- public void write(String str) throws IOException { }
+ public void write(String str) { }
@Override
public void write(String str, int off, int len) { }
@@ -37,5 +36,5 @@ public class NullWriter extends Writer{
@Override
public void flush() { }
@Override
- public void close() { };
+ public void close() { }
}
diff --git a/src/zutil/io/file/FileChangeListener.java b/src/zutil/io/file/FileChangeListener.java
index e6694fa..a764791 100644
--- a/src/zutil/io/file/FileChangeListener.java
+++ b/src/zutil/io/file/FileChangeListener.java
@@ -28,7 +28,7 @@ import java.io.File;
/**
* Interface for the FileWatcher class
- *
+ *
* @author Ziver
*/
public interface FileChangeListener{
@@ -38,5 +38,5 @@ public interface FileChangeListener{
*
* @param file The file that has changed
*/
- public void fileChangedEvent(File file);
+ void fileChangedEvent(File file);
}
diff --git a/src/zutil/io/file/FileSearcher.java b/src/zutil/io/file/FileSearcher.java
index 4329ad6..b5cf3a2 100755
--- a/src/zutil/io/file/FileSearcher.java
+++ b/src/zutil/io/file/FileSearcher.java
@@ -36,9 +36,8 @@ import java.util.zip.ZipFile;
public class FileSearcher implements Iterable{
// Constants
- private static final List compressedFileExtensions = Arrays.asList(new String[]{
- "jar", "zip"
- });
+ private static final List compressedFileExtensions = Arrays.asList(
+ "jar", "zip");
// Constructor params
private File root;
@@ -119,7 +118,7 @@ public class FileSearcher implements Iterable{
private FileSearchItem nextItem;
public FileSearchIterator(){
- fileList = new ArrayList();
+ fileList = new ArrayList<>();
index = 0;
addFiles(new FileSearchFileItem(root), root.list());
@@ -208,18 +207,18 @@ public class FileSearcher implements Iterable{
public interface FileSearchItem{
/** @return a file or folder name **/
- public String getName();
+ String getName();
/** @return a path to the file or folder, in case of a compressed file the path to the package will be returned **/
- public String getPath();
+ String getPath();
- public boolean isCompressed();
- public boolean isFile();
- public boolean isDirectory();
+ boolean isCompressed();
+ boolean isFile();
+ boolean isDirectory();
/** @return an InputStream if this is a file otherwise null **/
- public InputStream getInputStream() throws IOException;
+ InputStream getInputStream() throws IOException;
/** @return an String array with all files if this is a folder otherwise null **/
- public String[] listFiles();
+ String[] listFiles();
}
diff --git a/src/zutil/io/file/FileUtil.java b/src/zutil/io/file/FileUtil.java
index 5e7baea..c49a714 100755
--- a/src/zutil/io/file/FileUtil.java
+++ b/src/zutil/io/file/FileUtil.java
@@ -90,9 +90,6 @@ public class FileUtil {
/**
* Copy the contents of a source file to another file.
* NOTE: the method will replace the destination file if it exists.
- *
- * @param source
- * @param destination
*/
public static void copy(File source, File destination) throws IOException{
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));
@@ -126,7 +123,6 @@ public class FileUtil {
*
* @param path is the path to the file (no / if not absolute path)
* @return A URL object for the file
- * @throws URISyntaxException
*/
public static URL findURL(String path){
return Thread.currentThread().getContextClassLoader().getResource(path);
@@ -155,7 +151,6 @@ public class FileUtil {
/**
* Reads and returns the content of a file as a String.
*
- * @param file
* @return the file content
*/
public static String getContent(File file) throws IOException{
@@ -166,14 +161,12 @@ public class FileUtil {
}
/**
- * Reads and returns the content of a file as a String.
+ * Connects to a URL and returns the content of it as a String.
*
- * @param url
- * @return the file content
+ * @return the URL content
*/
public static String getContent(URL url) throws IOException{
- String data = new String(IOUtil.readContent(url.openStream(), true));
- return data;
+ return new String(IOUtil.readContent(url.openStream(), true));
}
/**
@@ -195,7 +188,7 @@ public class FileUtil {
* @return a List of files
*/
public static List search(File dir){
- return search(dir, new LinkedList(), true);
+ return search(dir, new LinkedList<>(), true);
}
/**
@@ -207,7 +200,7 @@ public class FileUtil {
* @return A List of files
*/
public static List search(File dir, List fileList, boolean recursive){
- return search(dir, new LinkedList(), false, (recursive ? Integer.MAX_VALUE : 0));
+ return search(dir, new LinkedList<>(), false, (recursive ? Integer.MAX_VALUE : 0));
}
/**
diff --git a/src/zutil/io/file/FileWatcher.java b/src/zutil/io/file/FileWatcher.java
index f80e96f..a41df9d 100644
--- a/src/zutil/io/file/FileWatcher.java
+++ b/src/zutil/io/file/FileWatcher.java
@@ -32,9 +32,9 @@ import java.util.Timer;
import java.util.TimerTask;
/**
- * This class calls a given listener
+ * This class calls a given listener
* when a file is changed
- *
+ *
* @author Ziver
*
*/
@@ -48,7 +48,6 @@ public class FileWatcher extends TimerTask{
* interval of 1 second
*
* @param file is the file to check
- * @throws FileNotFoundException
*/
public FileWatcher(File file) throws FileNotFoundException{
this(file, 1000);
@@ -59,17 +58,16 @@ public class FileWatcher extends TimerTask{
* check interval
*
* @param file is the file
- * @param intervall is the interval
- * @throws FileNotFoundException
+ * @param interval is the interval
*/
- public FileWatcher(File file, int intervall) throws FileNotFoundException{
+ public FileWatcher(File file, int interval) throws FileNotFoundException{
if(file==null || !file.exists())
throw new FileNotFoundException("File not found: "+file);
this.file = file;
lastChanged = file.lastModified();
Timer t = new Timer(true);
- t.schedule(this, 0, intervall);
+ t.schedule(this, 0, interval);
}
public void setListener(FileChangeListener listener){
diff --git a/src/zutil/jee/upload/AjaxFileUpload.java b/src/zutil/jee/upload/AjaxFileUpload.java
index 12077a5..2176521 100644
--- a/src/zutil/jee/upload/AjaxFileUpload.java
+++ b/src/zutil/jee/upload/AjaxFileUpload.java
@@ -51,7 +51,7 @@ import java.util.logging.Logger;
/**
*