From 1cab6609c0951cdf660b237548e6d7e4e466c885 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sat, 21 Oct 2017 18:39:06 +0200 Subject: [PATCH] Fixed javadoc warnings --- Zutil.iml | 9 + src/zutil/Hasher.java | 4 +- src/zutil/StringUtil.java | 307 ++++---- src/zutil/algo/ShanksTonelliAlgo.java | 2 +- src/zutil/algo/sort/QuickSort.java | 16 +- src/zutil/algo/sort/SimpleSort.java | 62 +- .../algo/sort/sortable/SortableDataList.java | 109 ++- src/zutil/chart/AbstractChart.java | 236 +++--- src/zutil/db/bean/DBBeanObjectDSO.java | 2 +- src/zutil/image/RAWImageUtil.java | 705 +++++++++--------- src/zutil/io/StringOutputStream.java | 86 +-- src/zutil/io/file/FileUtil.java | 1 - src/zutil/jee/upload/AjaxFileUpload.java | 368 ++++----- .../net/nio/worker/chat/ChatMessage.java | 78 +- src/zutil/net/ws/WSInterface.java | 159 ++-- src/zutil/net/ws/WSReturnObject.java | 4 +- src/zutil/parser/BEncodedParser.java | 1 - src/zutil/struct/BloomFilter.java | 297 ++++---- src/zutil/ui/wizard/WizardActionHandler.java | 158 ++-- test/zutil/struct/BloomFilterTest.java | 2 +- 20 files changed, 1301 insertions(+), 1305 deletions(-) diff --git a/Zutil.iml b/Zutil.iml index a2bde11..21e89b9 100755 --- a/Zutil.iml +++ b/Zutil.iml @@ -43,6 +43,15 @@ + + + + + + + + + diff --git a/src/zutil/Hasher.java b/src/zutil/Hasher.java index 75cf704..bcf465a 100755 --- a/src/zutil/Hasher.java +++ b/src/zutil/Hasher.java @@ -99,8 +99,8 @@ public class Hasher { /** * Returns the MD5 hash of the given file * - * @param object is the file to hash - * @return an String containing the hash + * @param file is the file to hash + * @return an String containing the hash */ public static String MD5(File file) throws IOException{ try { diff --git a/src/zutil/StringUtil.java b/src/zutil/StringUtil.java index af0e81c..ca3ba0b 100755 --- a/src/zutil/StringUtil.java +++ b/src/zutil/StringUtil.java @@ -35,84 +35,84 @@ import java.util.List; * @author Ziver * */ public class StringUtil { - public static final String[] sizes = new String[]{"YB", "ZB", "EB", "PB", "TB", "GB", "MB", "kB", "B"}; - - /** - * Present a size (in bytes) as a human-readable value - * - * @param bytes size (in bytes) - * @return string - */ - public static String formatByteSizeToString(long bytes){ - int total = sizes.length-1; - double value = bytes; - - for(; value > 1024 ;total--) { - value /= 1024; - } + public static final String[] sizes = new String[]{"YB", "ZB", "EB", "PB", "TB", "GB", "MB", "kB", "B"}; - value = (double)( (int)(value*10) )/10; - return value+" "+sizes[total]; - } - - public static String formatTimeToString(long milisec){ - StringBuilder str = new StringBuilder(); - long tmp = 0; - - // Years - if( milisec >= 31557032762.3361d ){ - tmp = (long) (milisec / 31557032762.3361d); - milisec -= tmp * 31557032762.3361d; - if( tmp > 1 ) - str.append(tmp).append(" years "); - else - str.append(tmp).append(" year "); - } - // Months - if( milisec >= 2629743830l ){ - tmp = (long) (milisec / 2629743830l); - milisec -= tmp * 2629743830l; - if( tmp > 1 ) - str.append(tmp).append(" months "); - else - str.append(tmp).append(" month "); - } - // Days - if( milisec >= 86400000 ){ - tmp = (long) (milisec / 86400000); - milisec -= tmp * 86400000; - if( tmp > 1 ) - str.append(tmp).append(" days "); - else - str.append(tmp).append(" day "); - } - // Hours - if( milisec >= 3600000 ){ - tmp = (long) (milisec / 3600000); - milisec -= tmp * 3600000; - if( tmp > 1 ) - str.append(tmp).append(" hours "); - else - str.append(tmp).append(" hour "); - } - // Minutes - if( milisec >= 60000 ){ - tmp = (long) (milisec / 60000); - milisec -= tmp * 60000; - str.append(tmp).append(" min "); - } - // sec - if( milisec >= 1000 ){ - tmp = (long) (milisec / 1000); - milisec -= tmp * 1000; - str.append(tmp).append(" sec "); - } - if( milisec > 0 ){ - str.append(milisec).append(" milisec "); - } - - return str.toString(); - } + /** + * Present a size (in bytes) as a human-readable value + * + * @param bytes size (in bytes) + * @return string + */ + public static String formatByteSizeToString(long bytes){ + int total = sizes.length-1; + double value = bytes; + + for(; value > 1024 ;total--) { + value /= 1024; + } + + value = (double)( (int)(value*10) )/10; + return value+" "+sizes[total]; + } + + public static String formatTimeToString(long milisec){ + StringBuilder str = new StringBuilder(); + long tmp = 0; + + // Years + if( milisec >= 31557032762.3361d ){ + tmp = (long) (milisec / 31557032762.3361d); + milisec -= tmp * 31557032762.3361d; + if( tmp > 1 ) + str.append(tmp).append(" years "); + else + str.append(tmp).append(" year "); + } + // Months + if( milisec >= 2629743830l ){ + tmp = (long) (milisec / 2629743830l); + milisec -= tmp * 2629743830l; + if( tmp > 1 ) + str.append(tmp).append(" months "); + else + str.append(tmp).append(" month "); + } + // Days + if( milisec >= 86400000 ){ + tmp = (long) (milisec / 86400000); + milisec -= tmp * 86400000; + if( tmp > 1 ) + str.append(tmp).append(" days "); + else + str.append(tmp).append(" day "); + } + // Hours + if( milisec >= 3600000 ){ + tmp = (long) (milisec / 3600000); + milisec -= tmp * 3600000; + if( tmp > 1 ) + str.append(tmp).append(" hours "); + else + str.append(tmp).append(" hour "); + } + // Minutes + if( milisec >= 60000 ){ + tmp = (long) (milisec / 60000); + milisec -= tmp * 60000; + str.append(tmp).append(" min "); + } + // sec + if( milisec >= 1000 ){ + tmp = (long) (milisec / 1000); + milisec -= tmp * 1000; + str.append(tmp).append(" sec "); + } + if( milisec > 0 ){ + str.append(milisec).append(" milisec "); + } + + return str.toString(); + } /** * Generates a String where the number has been prefixed @@ -130,20 +130,20 @@ public class StringUtil { } - /** - * @param delimiter a String delimiter that will be added between every entry in the list - * @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 - */ - public static String join(String delimiter, T... array){ - return join(delimiter, Arrays.asList(array)); - } /** * @param delimiter a String delimiter that will be added between every entry in the list - * @param list a list of object that toString() will be called on + * @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 */ - public static String join(String delimiter, Iterable list){ + public static String join(String delimiter, T... array){ + return join(delimiter, Arrays.asList(array)); + } + /** + * @param delimiter a String delimiter that will be added between every entry in the list + * @param list a list of object that toString() will be called on + * @return a String containing all entries in the list with the specified delimiter in between entries + */ + public static String join(String delimiter, Iterable list){ StringBuilder str = new StringBuilder(); Iterator it = list.iterator(); if(it.hasNext()) { @@ -155,74 +155,73 @@ public class StringUtil { return str.toString(); } - /** - * Trims the given char and whitespace at the beginning and the end - * - * @param str is the string to trim - * @param trim is the char to trim - * @return a trimmed String - */ - public static String trim(String str, char trim){ - if( str == null || str.isEmpty() ) - return str; - int start=0, stop=str.length(); - // The beginning - for(int i=0; istart ;i--){ - char c = str.charAt( i ); - if( c <= ' ' || c == trim ) - stop = i; - else - break; - } - if( start >= str.length() ) - return ""; - //System.out.println("str: \""+str+"\" start: "+start+" stop: "+stop); - return str.substring(start, stop); - } - - /** - * Trims the whitespace and quotes if the string starts and ends with one - * - * @param str is the string to trim - * @return - */ - public static String trimQuotes(String str){ - if( str == null ) - return null; - str = str.trim(); - if( str.length() >= 2 && str.charAt(0)=='\"' && str.charAt(str.length()-1)=='\"'){ - str = str.substring(1, str.length()-1); - } - return str; - } + /** + * Trims the given char and whitespace at the beginning and the end + * + * @param str is the string to trim + * @param trim is the char to trim + * @return a trimmed String + */ + public static String trim(String str, char trim){ + if( str == null || str.isEmpty() ) + return str; + int start=0, stop=str.length(); + // The beginning + for(int i=0; istart ;i--){ + char c = str.charAt( i ); + if( c <= ' ' || c == trim ) + stop = i; + else + break; + } + if( start >= str.length() ) + return ""; + //System.out.println("str: \""+str+"\" start: "+start+" stop: "+stop); + return str.substring(start, stop); + } + + /** + * Trims the whitespace and quotes if the string starts and ends with one + * + * @param str is the string to trim + */ + public static String trimQuotes(String str){ + if( str == null ) + return null; + str = str.trim(); + if( str.length() >= 2 && str.charAt(0)=='\"' && str.charAt(str.length()-1)=='\"'){ + str = str.substring(1, str.length()-1); + } + return str; + } - private static ArrayList SPACES = new ArrayList<>(); - /** - * @return A string containing a specific amount of spaces - */ - public static String getSpaces(int i){ - if(SPACES.size() <= i){ // Do we need to generate more spaces? - synchronized (SPACES) { // Make sure no one else updates the list at the same time - if(SPACES.size() <= i) { // Make sure the previous synchronized thread hasn't already generated strings - if (SPACES.isEmpty()) - SPACES.add(""); - for (int j = SPACES.size(); j <= i; j++) { - SPACES.add(SPACES.get(j - 1) + " "); - } - } - } - } - return SPACES.get(i); - } + private static ArrayList SPACES = new ArrayList<>(); + /** + * @return A string containing a specific amount of spaces + */ + public static String getSpaces(int i){ + if(SPACES.size() <= i){ // Do we need to generate more spaces? + synchronized (SPACES) { // Make sure no one else updates the list at the same time + if(SPACES.size() <= i) { // Make sure the previous synchronized thread hasn't already generated strings + if (SPACES.isEmpty()) + SPACES.add(""); + for (int j = SPACES.size(); j <= i; j++) { + SPACES.add(SPACES.get(j - 1) + " "); + } + } + } + } + return SPACES.get(i); + } /** @@ -235,7 +234,7 @@ public class StringUtil { * @param delimiter a single character delimiter * @return a List with all data between the delimiter */ - public static List split(String str, char delimiter){ + public static List split(String str, char delimiter){ ArrayList splitList = new ArrayList<>(); int from = 0, to = 0; while (to >= 0) { diff --git a/src/zutil/algo/ShanksTonelliAlgo.java b/src/zutil/algo/ShanksTonelliAlgo.java index a2f63ff..dfb100d 100644 --- a/src/zutil/algo/ShanksTonelliAlgo.java +++ b/src/zutil/algo/ShanksTonelliAlgo.java @@ -33,7 +33,7 @@ import java.math.BigInteger; * The algorithm solves the discreet log equation x^2 = n mod p * * @author Ziver - * @see http://en.wikipedia.org/wiki/Shanks-Tonelli_algorithm + * @see Wikipedia */ public class ShanksTonelliAlgo { public static BigInteger calc(BigInteger n, BigInteger p){ diff --git a/src/zutil/algo/sort/QuickSort.java b/src/zutil/algo/sort/QuickSort.java index 8bf73cc..59184e7 100644 --- a/src/zutil/algo/sort/QuickSort.java +++ b/src/zutil/algo/sort/QuickSort.java @@ -40,7 +40,7 @@ public class QuickSort{ /** * Sort the elements in ascending order using Quicksort. * - * @param A is the list to sort. + * @param list is the list to sort. */ public static void sort(SortableDataList list){ sort(list, 0, list.size()-1, MIDDLE_PIVOT, true); @@ -49,9 +49,9 @@ public class QuickSort{ /** * Sort the elements in ascending order using Quicksort. * - * @param A is the list to sort. - * @param type is the type of pivot - * @param insert is if insertion sort will be used + * @param list is the list to sort. + * @param type is the type of pivot + * @param insert is if insertion sort will be used */ public static void sort(SortableDataList list, int type, boolean insert){ sort(list, 0, list.size()-1, type, insert); @@ -62,10 +62,10 @@ public class QuickSort{ * Reference: http://www.inf.fh-flensburg.de/lang/algorithmen/sortieren/quick/quicken.htm * Complexity: O(n*log n) normally, but O(n^2) if the pivot is bad * - * @param A is the list to sort. - * @param start is the index to start from - * @param stop is the index to stop - * @param type is the type of pivot to use + * @param list is the list to sort. + * @param start is the index to start from + * @param stop is the index to stop + * @param type is the type of pivot to use */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void sort(SortableDataList list, int start, int stop, int type, boolean insertionSort){ diff --git a/src/zutil/algo/sort/SimpleSort.java b/src/zutil/algo/sort/SimpleSort.java index 3bbb7db..c71f3c5 100644 --- a/src/zutil/algo/sort/SimpleSort.java +++ b/src/zutil/algo/sort/SimpleSort.java @@ -39,50 +39,50 @@ public class SimpleSort{ * witch is the slowest of the algorithms. * Complexity: O(n^2). * - * @param A is the list to sort. + * @param list is the list to sort. */ - public static void bubbleSort(SortableDataList list){ - bubbleSort(list, 0, list.size()); + public static void bubbleSort(SortableDataList list){ + bubbleSort(list, 0, list.size()); } - /** + /** * Sort the elements in ascending order using bubble sort * witch is the slowest of the algorithms. * Complexity: O(n^2). * - * @param A is an array of integers. - * @param start is the index to start from - * @param stop is the index to stop + * @param list is an array of integers. + * @param start is the index to start from + * @param stop is the index to stop */ - public static void bubbleSort(SortableDataList list, int start, int stop){ + public static void bubbleSort(SortableDataList list, int start, int stop){ for(int i=start; i 0){ - list.swap(j, j+1); + list.swap(j, j+1); } } } } - + /** * Sort the elements in ascending order using selection sort * witch in practice is 40% faster than bubble sort. * Complexity: O(n^2). * - * @param list is the list to sort. + * @param list is the list to sort. */ - public static void selectionSort(SortableDataList list){ - selectionSort(list, 0, list.size()); + public static void selectionSort(SortableDataList list){ + selectionSort(list, 0, list.size()); } /** * Sort the elements in ascending order using selection sort * witch in practice is 40% faster than bubble sort. * Complexity: O(n^2). * - * @param list is the list to sort. - * @param start is the index to start from - * @param stop is the index to stop + * @param list is the list to sort. + * @param start is the index to start from + * @param stop is the index to stop */ - public static void selectionSort(SortableDataList list, int start, int stop){ + public static void selectionSort(SortableDataList list, int start, int stop){ for (int i = start; i < stop - 1; i++) { // find index m of the minimum element in v[i..n-1] int m = i; @@ -94,32 +94,32 @@ public class SimpleSort{ list.swap(i, m); } } - + /** * Sort the elements in ascending order using insertion sort * witch in practice is 5 times faster than bubble sort. * Complexity: O(n^2). * - * @param A is a list to sort. + * @param list is a list to sort. */ - public static void insertionSort(SortableDataList list){ - insertionSort(list, 0, list.size()); + public static void insertionSort(SortableDataList list){ + insertionSort(list, 0, list.size()); } - /** + /** * Sort the elements in ascending order using insertion sort * witch in practice is 5 times faster than bubble sort. * Complexity: O(n^2). * - * @param A is an array of integers. - * @param start is the index to start from - * @param stop is the index to stop + * @param list is an array of integers. + * @param start is the index to start from + * @param stop is the index to stop */ - public static void insertionSort(SortableDataList list, int start, int stop){ - for(int i=start; i0 ;--j){ - list.swap(j-1, j); - } - } + public static void insertionSort(SortableDataList list, int start, int stop){ + for(int i=start; i0 ;--j){ + list.swap(j-1, j); + } + } } } diff --git a/src/zutil/algo/sort/sortable/SortableDataList.java b/src/zutil/algo/sort/sortable/SortableDataList.java index fe375fa..8c8a77c 100644 --- a/src/zutil/algo/sort/sortable/SortableDataList.java +++ b/src/zutil/algo/sort/sortable/SortableDataList.java @@ -25,60 +25,59 @@ package zutil.algo.sort.sortable; public interface SortableDataList{ - - /** - * Returns a is a specific index i the list - * - * @param i is the index - * @return - */ - public T get(int i); - - /** - * Sets an Object in the specified index - * - * @param i is the index - * @param o is the Object - */ - public void set(int i, T o); - - /** - * Returns the size of the list - * - * @return the size of the list - */ - public int size(); - - /** - * Swaps the given indexes - * - * @param a is the first index - * @param b is the second index - */ - public void swap(int a, int b); - - /** - * Compares to indexes and returns: - * <0 if a0 if a>b , - * =0 if a=b - * - * @param a is the first index to compare - * @param b is the second index to compare - * @return Look at the info - */ - public int compare(int a, int b); - - /** - * Compares to indexes and returns: - * <0 if a0 if a>b , - * =0 if a=b - * - * @param a is the first index to compare - * @param b is the second Object to compare - * @return Look at the info - */ - public int compare(int a, T b); + + /** + * Returns a is a specific index i the list + * + * @param i is the index + */ + T get(int i); + + /** + * Sets an Object in the specified index + * + * @param i is the index + * @param o is the Object + */ + void set(int i, T o); + + /** + * Returns the size of the list + * + * @return the size of the list + */ + int size(); + + /** + * Swaps the given indexes + * + * @param a is the first index + * @param b is the second index + */ + void swap(int a, int b); + + /** + * Compares to indexes and returns: + * <0 if a0 if a>b , + * =0 if a=b + * + * @param a is the first index to compare + * @param b is the second index to compare + * @return Look at the info + */ + int compare(int a, int b); + + /** + * Compares to indexes and returns: + * <0 if a0 if a>b , + * =0 if a=b + * + * @param a is the first index to compare + * @param b is the second Object to compare + * @return Look at the info + */ + int compare(int a, T b); } diff --git a/src/zutil/chart/AbstractChart.java b/src/zutil/chart/AbstractChart.java index 557b9d4..7b29512 100755 --- a/src/zutil/chart/AbstractChart.java +++ b/src/zutil/chart/AbstractChart.java @@ -32,123 +32,123 @@ import java.awt.geom.Line2D; import java.util.logging.Logger; public abstract class AbstractChart extends JPanel{ - private static final Logger logger = LogUtil.getLogger(); - private static final long serialVersionUID = 1L; - - /** The offset from the borders of the panel in pixels */ - public static final int PADDING = 20; - - protected ChartData data; - protected int width; - protected int height; - protected Rectangle chartBound; + private static final Logger logger = LogUtil.getLogger(); + private static final long serialVersionUID = 1L; - - - protected void paintComponent(Graphics g){ - Graphics2D g2 = (Graphics2D)g; - - Rectangle bound = drawScale( g2 ); - drawChart( g2, bound ); - } - - protected Rectangle drawScale(Graphics2D g2){ - if( data == null ) - return null; - - // update values - width = this.getWidth(); - height = this.getHeight(); - Rectangle bound = new Rectangle(); - - // Values - int stepLength = 7; - - /////// Temp values - // Calculate Font sizes - FontMetrics metric = g2.getFontMetrics(); - int fontHeight = metric.getHeight(); - int fontXWidth = 0; - int fontYWidth = 0; - for( Point p : data.getPoints() ){ - int length = 0; - String tmp = data.getXString( p.x ); - if( tmp != null ) length = metric.stringWidth( tmp ); - else length = metric.stringWidth( ""+p.x ); - fontXWidth = Math.max(length, fontXWidth); - - tmp = data.getXString( p.y ); - if( tmp != null ) length = metric.stringWidth( tmp ); - else length = metric.stringWidth( ""+p.y ); - fontYWidth = Math.max(length, fontYWidth); - } - // Calculate origo - Point origo = new Point( PADDING+fontYWidth+stepLength, height-PADDING-fontHeight-stepLength ); - bound.x = (int) (origo.getX()+1); - bound.y = PADDING; - bound.width = width-bound.x-PADDING; - bound.height = (int) (origo.getY()-PADDING-1); - // Calculate Axis scales - double xScale = (double)(Math.abs(data.getMaxX())+Math.abs(data.getMinX()))/bound.width; - double yScale = (double)(Math.abs(data.getMaxY())+Math.abs(data.getMinY()))/bound.height; - - - /////// Draw - // Y Axis - g2.draw( new Line2D.Double( origo.getX(), PADDING, origo.getX(), origo.getY() )); - // X Axis - g2.draw( new Line2D.Double( origo.getX(), origo.getY(), width-PADDING, origo.getY() )); - // Y Axis steps and labels - g2.draw( new Line2D.Double( origo.getX(), origo.getY(), origo.getX()-stepLength, origo.getY() )); - g2.draw( new Line2D.Double( origo.getX(), PADDING, origo.getX()-stepLength, PADDING )); - - // X Axis steps and labels - g2.draw( new Line2D.Double( width-PADDING, origo.getY(), width-PADDING, origo.getY()+stepLength )); - - // DEBUG - /* - g2.setColor(Color.red); - g2.drawRect(bound.x, bound.y, bound.width, bound.height); - */ - return bound; - } - - /** - * This method is called after the chart scale has been drawn. - * This method will draw the actual chart - * - * @param g is the Graphics object that will paint the chart - * @param bound is the bounds of the chart, the drawing should not exceed this bound - */ - protected abstract void drawChart(Graphics2D g2, Rectangle bound); - - - /** - * Sets the data that will be drawn. - * - * @param data is the data to draw - */ - public void setChartData(ChartData data){ - this.data = data; - } - - /** - * Converts a x value to ax pixel coordinate - * - * @param x is the x data value - * @return pixel coordinate, or 0 if the chart have not been drawn yet. - */ - protected int getXCoordinate(int x){ - return 0; - } - - /** - * Converts a y value to a y pixel coordinate - * - * @param y is the y data value - * @return pixel coordinate, or 0 if the chart have not been drawn yet. - */ - protected int getYCoordinate(int y){ - return 0; - } + /** The offset from the borders of the panel in pixels */ + public static final int PADDING = 20; + + protected ChartData data; + protected int width; + protected int height; + protected Rectangle chartBound; + + + + protected void paintComponent(Graphics g){ + Graphics2D g2 = (Graphics2D)g; + + Rectangle bound = drawScale( g2 ); + drawChart( g2, bound ); + } + + protected Rectangle drawScale(Graphics2D g2){ + if( data == null ) + return null; + + // update values + width = this.getWidth(); + height = this.getHeight(); + Rectangle bound = new Rectangle(); + + // Values + int stepLength = 7; + + /////// Temp values + // Calculate Font sizes + FontMetrics metric = g2.getFontMetrics(); + int fontHeight = metric.getHeight(); + int fontXWidth = 0; + int fontYWidth = 0; + for( Point p : data.getPoints() ){ + int length = 0; + String tmp = data.getXString( p.x ); + if( tmp != null ) length = metric.stringWidth( tmp ); + else length = metric.stringWidth( ""+p.x ); + fontXWidth = Math.max(length, fontXWidth); + + tmp = data.getXString( p.y ); + if( tmp != null ) length = metric.stringWidth( tmp ); + else length = metric.stringWidth( ""+p.y ); + fontYWidth = Math.max(length, fontYWidth); + } + // Calculate origo + Point origo = new Point( PADDING+fontYWidth+stepLength, height-PADDING-fontHeight-stepLength ); + bound.x = (int) (origo.getX()+1); + bound.y = PADDING; + bound.width = width-bound.x-PADDING; + bound.height = (int) (origo.getY()-PADDING-1); + // Calculate Axis scales + double xScale = (double)(Math.abs(data.getMaxX())+Math.abs(data.getMinX()))/bound.width; + double yScale = (double)(Math.abs(data.getMaxY())+Math.abs(data.getMinY()))/bound.height; + + + /////// Draw + // Y Axis + g2.draw( new Line2D.Double( origo.getX(), PADDING, origo.getX(), origo.getY() )); + // X Axis + g2.draw( new Line2D.Double( origo.getX(), origo.getY(), width-PADDING, origo.getY() )); + // Y Axis steps and labels + g2.draw( new Line2D.Double( origo.getX(), origo.getY(), origo.getX()-stepLength, origo.getY() )); + g2.draw( new Line2D.Double( origo.getX(), PADDING, origo.getX()-stepLength, PADDING )); + + // X Axis steps and labels + g2.draw( new Line2D.Double( width-PADDING, origo.getY(), width-PADDING, origo.getY()+stepLength )); + + // DEBUG + /* + g2.setColor(Color.red); + g2.drawRect(bound.x, bound.y, bound.width, bound.height); + */ + return bound; + } + + /** + * This method is called after the chart scale has been drawn. + * This method will draw the actual chart + * + * @param g2 is the Graphics object that will paint the chart + * @param bound is the bounds of the chart, the drawing should not exceed this bound + */ + protected abstract void drawChart(Graphics2D g2, Rectangle bound); + + + /** + * Sets the data that will be drawn. + * + * @param data is the data to draw + */ + public void setChartData(ChartData data){ + this.data = data; + } + + /** + * Converts a x value to ax pixel coordinate + * + * @param x is the x data value + * @return pixel coordinate, or 0 if the chart have not been drawn yet. + */ + protected int getXCoordinate(int x){ + return 0; + } + + /** + * Converts a y value to a y pixel coordinate + * + * @param y is the y data value + * @return pixel coordinate, or 0 if the chart have not been drawn yet. + */ + protected int getYCoordinate(int y){ + return 0; + } } diff --git a/src/zutil/db/bean/DBBeanObjectDSO.java b/src/zutil/db/bean/DBBeanObjectDSO.java index 9709219..68be24c 100755 --- a/src/zutil/db/bean/DBBeanObjectDSO.java +++ b/src/zutil/db/bean/DBBeanObjectDSO.java @@ -13,7 +13,7 @@ import java.util.logging.Logger; /** * A intermediate class for loading Objects of generic Classes. - * The extending class must set the "superBean" parameter to true in {@link @DBBean.DBTable}. + * The extending class must set the "superBean" parameter to true in {@link DBBean.DBTable}. * The Object that is stored must use Configurator to define what fields that should be stored. * * This class needs to fields in DB: diff --git a/src/zutil/image/RAWImageUtil.java b/src/zutil/image/RAWImageUtil.java index c6bb370..4402b8d 100644 --- a/src/zutil/image/RAWImageUtil.java +++ b/src/zutil/image/RAWImageUtil.java @@ -30,367 +30,360 @@ package zutil.image; * */ public class RAWImageUtil { - - /** - * Returns the peek value in the image - * - * @param data The image data - * @param startX is the x pixel of the image to start from - * @param startY is the y pixel of the image to start from - * @param stopX is the x pixel of the image to stop - * @param stopY is the y pixel of the image to stop - * @return The peak value of the image - */ - public static int getPeakValue(int[][][] data) { - return getPeakValue(data, 0, 0, data[0].length, data.length); - } - - /** - * Returns the peek value in the image - * - * @param data The image data - * @param startX is the x pixel of the image to start from - * @param startY is the y pixel of the image to start from - * @param stopX is the x pixel of the image to stop - * @param stopY is the y pixel of the image to stop - * @return The peak value of the image - */ - public static int getPeakValue(int[][][] data, int startX, int startY, int stopX, int stopY) { - int peak = 0; - for(int y=startY; y peak) peak = data[y][x][1]; - if(data[y][x][2] > peak) peak = data[y][x][2]; - if(data[y][x][3] > peak) peak = data[y][x][3]; - } - } - return peak; - } - /** - * Normalizes the image data by the given scale - * - * @param data The image data - * @param startX is the x pixel of the image to start from - * @param startY is the y pixel of the image to start from - * @param stopX is the x pixel of the image to stop - * @param stopY is the y pixel of the image to stop - * @param scale The scale to normalize the image by - */ - public static void normalize(int[][][] data, int startX, int startY, int stopX, int stopY, double scale) { - for(int y=startY; y peak) peak = data[y][x][1]; + if(data[y][x][2] > peak) peak = data[y][x][2]; + if(data[y][x][3] > peak) peak = data[y][x][3]; + } + } + return peak; + } - /** - * Multiplies the given image data by the given value - * - * @param data is the image data - * @param startX is the x pixel of the image to start from - * @param startY is the y pixel of the image to start from - * @param stopX is the x pixel of the image to stop - * @param stopY is the y pixel of the image to stop - * @param scale is the number to scale the image color by - */ - public static void scale(int[][][] data, int startX, int startY, int stopX, int stopY, double scale){ - for(int y=startY; y 255) - return 255; - else - return color; - } + /** + * Returns the mean value of the given image data + * + * @param data is the image data + * @return the mean value of the image + */ + public static int getMeanValue(int[][][] data){ + return getMeanValue(data, 0, 0, data[0].length, data.length); + } + + /** + * Returns the mean value of the given image data + * + * @param data is the image data + * @param startX is the x pixel of the image to start from + * @param startY is the y pixel of the image to start from + * @param stopX is the x pixel of the image to stop + * @param stopY is the y pixel of the image to stop + * @return the mean value of the image + */ + public static int getMeanValue(int[][][] data, int startX, int startY, int stopX, int stopY){ + int[] tmp = getMeanArray(data, startX, startY, stopX, stopY); + return (tmp[0] + tmp[1] + tmp[2])/3; + } + + /** + * Returns an mean array containing a mean value for each color + * + * @param data is the image data + * @param startX is the x pixel of the image to start from + * @param startY is the y pixel of the image to start from + * @param stopX is the x pixel of the image to stop + * @param stopY is the y pixel of the image to stop + * @return the mean value of the image + */ + public static int[] getMeanArray(int[][][] data, int startX, int startY, int stopX, int stopY){ + int mean[] = new int[3]; + for(int y=startY; y 255) + return 255; + else + return color; + } } diff --git a/src/zutil/io/StringOutputStream.java b/src/zutil/io/StringOutputStream.java index c8428b9..fc0ccd5 100755 --- a/src/zutil/io/StringOutputStream.java +++ b/src/zutil/io/StringOutputStream.java @@ -33,49 +33,49 @@ import java.io.OutputStream; * */ public class StringOutputStream extends OutputStream{ - // The buffer - protected StringBuilder buffer; - - /** - * Creates an new instance of this class - */ - public StringOutputStream(){ - clear(); - } - - @Override - public void write(int b) { - buffer.append( b ); - } + // The buffer + protected StringBuilder buffer; - @Override - public void write(byte[] b) { - buffer.append( new String(b) ); - } - - @Override - public void write(byte[] b, int off, int len) { - buffer.append( new String(b, off, len) ); - } + /** + * Creates an new instance of this class + */ + public StringOutputStream(){ + clear(); + } - /** - * Same as {@link OutputStream:clear()} - */ - @Override - public void close() {} - - /** - * Clears the String buffer - */ - public void clear(){ - buffer = new StringBuilder(); - } - - /** - * @return the String with the data - */ - @Override - public String toString() { - return buffer.toString(); - } + @Override + public void write(int b) { + buffer.append( b ); + } + + @Override + public void write(byte[] b) { + buffer.append( new String(b) ); + } + + @Override + public void write(byte[] b, int off, int len) { + buffer.append( new String(b, off, len) ); + } + + /** + * Same as {@link OutputStream#close()} + */ + @Override + public void close() {} + + /** + * Clears the String buffer + */ + public void clear(){ + buffer = new StringBuilder(); + } + + /** + * @return the String with the data + */ + @Override + public String toString() { + return buffer.toString(); + } } diff --git a/src/zutil/io/file/FileUtil.java b/src/zutil/io/file/FileUtil.java index 7e9a6e4..5e7baea 100755 --- a/src/zutil/io/file/FileUtil.java +++ b/src/zutil/io/file/FileUtil.java @@ -273,7 +273,6 @@ public class FileUtil { * * @param file is the name of the file * @param ext is the new extension, without the dot - * @return */ public static String replaceExtension(String file, String ext) { if( file == null ) diff --git a/src/zutil/jee/upload/AjaxFileUpload.java b/src/zutil/jee/upload/AjaxFileUpload.java index b073bcf..12077a5 100644 --- a/src/zutil/jee/upload/AjaxFileUpload.java +++ b/src/zutil/jee/upload/AjaxFileUpload.java @@ -50,217 +50,217 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - * + * <pre> * Example web.xml: - * <servlet> - * <servlet-name>Upload</servlet-name> - * <servlet-class>zall.util.AjaxFileUpload</servlet-class> - * <init-param> - * <param-name>JAVASCRIPT</param-name> - * <param-value>{FILE_PATH}</param-value> - * </init-param> - * <init-param> - * <param-name>TEMP_PATH</param-name> - * <param-value>SYSTEM|SERVLET|{PATH}</param-value> - * </init-param> - * </servlet> + * &lt;servlet&gt; + * &lt;servlet-name&gt;Upload&lt;/servlet-name&gt; + * &lt;servlet-class&gt;zall.util.AjaxFileUpload&lt;/servlet-class&gt; + * &lt;init-param&gt; + * &lt;param-name&gt;JAVASCRIPT&lt;/param-name&gt; + * &lt;param-value&gt;{FILE_PATH}&lt;/param-value&gt; + * &lt;/init-param&gt; + * &lt;init-param&gt; + * &lt;param-name&gt;TEMP_PATH&lt;/param-name&gt; + * &lt;param-value&gt;SYSTEM|SERVLET|{PATH}&lt;/param-value&gt; + * &lt;/init-param&gt; + * &lt;/servlet&gt; * * * HTML Header: - * <script type='text/javascript' src='{PATH_TO_SERVLET}?js'></script> + * &lt;script type='text/javascript' src='{PATH_TO_SERVLET}?js'&gt;&lt;/script&gt; * * * HTML Body: - * <FORM id="AjaxFileUpload"> - * <input type="file" multiple name="file" /> - * </FORM> - * <UL id="UploadQueue"></UL> + * &lt;FORM id="AjaxFileUpload"&gt; + * &lt;input type="file" multiple name="file" /&gt; + * &lt;/FORM&gt; + * &lt;UL id="UploadQueue"&gt;&lt;/UL&gt; * * - * + * * @author Ziver * */ public abstract class AjaxFileUpload extends HttpServlet { - private static final Logger logger = LogUtil.getLogger(); - private static final long serialVersionUID = 1L; + private static final Logger logger = LogUtil.getLogger(); + private static final long serialVersionUID = 1L; - public static final String SESSION_FILEUPLOAD_LISTENER = "FILEUPLOAD_LISTENER"; - public static final String JAVASCRIPT_FILE = "zutil/jee/upload/AjaxFileUpload.js"; + public static final String SESSION_FILEUPLOAD_LISTENER = "FILEUPLOAD_LISTENER"; + public static final String JAVASCRIPT_FILE = "zutil/jee/upload/AjaxFileUpload.js"; - public static File TEMPFILE_PATH = null; - public static String JAVASCRIPT = ""; - public static HashSet ALLOWED_EXTENSIONS = new HashSet(); + public static File TEMPFILE_PATH = null; + public static String JAVASCRIPT = ""; + public static HashSet ALLOWED_EXTENSIONS = new HashSet(); - public void init(ServletConfig config) throws ServletException { - super.init(config); - try { - // Read the javascript file to memory - String path = JAVASCRIPT_FILE; - if(config.getInitParameter("JAVASCRIPT_FILE") != null) - path = config.getInitParameter("JAVASCRIPT_FILE"); - JAVASCRIPT = FileUtil.getContent( FileUtil.findURL(path) ); + public void init(ServletConfig config) throws ServletException { + super.init(config); + try { + // Read the javascript file to memory + String path = JAVASCRIPT_FILE; + if(config.getInitParameter("JAVASCRIPT_FILE") != null) + path = config.getInitParameter("JAVASCRIPT_FILE"); + JAVASCRIPT = FileUtil.getContent( FileUtil.findURL(path) ); - // Read temp dir - if(config.getInitParameter("TEMP_PATH") != null){ - if( config.getInitParameter("TEMP_PATH").equalsIgnoreCase("SYSTEM") ) - TEMPFILE_PATH = new File( System.getProperty("java.io.tmpdir") ); - else if( config.getInitParameter("TEMP_PATH").equalsIgnoreCase("SERVLET") ) - TEMPFILE_PATH = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"); - else - TEMPFILE_PATH = new File( config.getInitParameter("TEMP_PATH") ); - } - - // Read allowed file types - if(config.getInitParameter("ALLOWED_EXTENSIONS") != null){ - String[] tmp = config.getInitParameter("ALLOWED_EXTENSIONS").split(","); - StringBuilder ext_log = new StringBuilder("Allowed extensions: "); - for( String ext : tmp ){ - ALLOWED_EXTENSIONS.add(ext.trim().toLowerCase()); - ext_log.append(ext).append(", "); - } - logger.info( ext_log.toString() ); - } + // Read temp dir + if(config.getInitParameter("TEMP_PATH") != null){ + if( config.getInitParameter("TEMP_PATH").equalsIgnoreCase("SYSTEM") ) + TEMPFILE_PATH = new File( System.getProperty("java.io.tmpdir") ); + else if( config.getInitParameter("TEMP_PATH").equalsIgnoreCase("SERVLET") ) + TEMPFILE_PATH = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"); + else + TEMPFILE_PATH = new File( config.getInitParameter("TEMP_PATH") ); + } - } catch (IOException e) { - e.printStackTrace(); - } - } + // Read allowed file types + if(config.getInitParameter("ALLOWED_EXTENSIONS") != null){ + String[] tmp = config.getInitParameter("ALLOWED_EXTENSIONS").split(","); + StringBuilder ext_log = new StringBuilder("Allowed extensions: "); + for( String ext : tmp ){ + ALLOWED_EXTENSIONS.add(ext.trim().toLowerCase()); + ext_log.append(ext).append(", "); + } + logger.info( ext_log.toString() ); + } - @SuppressWarnings("unchecked") - protected void doGet(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - PrintWriter out = response.getWriter(); - if(request.getParameter("js") != null){ - response.setContentType("application/x-javascript"); - String tmp = JAVASCRIPT; - tmp = JAVASCRIPT.replaceAll("\\{SERVLET_URL\\}", request.getRequestURI()); - tmp = tmp.replaceAll("\\{BGUPLOAD\\}", "false"); - tmp = tmp.replaceAll("\\{PROGHTML\\}", getProgressHTML()); - out.print(tmp); - return; - } + } catch (IOException e) { + e.printStackTrace(); + } + } - response.setContentType("application/json"); - HttpSession session = request.getSession(); - LinkedList list = - (LinkedList)session.getAttribute(SESSION_FILEUPLOAD_LISTENER); - if (list == null) { - out.println("[]"); - return; - } + @SuppressWarnings("unchecked") + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if(request.getParameter("js") != null){ + response.setContentType("application/x-javascript"); + String tmp = JAVASCRIPT; + tmp = JAVASCRIPT.replaceAll("\\{SERVLET_URL\\}", request.getRequestURI()); + tmp = tmp.replaceAll("\\{BGUPLOAD\\}", "false"); + tmp = tmp.replaceAll("\\{PROGHTML\\}", getProgressHTML()); + out.print(tmp); + return; + } - // Generate JSON - DataNode root = new DataNode( DataType.List ); - Iterator it = list.iterator(); - while( it.hasNext() ) { - FileUploadListener listener = it.next(); - if( listener.getStatus() == Status.Done || listener.getStatus() == Status.Error ){ - if( listener.getTime() + 5000 < System.currentTimeMillis() ){ - it.remove(); - } - } - - root.add( listener.getJSON() ); - } + response.setContentType("application/json"); + HttpSession session = request.getSession(); + LinkedList list = + (LinkedList)session.getAttribute(SESSION_FILEUPLOAD_LISTENER); + if (list == null) { + out.println("[]"); + return; + } - // Write to the user - JSONWriter json_out = new JSONWriter( out ); - json_out.write(root); - } + // Generate JSON + DataNode root = new DataNode( DataType.List ); + Iterator it = list.iterator(); + while( it.hasNext() ) { + FileUploadListener listener = it.next(); + if( listener.getStatus() == Status.Done || listener.getStatus() == Status.Error ){ + if( listener.getTime() + 5000 < System.currentTimeMillis() ){ + it.remove(); + } + } + + root.add( listener.getJSON() ); + } + + // Write to the user + JSONWriter json_out = new JSONWriter( out ); + json_out.write(root); + } - @SuppressWarnings("unchecked") - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - - FileUploadListener listener = new FileUploadListener(); - try { - // Initiate list and HashMap that will contain the data - HashMap fields = new HashMap(); - ArrayList files = new ArrayList(); - - // Add the listener to the session - HttpSession session = request.getSession(); - LinkedList list = - (LinkedList)session.getAttribute(SESSION_FILEUPLOAD_LISTENER); - if(list == null){ - list = new LinkedList(); - session.setAttribute(SESSION_FILEUPLOAD_LISTENER, list); - } - list.add(listener); + @SuppressWarnings("unchecked") + protected void doPost(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { - // Create a factory for disk-based file items - DiskFileItemFactory factory = new DiskFileItemFactory(); - if(TEMPFILE_PATH != null) - factory.setRepository( TEMPFILE_PATH ); - // Create a new file upload handler - ServletFileUpload upload = new ServletFileUpload(factory); - upload.setProgressListener( listener ); - // Set overall request size constraint - //upload.setSizeMax(yourMaxRequestSize); + FileUploadListener listener = new FileUploadListener(); + try { + // Initiate list and HashMap that will contain the data + HashMap fields = new HashMap(); + ArrayList files = new ArrayList(); - // Parse the request - FileItemIterator it = upload.getItemIterator( request ); - while( it.hasNext() ) { - FileItemStream item = it.next(); - // Is the file type allowed? - if( !item.isFormField() && !ALLOWED_EXTENSIONS.contains( FileUtil.getFileExtension(item.getName()).toLowerCase() )){ - String msg = "Filetype '"+FileUtil.getFileExtension(item.getName())+"' is not allowed!"; - logger.warning( msg ); - listener.setStatus(Status.Error); - listener.setFileName( item.getName() ); - listener.setMessage( msg ); - return; - } - listener.setFileName( item.getName() ); - FileItem fileItem = factory.createItem(item.getFieldName(), - item.getContentType(), item.isFormField(), item.getName()); - // Read the file data - Streams.copy(item.openStream(), fileItem.getOutputStream(), true); - if (fileItem instanceof FileItemHeadersSupport) { - final FileItemHeaders fih = item.getHeaders(); - ((FileItemHeadersSupport) fileItem).setHeaders(fih); - } - - //Handle the item - if(fileItem.isFormField()){ - fields.put( fileItem.getFieldName(), fileItem.getString()); - } - else{ - files.add( fileItem ); - logger.info("Recieved file: "+fileItem.getName()+" ("+StringUtil.formatByteSizeToString(fileItem.getSize())+")"); - } - } - // Process the upload - listener.setStatus( Status.Processing ); - doUpload( request, response, fields, files ); - // Done - listener.setStatus( Status.Done ); - } catch (Exception e) { - logger.log(Level.SEVERE, null, e); - listener.setStatus(Status.Error); - listener.setFileName(""); - listener.setMessage( e.getMessage() ); - } - } + // Add the listener to the session + HttpSession session = request.getSession(); + LinkedList list = + (LinkedList)session.getAttribute(SESSION_FILEUPLOAD_LISTENER); + if(list == null){ + list = new LinkedList(); + session.setAttribute(SESSION_FILEUPLOAD_LISTENER, list); + } + list.add(listener); - /** - * @return the HTML for the progress bar. Special ID's: - *
-filename = String - *
-progress = percent - *
-total = String - *
-uploaded = String - *
-status = String (Uploading, Initializing etc) - *
-speed = String - */ - public abstract String getProgressHTML(); + // Create a factory for disk-based file items + DiskFileItemFactory factory = new DiskFileItemFactory(); + if(TEMPFILE_PATH != null) + factory.setRepository( TEMPFILE_PATH ); + // Create a new file upload handler + ServletFileUpload upload = new ServletFileUpload(factory); + upload.setProgressListener( listener ); + // Set overall request size constraint + //upload.setSizeMax(yourMaxRequestSize); - /** - * Handle the uppload - * @throws ServletException - */ - public abstract void doUpload(HttpServletRequest request, HttpServletResponse response, - Map fields, List files) throws ServletException; + // Parse the request + FileItemIterator it = upload.getItemIterator( request ); + while( it.hasNext() ) { + FileItemStream item = it.next(); + // Is the file type allowed? + if( !item.isFormField() && !ALLOWED_EXTENSIONS.contains( FileUtil.getFileExtension(item.getName()).toLowerCase() )){ + String msg = "Filetype '"+FileUtil.getFileExtension(item.getName())+"' is not allowed!"; + logger.warning( msg ); + listener.setStatus(Status.Error); + listener.setFileName( item.getName() ); + listener.setMessage( msg ); + return; + } + listener.setFileName( item.getName() ); + FileItem fileItem = factory.createItem(item.getFieldName(), + item.getContentType(), item.isFormField(), item.getName()); + // Read the file data + Streams.copy(item.openStream(), fileItem.getOutputStream(), true); + if (fileItem instanceof FileItemHeadersSupport) { + final FileItemHeaders fih = item.getHeaders(); + ((FileItemHeadersSupport) fileItem).setHeaders(fih); + } + + //Handle the item + if(fileItem.isFormField()){ + fields.put( fileItem.getFieldName(), fileItem.getString()); + } + else{ + files.add( fileItem ); + logger.info("Recieved file: "+fileItem.getName()+" ("+StringUtil.formatByteSizeToString(fileItem.getSize())+")"); + } + } + // Process the upload + listener.setStatus( Status.Processing ); + doUpload( request, response, fields, files ); + // Done + listener.setStatus( Status.Done ); + } catch (Exception e) { + logger.log(Level.SEVERE, null, e); + listener.setStatus(Status.Error); + listener.setFileName(""); + listener.setMessage( e.getMessage() ); + } + } + + /** + * @return the HTML for the progress bar. Special ID's: + *
-filename = String + *
-progress = percent + *
-total = String + *
-uploaded = String + *
-status = String (Uploading, Initializing etc) + *
-speed = String + */ + public abstract String getProgressHTML(); + + /** + * Handle the uppload + * @throws ServletException + */ + public abstract void doUpload(HttpServletRequest request, HttpServletResponse response, + Map fields, List files) throws ServletException; } diff --git a/src/zutil/net/nio/worker/chat/ChatMessage.java b/src/zutil/net/nio/worker/chat/ChatMessage.java index 1e29977..278fa0c 100755 --- a/src/zutil/net/nio/worker/chat/ChatMessage.java +++ b/src/zutil/net/nio/worker/chat/ChatMessage.java @@ -27,45 +27,43 @@ package zutil.net.nio.worker.chat; import zutil.net.nio.message.Message; public class ChatMessage implements Message { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public static enum ChatMessageType {REGISTER, UNREGISTER, MESSAGE}; - - public ChatMessageType type; - public String msg; - public String room; - - /** - * Registers the user to the main chat - * - * @param name Name of user - */ - public ChatMessage(){ - this("", "", ChatMessageType.REGISTER); - } - - /** - * Registers the user to the given room - * - * @param room The room to register to - */ - public ChatMessage(String room){ - this("", room, ChatMessageType.REGISTER); - } - - /** - * Sends a message to the given room - * - * @param msg The message - * @param room The room - */ - public ChatMessage(String msg, String room){ - this(msg, room, ChatMessageType.MESSAGE); - } - - public ChatMessage(String msg, String room, ChatMessageType type){ - this.msg = msg; - this.room = room; - this.type = type; - } + public static enum ChatMessageType {REGISTER, UNREGISTER, MESSAGE}; + + public ChatMessageType type; + public String msg; + public String room; + + /** + * Registers the user to the main chat + */ + public ChatMessage(){ + this("", "", ChatMessageType.REGISTER); + } + + /** + * Registers the user to the given room + * + * @param room The room to register to + */ + public ChatMessage(String room){ + this("", room, ChatMessageType.REGISTER); + } + + /** + * Sends a message to the given room + * + * @param msg The message + * @param room The room + */ + public ChatMessage(String msg, String room){ + this(msg, room, ChatMessageType.MESSAGE); + } + + public ChatMessage(String msg, String room, ChatMessageType type){ + this.msg = msg; + this.room = room; + this.type = type; + } } diff --git a/src/zutil/net/ws/WSInterface.java b/src/zutil/net/ws/WSInterface.java index 1857a95..7f0c3ff 100755 --- a/src/zutil/net/ws/WSInterface.java +++ b/src/zutil/net/ws/WSInterface.java @@ -38,22 +38,22 @@ import java.lang.annotation.Target; * private static class Test implements WSInterface{ * public Test(){} * - * @WSDocumentation("blabla") - * @WSDLParamDocumentation("olle = a variable?") + * @WSDocumentation("blabla") + * @WSDLParamDocumentation("olle = a variable?") * public void pubZ( - * @WSParamName("olle") int lol) + * @WSParamName("olle") int lol) * throws Exception{ * .... * } * - * @WSReturnName("param") + * @WSReturnName("param") * public String pubA( - * @WSParamName(value="lol", optional=true) String lol) + * @WSParamName(value="lol", optional=true) String lol) * throws Exception{ * .... * } * - * @WSIgnore() + * @WSIgnore() * public void privaZ(....){ * ... * } @@ -63,79 +63,78 @@ import java.lang.annotation.Target; * @author Ziver */ public interface WSInterface { - /** - * Annotation that assigns a name to an parameters - * in an method. - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.PARAMETER) - public @interface WSParamName { - String value(); - boolean optional() default false; - } - - /** - * Annotation that assigns a name to the return value - * in an method. - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - public @interface WSReturnName { - String value(); - } - - /** - * Skipp publication of the given method - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - public @interface WSIgnore { } - - /** - * Method or Parameter comments for the WSDL. - * These comments are put in the message part of the WSDL - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - public @interface WSDocumentation{ - String value(); - } + /** + * Annotation that assigns a name to an parameters + * in an method. + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.PARAMETER) + @interface WSParamName { + String value(); + boolean optional() default false; + } - /** - * Parameter comments for the WSDL. - * These comments are put in the message part of the WSDL - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - public @interface WSParamDocumentation{ - String value(); - } - - /** - * This method will be used in the header. - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - public @interface WSHeader { } - - /** - * Specifies the name space for method. - * - * @author Ziver - */ - @Retention(RetentionPolicy.RUNTIME) - //@Target(ElementType.TYPE) - public @interface WSNamespace { - String value(); - } + /** + * Annotation that assigns a name to the return value + * in an method. + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface WSReturnName { + String value(); + } + + /** + * Skipp publication of the given method + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface WSIgnore { } + + /** + * Method or Parameter comments for the WSDL. + * These comments are put in the message part of the WSDL + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @interface WSDocumentation{ + String value(); + } + + /** + * Parameter comments for the WSDL. + * These comments are put in the message part of the WSDL + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @interface WSParamDocumentation{ + String value(); + } + + /** + * This method will be used in the header. + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface WSHeader { } + + /** + * Specifies the name space for method. + * + * @author Ziver + */ + @Retention(RetentionPolicy.RUNTIME) + @interface WSNamespace { + String value(); + } } diff --git a/src/zutil/net/ws/WSReturnObject.java b/src/zutil/net/ws/WSReturnObject.java index de37938..eb4d7e1 100644 --- a/src/zutil/net/ws/WSReturnObject.java +++ b/src/zutil/net/ws/WSReturnObject.java @@ -38,9 +38,9 @@ import java.lang.reflect.Field; * *
  * 	private static class TestObject implements WSReturnObject{
- *		@WSValueName("name")
+ *		@WSValueName("name")
  *		public String name;
- *		@WSValueName("lastname")
+ *		@WSValueName("lastname")
  *		public String lastname;
  *
  *		public TestObject(String n, String l){
diff --git a/src/zutil/parser/BEncodedParser.java b/src/zutil/parser/BEncodedParser.java
index ff5fc0e..eddbdfc 100755
--- a/src/zutil/parser/BEncodedParser.java
+++ b/src/zutil/parser/BEncodedParser.java
@@ -41,7 +41,6 @@ public class BEncodedParser {
 	 * Returns the representation of the data in the BEncoded string
 	 * 
 	 * @param	data	is the data to be decoded
-	 * @return
 	 */
 	public static DataNode read(String data) throws ParseException {
 		return decode_BEncoded(new MutableInt(), new StringBuilder(data));
diff --git a/src/zutil/struct/BloomFilter.java b/src/zutil/struct/BloomFilter.java
index 9c21b7c..cd74aff 100644
--- a/src/zutil/struct/BloomFilter.java
+++ b/src/zutil/struct/BloomFilter.java
@@ -38,163 +38,164 @@ import java.util.Set;
  *
  */
 public class BloomFilter implements Set, Serializable{
-	private static final long serialVersionUID = 1L;
-	
-	private BitSet bits;
-	private int content_size;
-	private int optimal_size;
-	private int k;
+    private static final long serialVersionUID = 1L;
 
-	
-	/**
-	 * Creates a bloom filter
-	 * 
-	 * @param size The amount of bits in the filter
-	 * @param expected_data_count The estimated amount of data to 
-	 * 			be inserted(a bigger number is better than a smaller)
-	 */
-	public BloomFilter(int size, int expected_data_count){
-		bits = new BitSet(size);
-		k = (int)((size/expected_data_count) * Math.log(2));
-		content_size = 0;
-		optimal_size = expected_data_count;
-	}
+    private BitSet bits;
+    private int content_size;
+    private int optimal_size;
+    private int k;
 
-	/**
-	 * @param e A Serializable object
-	 * @return If the optimal size has been reached
-	 */
-	public boolean add(T e) {
-		try {
-			content_size++;
-			int hash = 0;
-			for(int i=0; i c) {
-		for(T t : c){
-			add(t);
-		}
-		return isFull();
-	}
+    /**
+     * Creates a bloom filter
+     *
+     * @param	size	The amount of bits in the filter
+     * @param	expected_data_count The estimated amount of data to
+     * 			be inserted(a bigger number is better than a smaller)
+     */
+    public BloomFilter(int size, int expected_data_count){
+        bits = new BitSet(size);
+        k = (int)((size/expected_data_count) * Math.log(2));
+        content_size = 0;
+        optimal_size = expected_data_count;
+    }
 
-	/**
-	 * @return clears the filter
-	 */
-	public void clear() {
-		content_size = 0;
-		bits.clear();
-	}
+    /**
+     * @param	e	A Serializable object
+     * @return If the optimal size has been reached
+     */
+    public boolean add(T e) {
+        try {
+            content_size++;
+            int hash = 0;
+            for(int i=0; i c) {
+        for(T t : c){
+            add(t);
+        }
+        return isFull();
+    }
 
-	/**
-	 * Checks if the whole collection contains in the filter
-	 * 
-	 * @param c The collection
-	 */
-	public boolean containsAll(Collection c) {
-		for(Object o : c){
-			if(!contains(o)) return false;
-		}
-		return true;
-	}
+    /**
+     * Clears the filter
+     */
+    public void clear() {
+        content_size = 0;
+        bits.clear();
+    }
 
-	/**
-	 * @return If the bloom filter is empty
-	 */
-	public boolean isEmpty() {
-		return content_size == 0;
-	}
-	
-	/**
-	 * @return If the optimal size has been reached
-	 */
-	public boolean isFull() {
-		return content_size > optimal_size;
-	}
-	
-	/**
-	 * @return The number of data added
-	 */
-	public int size() {
-		return content_size;
-	}
-	
-	/**
-	 * @return The false positive probability of the current state of the filter
-	 */
-	public double falsePosetiveProbability(){
-		return Math.pow(0.6185, bits.size()/content_size);
-	}
-	
-	/**
-	 * Set the hash count. Should be set before adding elements 
-	 * or the already added elements will be lost
-	 * 
-	 * @param k The hash count
-	 */
-	public void setHashCount(int k){
-		this.k = k;
-	}
-	
-	//*********************************************************************
-	//*********************************************************************
-	public Object[] toArray() {
-		throw new UnsupportedOperationException();  
-	}
+    /**
+     * @param	o	is the Serializable object to search for
+     * @return If the object contains in the filter or
+     * 			false if the Object is not Serializable
+     */
+    public boolean contains(Object o) {
+        try {
+            if(!(o instanceof Serializable))return false;
+            int hash = 0;
+            for(int i=0; i T[] toArray(T[] a) {
-		throw new UnsupportedOperationException();  
-	}
+        return true;
+    }
 
-	public Iterator iterator() {
-		throw new UnsupportedOperationException();  
-	}
+    /**
+     * Checks if the whole collection contains in the filter
+     *
+     * @param	c	The collection
+     */
+    public boolean containsAll(Collection c) {
+        for(Object o : c){
+            if(!contains(o)) return false;
+        }
+        return true;
+    }
 
-	public boolean remove(Object o) {
-		throw new UnsupportedOperationException();  
-	}
+    /**
+     * @return If the bloom filter is empty
+     */
+    public boolean isEmpty() {
+        return content_size == 0;
+    }
 
-	public boolean removeAll(Collection c) {
-		throw new UnsupportedOperationException();  
-	}
-	
-	public boolean retainAll(Collection c) {
-		throw new UnsupportedOperationException();  
-	}
+    /**
+     * @return If the optimal size has been reached
+     */
+    public boolean isFull() {
+        return content_size > optimal_size;
+    }
+
+    /**
+     * @return The number of data added
+     */
+    public int size() {
+        return content_size;
+    }
+
+    /**
+     * @return The false positive probability of the current state of the filter
+     */
+    public double falsePositiveProbability(){
+        return Math.pow(0.6185, bits.size()/content_size);
+    }
+
+    /**
+     * Set the hash count. Should be set before adding elements
+     * or the already added elements will be lost
+     *
+     * @param	k	The hash count
+     */
+    public void setHashCount(int k){
+        this.k = k;
+    }
+
+
+    //*********************************************************************
+    //*********************************************************************
+    public Object[] toArray() {
+        throw new UnsupportedOperationException();
+    }
+
+    @SuppressWarnings("hiding")
+    public  T[] toArray(T[] a) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator iterator() {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean removeAll(Collection c) {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean retainAll(Collection c) {
+        throw new UnsupportedOperationException();
+    }
 }
diff --git a/src/zutil/ui/wizard/WizardActionHandler.java b/src/zutil/ui/wizard/WizardActionHandler.java
index 3cbbe1e..7a6b33b 100644
--- a/src/zutil/ui/wizard/WizardActionHandler.java
+++ b/src/zutil/ui/wizard/WizardActionHandler.java
@@ -36,87 +36,87 @@ import java.awt.event.FocusListener;
 import java.util.HashMap;
 
 public class WizardActionHandler implements ActionListener, FocusListener, ListSelectionListener{
-	private HashMap values;
+    private HashMap values;
 
-	public WizardActionHandler(HashMap values){
-		this.values = values;
-	}
+    public WizardActionHandler(HashMap values){
+        this.values = values;
+    }
 
-	public void actionPerformed(ActionEvent e) {
-		event(e);
-	}	
-	public void focusGained(FocusEvent e) {
-		event(e);
-	}
-	public void focusLost(FocusEvent e) {
-		event(e);
-	}	
-	public void event(AWTEvent e){
-		if(e.getSource() instanceof Component) 
-			registerValue( (Component)e.getSource() );
-	}
-	public void valueChanged(ListSelectionEvent e) {
-		if(e.getSource() instanceof Component) 
-			registerValue( (Component)e.getSource() );
-	}
+    public void actionPerformed(ActionEvent e) {
+        event(e);
+    }
+    public void focusGained(FocusEvent e) {
+        event(e);
+    }
+    public void focusLost(FocusEvent e) {
+        event(e);
+    }
+    public void event(AWTEvent e){
+        if(e.getSource() instanceof Component)
+            registerValue( (Component)e.getSource() );
+    }
+    public void valueChanged(ListSelectionEvent e) {
+        if(e.getSource() instanceof Component)
+            registerValue( (Component)e.getSource() );
+    }
 
-	public void registerListener(Component c){
-		/**
-		 * JToggleButton
-		 * JCheckBox
-		 * JRadioButton
-		 */
-		if(c instanceof JToggleButton){
-			JToggleButton o = (JToggleButton) c;
-			o.addActionListener( this );
-		}		
-		/**
-		 * JEditorPane
-		 * JTextArea
-		 * JTextField
-		 */
-		else if(c instanceof JTextComponent){
-			JTextComponent o = (JTextComponent) c;
-			o.addFocusListener( this );
-		}
-		/**
-		 * JList
-		 */
-		else if(c instanceof JList){
-			JList o = (JList) c;
-			o.addListSelectionListener( this );
-		}
-	}
+    public void registerListener(Component c){
+        /**
+         * JToggleButton
+         * JCheckBox
+         * JRadioButton
+         */
+        if(c instanceof JToggleButton){
+            JToggleButton o = (JToggleButton) c;
+            o.addActionListener( this );
+        }
+        /**
+         * JEditorPane
+         * JTextArea
+         * JTextField
+         */
+        else if(c instanceof JTextComponent){
+            JTextComponent o = (JTextComponent) c;
+            o.addFocusListener( this );
+        }
+        /**
+         * JList
+         */
+        else if(c instanceof JList){
+            JList o = (JList) c;
+            o.addListSelectionListener( this );
+        }
+    }
 
-	/**
-	 * Registers the state of the event source
-	 * @param e is the event
-	 */
-	public void registerValue(Component c) {
-		/**
-		 * JToggleButton
-		 * JCheckBox
-		 * JRadioButton
-		 */
-		if(c instanceof JToggleButton){
-			JToggleButton o = (JToggleButton) c;
-			values.put( o.getName() , o.isSelected() );
-		}		
-		/**
-		 * JEditorPane
-		 * JTextArea
-		 * JTextField
-		 */
-		else if(c instanceof JTextComponent){
-			JTextComponent o = (JTextComponent) c;
-			values.put( o.getName() , o.getText() );
-		}
-		/**
-		 * JList
-		 */
-		else if(c instanceof JList){
-			JList o = (JList) c;
-			values.put( o.getName() , o.getSelectedValue() );
-		}
-	}
+    /**
+     * Registers the state of the event source
+     * @param	c 	is the event
+     */
+    public void registerValue(Component c) {
+        /**
+         * JToggleButton
+         * JCheckBox
+         * JRadioButton
+         */
+        if(c instanceof JToggleButton){
+            JToggleButton o = (JToggleButton) c;
+            values.put( o.getName() , o.isSelected() );
+        }
+        /**
+         * JEditorPane
+         * JTextArea
+         * JTextField
+         */
+        else if(c instanceof JTextComponent){
+            JTextComponent o = (JTextComponent) c;
+            values.put( o.getName() , o.getText() );
+        }
+        /**
+         * JList
+         */
+        else if(c instanceof JList){
+            JList o = (JList) c;
+            values.put( o.getName() , o.getSelectedValue() );
+        }
+    }
 }
diff --git a/test/zutil/struct/BloomFilterTest.java b/test/zutil/struct/BloomFilterTest.java
index 2dfa9fb..0f8ec82 100755
--- a/test/zutil/struct/BloomFilterTest.java
+++ b/test/zutil/struct/BloomFilterTest.java
@@ -70,7 +70,7 @@ public class BloomFilterTest extends TestCase {
 					falsePositives++;
 				}
 			}
-			double expectedFP = bf.falsePosetiveProbability();
+			double expectedFP = bf.falsePositiveProbability();
 			double actualFP = (double) falsePositives / (double) addCount;
 			System.out.println("Got " + falsePositives
 					+ " false positives out of " + addCount + " added items, rate = "