From cf5ddaf81c3cf41be90d2768253df088cabd0c14 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 4 May 2017 23:36:04 +0200 Subject: [PATCH] Performed code review and Javadoc review. --- src/fr/devinsy/util/DataFile.java | 79 +++++++-- src/fr/devinsy/util/DataFiles.java | 31 +++- src/fr/devinsy/util/DateHelper.java | 92 +++++++++-- src/fr/devinsy/util/DateTimeHelper.java | 28 +++- src/fr/devinsy/util/Digester.java | 19 ++- src/fr/devinsy/util/FileCopier.java | 11 +- src/fr/devinsy/util/FileIterator.java | 96 ++++++++--- src/fr/devinsy/util/FileIteratorState.java | 36 +++-- src/fr/devinsy/util/FileTools.java | 150 ++++++++++++++---- src/fr/devinsy/util/Fraction.java | 49 +++++- .../util/InternetProxyConfiguration.java | 77 ++++++--- src/fr/devinsy/util/SimpleAveragemeter.java | 28 ++-- src/fr/devinsy/util/SimpleChronometer.java | 22 ++- src/fr/devinsy/util/StacktraceWriter.java | 12 +- src/fr/devinsy/util/ToolBox.java | 34 +++- test/FileIteratorSandbox.java | 141 ++++++++-------- test/Foot1Test.java | 18 +++ test/fr/devinsy/util/FileToolsTest.java | 30 ++-- 18 files changed, 703 insertions(+), 250 deletions(-) diff --git a/src/fr/devinsy/util/DataFile.java b/src/fr/devinsy/util/DataFile.java index 475ee75..65b3be6 100755 --- a/src/fr/devinsy/util/DataFile.java +++ b/src/fr/devinsy/util/DataFile.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -29,30 +29,39 @@ public class DataFile public static int DEFAULT_SIZE = 0; // - protected int id; - protected int contentId; - protected String name; - protected long size; - protected byte[] data; - protected String creationDate; - protected String creationUser; + private int id; + private int contentId; + private String name; + private long size; + private byte[] data; + private String creationDate; + private String creationUser; /** - * + * Instantiates a new data file. */ public DataFile() { this.id = NOID; this.contentId = NOID; this.name = null; - this.size = this.DEFAULT_SIZE; + this.size = DEFAULT_SIZE; this.data = null; this.creationDate = null; this.creationUser = null; } /** - * + * Instantiates a new data file. + * + * @param contentId + * the content id + * @param name + * the name + * @param size + * the size + * @param data + * the data */ public DataFile(final int contentId, final String name, final long size, final byte[] data) { @@ -66,7 +75,14 @@ public class DataFile } /** - * + * Instantiates a new data file. + * + * @param name + * the name + * @param size + * the size + * @param data + * the data */ public DataFile(final String name, final long size, final byte[] data) { @@ -80,7 +96,9 @@ public class DataFile } /** + * Content id. * + * @return the int */ public int contentId() { @@ -93,7 +111,9 @@ public class DataFile } /** - * + * Creation date. + * + * @return the string */ public String creationDate() { @@ -106,7 +126,9 @@ public class DataFile } /** + * Creation user. * + * @return the string */ public String creationUser() { @@ -119,7 +141,9 @@ public class DataFile } /** + * Data. * + * @return the byte[] */ public byte[] data() { @@ -132,7 +156,9 @@ public class DataFile } /** + * Id. * + * @return the int */ public int id() { @@ -145,7 +171,9 @@ public class DataFile } /** + * Name. * + * @return the string */ public String name() { @@ -158,7 +186,10 @@ public class DataFile } /** + * Sets the content id. * + * @param contentId + * the new content id */ public void setContentId(final int contentId) { @@ -166,7 +197,10 @@ public class DataFile } /** + * Sets the creation date. * + * @param creationDate + * the new creation date */ public void setCreationDate(final String creationDate) { @@ -181,7 +215,10 @@ public class DataFile } /** + * Sets the creation user. * + * @param creationUser + * the new creation user */ public void setCreationUser(final String creationUser) { @@ -196,7 +233,10 @@ public class DataFile } /** + * Sets the data. * + * @param data + * the new data */ public void setData(final byte[] data) { @@ -204,7 +244,10 @@ public class DataFile } /** + * Sets the id. * + * @param id + * the new id */ public void setId(final int id) { @@ -212,7 +255,10 @@ public class DataFile } /** + * Sets the name. * + * @param name + * the new name */ public void setName(final String name) { @@ -227,7 +273,10 @@ public class DataFile } /** + * Sets the size. * + * @param size + * the new size */ public void setSize(final long size) { @@ -242,7 +291,9 @@ public class DataFile } /** + * Size. * + * @return the long */ public long size() { diff --git a/src/fr/devinsy/util/DataFiles.java b/src/fr/devinsy/util/DataFiles.java index 5cd7ea9..784e549 100755 --- a/src/fr/devinsy/util/DataFiles.java +++ b/src/fr/devinsy/util/DataFiles.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -23,15 +23,14 @@ import java.util.ArrayList; /** * This class is a collection of DataFile objects whit some specific methods. * - * @author Christian Pierre MOMON + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class DataFiles extends ArrayList { private static final long serialVersionUID = -4584622422555785456L; /** - * - * + * Instantiates a new data files. */ public DataFiles() { @@ -39,8 +38,10 @@ public class DataFiles extends ArrayList } /** + * Instantiates a new data files. * * @param source + * the source */ public DataFiles(final DataFiles source) { @@ -48,7 +49,11 @@ public class DataFiles extends ArrayList } /** + * Gets the by content id. * + * @param id + * the id + * @return the by content id */ public DataFiles getByContentId(final int id) { @@ -69,7 +74,11 @@ public class DataFiles extends ArrayList } /** + * Gets the by id. * + * @param id + * the id + * @return the by id */ public DataFile getById(final int id) { @@ -105,7 +114,11 @@ public class DataFiles extends ArrayList } /** + * Gets the by index. * + * @param index + * the index + * @return the by index */ public DataFile getByIndex(final int index) { @@ -118,7 +131,11 @@ public class DataFiles extends ArrayList } /** + * Gets the by name. * + * @param name + * the name + * @return the by name */ public DataFile getByName(final String name) { @@ -160,8 +177,8 @@ public class DataFiles extends ArrayList return result; } - /** - * + /* (non-Javadoc) + * @see java.util.AbstractCollection#toString() */ @Override public String toString() diff --git a/src/fr/devinsy/util/DateHelper.java b/src/fr/devinsy/util/DateHelper.java index 53a96c4..e28c456 100755 --- a/src/fr/devinsy/util/DateHelper.java +++ b/src/fr/devinsy/util/DateHelper.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -45,7 +45,11 @@ public class DateHelper private static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$"; /** - * + * American format. + * + * @param time + * the time + * @return the string */ public static String americanFormat(final Calendar time) { @@ -65,7 +69,11 @@ public class DateHelper } /** - * + * European format. + * + * @param time + * the time + * @return the string */ public static String europeanFormat(final Calendar time) { @@ -85,7 +93,11 @@ public class DateHelper } /** - * + * Checks if is american format. + * + * @param date + * the date + * @return true, if is american format */ public static boolean isAmericanFormat(final String date) { @@ -105,7 +117,11 @@ public class DateHelper } /** - * + * Checks if is european format. + * + * @param date + * the date + * @return true, if is european format */ public static boolean isEuropeanFormat(final String date) { @@ -125,7 +141,11 @@ public class DateHelper } /** - * + * Checks if is ISO format. + * + * @param date + * the date + * @return true, if is ISO format */ public static boolean isISOFormat(final String date) { @@ -145,7 +165,11 @@ public class DateHelper } /** - * + * ISO format. + * + * @param time + * the time + * @return the string */ public static String ISOFormat(final Calendar time) { @@ -165,7 +189,11 @@ public class DateHelper } /** - * + * Checks if is raw format. + * + * @param date + * the date + * @return true, if is raw format */ public static boolean isRawFormat(final String date) { @@ -185,7 +213,11 @@ public class DateHelper } /** - * + * Checks if is valid date. + * + * @param date + * the date + * @return true, if is valid date */ public static boolean isValidDate(final String date) { @@ -205,7 +237,11 @@ public class DateHelper } /** - * + * Parses the american date. + * + * @param date + * the date + * @return the calendar */ public static Calendar parseAmericanDate(final String date) { @@ -229,6 +265,10 @@ public class DateHelper /** * Note: European parsing test made before the American parsing one. + * + * @param date + * the date + * @return the calendar */ public static Calendar parseDate(final String date) { @@ -260,7 +300,11 @@ public class DateHelper } /** - * + * Parses the european date. + * + * @param date + * the date + * @return the calendar */ public static Calendar parseEuropeanDate(final String date) { @@ -283,7 +327,11 @@ public class DateHelper } /** - * + * Parses the ISO date. + * + * @param date + * the date + * @return the calendar */ public static Calendar parseISODate(final String date) { @@ -306,7 +354,11 @@ public class DateHelper } /** - * + * Parses the raw date. + * + * @param date + * the date + * @return the calendar */ public static Calendar parseRawDate(final String date) { @@ -329,7 +381,11 @@ public class DateHelper } /** - * + * Raw format. + * + * @param time + * the time + * @return the string */ public static String rawFormat(final Calendar time) { @@ -349,7 +405,11 @@ public class DateHelper } /** - * + * Short european format. + * + * @param time + * the time + * @return the string */ public static String shortEuropeanFormat(final Calendar time) { diff --git a/src/fr/devinsy/util/DateTimeHelper.java b/src/fr/devinsy/util/DateTimeHelper.java index 74dce8f..afcbd01 100755 --- a/src/fr/devinsy/util/DateTimeHelper.java +++ b/src/fr/devinsy/util/DateTimeHelper.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -39,7 +39,11 @@ public class DateTimeHelper private static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$"; /** - * + * American format. + * + * @param time + * the time + * @return the string */ public static String americanFormat(final Calendar time) { @@ -60,7 +64,11 @@ public class DateTimeHelper } /** - * + * European format. + * + * @param time + * the time + * @return the string */ public static String europeanFormat(final Calendar time) { @@ -81,7 +89,11 @@ public class DateTimeHelper } /** - * + * ISO format. + * + * @param time + * the time + * @return the string */ public static String ISOFormat(final Calendar time) { @@ -102,7 +114,11 @@ public class DateTimeHelper } /** - * + * Raw format. + * + * @param time + * the time + * @return the string */ public static String rawFormat(final Calendar time) { diff --git a/src/fr/devinsy/util/Digester.java b/src/fr/devinsy/util/Digester.java index 367daa5..cd735a0 100644 --- a/src/fr/devinsy/util/Digester.java +++ b/src/fr/devinsy/util/Digester.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2006, 2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2006,2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -32,8 +32,17 @@ import java.security.MessageDigest; @Deprecated public class Digester { + /** - * "SHA-1", "MD5", "SHA-256", and "SHA-512" + * "SHA-1", "MD5", "SHA-256", and "SHA-512". + * + * @param digestMethod + * the digest method + * @param file + * the file + * @return the string + * @throws Exception + * the exception */ public static String computeHash(final String digestMethod, final File file) throws Exception { @@ -98,7 +107,11 @@ public class Digester } /** + * Human readable digest. * + * @param digest + * the digest + * @return the string */ public static String humanReadableDigest(final byte[] digest) { diff --git a/src/fr/devinsy/util/FileCopier.java b/src/fr/devinsy/util/FileCopier.java index 3c99aaf..eddb2a0 100644 --- a/src/fr/devinsy/util/FileCopier.java +++ b/src/fr/devinsy/util/FileCopier.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -30,7 +30,14 @@ public class FileCopier public static final int BUFFER_SIZE = 4 * 1024; /** + * Copy. * + * @param source + * the source + * @param target + * the target + * @throws Exception + * the exception */ public static void copy(final File source, final File target) throws Exception { diff --git a/src/fr/devinsy/util/FileIterator.java b/src/fr/devinsy/util/FileIterator.java index 041affa..e96d5da 100644 --- a/src/fr/devinsy/util/FileIterator.java +++ b/src/fr/devinsy/util/FileIterator.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -24,19 +24,22 @@ import java.util.Vector; import java.util.regex.Pattern; /** - * + * The Class FileIterator. */ public class FileIterator extends Vector implements Iterator { private static final long serialVersionUID = 8790133455427427766L; - protected int currentDepth; - protected Pattern pattern; - protected File previous; - protected boolean followLinks; + private int currentDepth; + private Pattern pattern; + private File previous; + private boolean followLinks; /** - * + * Instantiates a new file iterator. + * + * @param root + * the root */ public FileIterator(final File root) { @@ -57,7 +60,14 @@ public class FileIterator extends Vector implements Iterator< } /** - * + * Instantiates a new file iterator. + * + * @param root + * the root + * @param filter + * the filter + * @param followLinks + * the follow links */ public FileIterator(final File root, final String filter, final boolean followLinks) { @@ -99,7 +109,14 @@ public class FileIterator extends Vector implements Iterator< } /** - * + * Instantiates a new file iterator. + * + * @param pathnames + * the pathnames + * @param filter + * the filter + * @param followLinks + * the follow links */ public FileIterator(final String[] pathnames, final String filter, final boolean followLinks) { @@ -109,7 +126,9 @@ public class FileIterator extends Vector implements Iterator< } /** + * Current file. * + * @return the file */ public File currentFile() { @@ -122,7 +141,9 @@ public class FileIterator extends Vector implements Iterator< } /** + * Current state. * + * @return the file iterator state */ protected FileIteratorState currentState() { @@ -135,7 +156,9 @@ public class FileIterator extends Vector implements Iterator< } /** + * Directory final countdown. * + * @return the int */ public int directoryFinalCountdown() { @@ -175,7 +198,9 @@ public class FileIterator extends Vector implements Iterator< } /** + * Filter. * + * @return the string */ protected String filter() { @@ -195,7 +220,9 @@ public class FileIterator extends Vector implements Iterator< } /** + * Final countdown. * + * @return the int */ public int finalCountdown() { @@ -212,7 +239,11 @@ public class FileIterator extends Vector implements Iterator< } /** + * Follow. * + * @param file + * the file + * @return true, if successful */ public boolean follow(final File file) { @@ -243,8 +274,8 @@ public class FileIterator extends Vector implements Iterator< return result; } - /** - * + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() */ @Override public boolean hasNext() @@ -258,7 +289,14 @@ public class FileIterator extends Vector implements Iterator< } /** - * + * Inits the. + * + * @param pathnames + * the pathnames + * @param filter + * the filter + * @param followLinks + * the follow links */ protected void init(final String[] pathnames, final String filter, final boolean followLinks) { @@ -272,8 +310,8 @@ public class FileIterator extends Vector implements Iterator< shift(); } - /** - * + /* (non-Javadoc) + * @see java.util.Iterator#next() */ @Override public File next() @@ -297,7 +335,9 @@ public class FileIterator extends Vector implements Iterator< } /** + * Pattern. * + * @return the pattern */ public Pattern pattern() { @@ -310,7 +350,7 @@ public class FileIterator extends Vector implements Iterator< } /** - * + * Pop. */ public void pop() { @@ -319,7 +359,10 @@ public class FileIterator extends Vector implements Iterator< } /** + * Push. * + * @param file + * the file */ public void push(final File file) { @@ -330,8 +373,8 @@ public class FileIterator extends Vector implements Iterator< } } - /** - * + /* (non-Javadoc) + * @see java.util.Iterator#remove() */ @Override public void remove() @@ -344,7 +387,7 @@ public class FileIterator extends Vector implements Iterator< } /** - * + * Reset. */ public void reset() { @@ -362,7 +405,10 @@ public class FileIterator extends Vector implements Iterator< } /** + * Sets the filter. * + * @param filter + * the new filter */ protected void setFilter(final String filter) { @@ -416,22 +462,28 @@ public class FileIterator extends Vector implements Iterator< } } - /** - * + /* (non-Javadoc) + * @see java.util.Vector#toString() */ @Override public String toString() { String result; - result = "[depth=" + this.currentDepth + "][index=" + this.get(this.currentDepth).currentIndex() + "/" + this.get(this.currentDepth).files.length + "]"; + result = "[depth=" + this.currentDepth + "][index=" + this.get(this.currentDepth).currentIndex() + "/" + this.get(this.currentDepth).files().length + "]"; // return result; } /** + * Checks if is link. * + * @param file + * the file + * @return true, if is link + * @throws Exception + * the exception */ public static boolean isLink(final File file) throws Exception { diff --git a/src/fr/devinsy/util/FileIteratorState.java b/src/fr/devinsy/util/FileIteratorState.java index f04f08c..73dd39e 100644 --- a/src/fr/devinsy/util/FileIteratorState.java +++ b/src/fr/devinsy/util/FileIteratorState.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2010, 2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -26,11 +26,14 @@ import java.util.Iterator; */ public class FileIteratorState implements Iterator { - protected File[] files; - protected int currentIndex; + private File[] files; + private int currentIndex; /** - * + * Instantiates a new file iterator state. + * + * @param files + * the files */ public FileIteratorState(final File[] files) { @@ -49,6 +52,9 @@ public class FileIteratorState implements Iterator /** * Useful for the depth zero, otherwise parent path is lost. + * + * @param pathnames + * the pathnames */ public FileIteratorState(final String[] pathnames) { @@ -63,7 +69,9 @@ public class FileIteratorState implements Iterator } /** + * Current file. * + * @return the file */ protected File currentFile() { @@ -83,7 +91,9 @@ public class FileIteratorState implements Iterator } /** + * Current index. * + * @return the int */ protected int currentIndex() { @@ -96,7 +106,9 @@ public class FileIteratorState implements Iterator } /** + * Files. * + * @return the file[] */ protected File[] files() { @@ -108,8 +120,8 @@ public class FileIteratorState implements Iterator return result; } - /** - * + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() */ @Override public boolean hasNext() @@ -129,8 +141,8 @@ public class FileIteratorState implements Iterator return result; } - /** - * + /* (non-Javadoc) + * @see java.util.Iterator#next() */ @Override public File next() @@ -144,8 +156,8 @@ public class FileIteratorState implements Iterator return result; } - /** - * + /* (non-Javadoc) + * @see java.util.Iterator#remove() */ @Override public void remove() @@ -153,7 +165,7 @@ public class FileIteratorState implements Iterator } /** - * + * Reset. */ public void reset() { diff --git a/src/fr/devinsy/util/FileTools.java b/src/fr/devinsy/util/FileTools.java index 6c9eb3b..105ce81 100644 --- a/src/fr/devinsy/util/FileTools.java +++ b/src/fr/devinsy/util/FileTools.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2008-2015 Christian Pierre MOMON +/* + * Copyright (C) 2008-2015,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -35,6 +35,7 @@ import fr.devinsy.util.strings.StringList; import fr.devinsy.util.strings.StringListUtils; /** + * The Class FileTools. * * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ @@ -43,11 +44,12 @@ public class FileTools public static final String DEFAULT_CHARSET_NAME = "UTF-8"; /** - * + * Adds the before extension. * * @param fileName * Source. - * + * @param addition + * the addition * @return Extension value or null. */ public static String addBeforeExtension(final String fileName, final String addition) @@ -83,11 +85,12 @@ public class FileTools } /** - * + * Adds the to name. * * @param file * Source. - * + * @param addition + * the addition * @return Extension value or null. */ public static File addToName(final File file, final String addition) @@ -149,9 +152,8 @@ public class FileTools *
  • getExtension("abc.efg") = "efg"
  • * * - * @param file - * Source. - * + * @param fileName + * the file name * @return Extension value or null. * @deprecated See * org.apache.commons.io.FilenameUtils.getExtension @@ -183,10 +185,13 @@ public class FileTools } /** + * Load. * - * @param file - * @return + * @param source + * the source + * @return the string * @throws IOException + * Signals that an I/O exception has occurred. */ public static String load(final File source) throws IOException { @@ -199,9 +204,15 @@ public class FileTools } /** + * Load. * - * @param file + * @param source + * the source + * @param charsetName + * the charset name + * @return the string * @throws IOException + * Signals that an I/O exception has occurred. */ public static String load(final File source, final String charsetName) throws IOException { @@ -214,10 +225,13 @@ public class FileTools } /** + * Load. * - * @param file - * @return + * @param source + * the source + * @return the string * @throws IOException + * Signals that an I/O exception has occurred. */ public static String load(final URL source) throws IOException { @@ -230,9 +244,15 @@ public class FileTools } /** + * Load. * - * @param file + * @param source + * the source + * @param charsetName + * the charset name + * @return the string * @throws IOException + * Signals that an I/O exception has occurred. */ public static String load(final URL source, final String charsetName) throws IOException { @@ -250,9 +270,13 @@ public class FileTools } /** + * Load string list. * - * @param file + * @param source + * the source + * @return the string list * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringList loadStringList(final File source) throws IOException { @@ -265,9 +289,15 @@ public class FileTools } /** + * Load string list. * * @param file + * the file + * @param charsetName + * the charset name + * @return the string list * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringList loadStringList(final File file, final String charsetName) throws IOException { @@ -280,9 +310,13 @@ public class FileTools } /** + * Load to string buffer. * - * @param file + * @param source + * the source + * @return the string buffer * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringBuffer loadToStringBuffer(final File source) throws IOException { @@ -295,9 +329,15 @@ public class FileTools } /** + * Load to string buffer. * * @param file + * the file + * @param charsetName + * the charset name + * @return the string buffer * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringBuffer loadToStringBuffer(final File file, final String charsetName) throws IOException { @@ -345,9 +385,13 @@ public class FileTools } /** + * Load to string list. * - * @param file + * @param source + * the source + * @return the string list * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringList loadToStringList(final File source) throws IOException { @@ -360,9 +404,15 @@ public class FileTools } /** + * Load to string list. * * @param file + * the file + * @param charsetName + * the charset name + * @return the string list * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringList loadToStringList(final File file, final String charsetName) throws IOException { @@ -410,10 +460,13 @@ public class FileTools } /** + * Load to string list. * - * @param file - * @return + * @param source + * the source + * @return the string list * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringList loadToStringList(final URL source) throws IOException { @@ -426,9 +479,15 @@ public class FileTools } /** + * Load to string list. * - * @param file + * @param source + * the source + * @param charsetName + * the charset name + * @return the string list * @throws IOException + * Signals that an I/O exception has occurred. */ public static StringList loadToStringList(final URL source, final String charsetName) throws IOException { @@ -442,9 +501,16 @@ public class FileTools } /** + * Read. * - * @param file + * @param out + * the out + * @param is + * the is + * @param charsetName + * the charset name * @throws IOException + * Signals that an I/O exception has occurred. */ public static void read(final StringBuffer out, final InputStream is, final String charsetName) throws IOException { @@ -487,11 +553,11 @@ public class FileTools } /** + * Removes the extension. * * @param source - * @param extension - * @return - * + * the source + * @return the string * @deprecated See * org.apache.commons.io.FilenameUtils.removeExtension */ @@ -524,10 +590,16 @@ public class FileTools } /** + * Save. * * @param file - * @throws FileNotFoundException + * the file + * @param source + * the source * @throws UnsupportedEncodingException + * the unsupported encoding exception + * @throws FileNotFoundException + * the file not found exception */ public static void save(final File file, final String source) throws UnsupportedEncodingException, FileNotFoundException { @@ -548,10 +620,16 @@ public class FileTools } /** + * Save. * * @param file - * @throws FileNotFoundException + * the file + * @param source + * the source * @throws UnsupportedEncodingException + * the unsupported encoding exception + * @throws FileNotFoundException + * the file not found exception */ public static void save(final File file, final StringBuffer source) throws UnsupportedEncodingException, FileNotFoundException { @@ -559,10 +637,16 @@ public class FileTools } /** + * Save. * * @param file - * @throws FileNotFoundException + * the file + * @param source + * the source * @throws UnsupportedEncodingException + * the unsupported encoding exception + * @throws FileNotFoundException + * the file not found exception */ public static void save(final File file, final StringList source) throws UnsupportedEncodingException, FileNotFoundException { @@ -570,10 +654,13 @@ public class FileTools } /** + * Sets the extension. * * @param source + * the source * @param extension - * @return + * the extension + * @return the file */ public static File setExtension(final File source, final String extension) { @@ -593,10 +680,13 @@ public class FileTools } /** + * Sets the extension. * * @param source + * the source * @param extension - * @return + * the extension + * @return the string */ public static String setExtension(final String source, final String extension) { diff --git a/src/fr/devinsy/util/Fraction.java b/src/fr/devinsy/util/Fraction.java index 336b4d0..75e094b 100644 --- a/src/fr/devinsy/util/Fraction.java +++ b/src/fr/devinsy/util/Fraction.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2009-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2009-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -25,11 +25,16 @@ package fr.devinsy.util; */ public class Fraction { - protected long numerator; - protected long denominator; + private long numerator; + private long denominator; /** + * Instantiates a new fraction. * + * @param numerator + * the numerator + * @param denominator + * the denominator */ public Fraction(final long numerator, final long denominator) { @@ -38,7 +43,9 @@ public class Fraction } /** + * Denominator. * + * @return the long */ public long denominator() { @@ -51,7 +58,9 @@ public class Fraction } /** + * Numerator. * + * @return the long */ public long numerator() { @@ -64,7 +73,11 @@ public class Fraction } /** + * Percentage. * + * @return the long + * @throws Exception + * the exception */ public long percentage() throws Exception { @@ -77,7 +90,9 @@ public class Fraction } /** + * Percentage full string. * + * @return the string */ public String percentageFullString() { @@ -90,7 +105,9 @@ public class Fraction } /** + * Percentage string. * + * @return the string */ public String percentageString() { @@ -102,8 +119,8 @@ public class Fraction return result; } - /** - * + /* (non-Javadoc) + * @see java.lang.Object#toString() */ @Override public String toString() @@ -117,7 +134,15 @@ public class Fraction } /** + * Percentage. * + * @param numerator + * the numerator + * @param denominator + * the denominator + * @return the long + * @throws Exception + * the exception */ public static long percentage(final long numerator, final long denominator) throws Exception { @@ -137,7 +162,13 @@ public class Fraction } /** + * Percentage full string. * + * @param numerator + * the numerator + * @param denominator + * the denominator + * @return the string */ public static String percentageFullString(final long numerator, final long denominator) { @@ -150,7 +181,13 @@ public class Fraction } /** + * Percentage string. * + * @param numerator + * the numerator + * @param denominator + * the denominator + * @return the string */ public static String percentageString(final long numerator, final long denominator) { diff --git a/src/fr/devinsy/util/InternetProxyConfiguration.java b/src/fr/devinsy/util/InternetProxyConfiguration.java index 8933c36..2cec98b 100755 --- a/src/fr/devinsy/util/InternetProxyConfiguration.java +++ b/src/fr/devinsy/util/InternetProxyConfiguration.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2009-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2009-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -19,18 +19,17 @@ package fr.devinsy.util; /** - * + * The Class InternetProxyConfiguration. */ public class InternetProxyConfiguration { - // - protected String host; - protected int port; - protected String login; - protected String password; + private String host; + private int port; + private String login; + private String password; - /** - * + /** + * Instantiates a new internet proxy configuration. */ public InternetProxyConfiguration() { @@ -40,8 +39,17 @@ public class InternetProxyConfiguration this.password = ""; } - /** - * + /** + * Instantiates a new internet proxy configuration. + * + * @param host + * the host + * @param port + * the port + * @param login + * the login + * @param password + * the password */ public InternetProxyConfiguration(final String host, final int port, final String login, final String password) { @@ -79,8 +87,19 @@ public class InternetProxyConfiguration } } - /** - * + /** + * Instantiates a new internet proxy configuration. + * + * @param host + * the host + * @param port + * the port + * @param login + * the login + * @param password + * the password + * @throws Exception + * the exception */ public InternetProxyConfiguration(final String host, final String port, final String login, final String password) throws Exception { @@ -133,8 +152,10 @@ public class InternetProxyConfiguration } } - /** - * + /** + * Host. + * + * @return the string */ public String host() { @@ -147,7 +168,9 @@ public class InternetProxyConfiguration } /** + * Checks if is initialized. * + * @return true, if is initialized */ public boolean isInitialized() { @@ -166,8 +189,10 @@ public class InternetProxyConfiguration return result; } - /** - * + /** + * Login. + * + * @return the string */ public String login() { @@ -179,8 +204,10 @@ public class InternetProxyConfiguration return result; } - /** - * + /** + * Password. + * + * @return the string */ public String password() { @@ -192,8 +219,10 @@ public class InternetProxyConfiguration return result; } - /** - * + /** + * Port. + * + * @return the int */ public int port() { @@ -205,8 +234,8 @@ public class InternetProxyConfiguration return result; } - /** - * + /* (non-Javadoc) + * @see java.lang.Object#toString() */ @Override public String toString() diff --git a/src/fr/devinsy/util/SimpleAveragemeter.java b/src/fr/devinsy/util/SimpleAveragemeter.java index 8fe11dd..beab7f3 100755 --- a/src/fr/devinsy/util/SimpleAveragemeter.java +++ b/src/fr/devinsy/util/SimpleAveragemeter.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2009-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2009-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -24,13 +24,12 @@ package fr.devinsy.util; */ public class SimpleAveragemeter { - // - protected long sum; - protected long cardinal; - protected long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond. + private long sum; + private long cardinal; + private long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond. /** - * + * Instantiates a new simple averagemeter. */ public SimpleAveragemeter() { @@ -38,7 +37,10 @@ public class SimpleAveragemeter } /** + * Adds the. * + * @param value + * the value */ synchronized public void add(final long value) { @@ -63,7 +65,9 @@ public class SimpleAveragemeter } /** + * Average. * + * @return the long */ synchronized public long average() { @@ -83,7 +87,9 @@ public class SimpleAveragemeter } /** + * Cardinal. * + * @return the long */ public long cardinal() { @@ -96,7 +102,7 @@ public class SimpleAveragemeter } /** - * + * Reset. */ synchronized public void reset() { @@ -104,8 +110,8 @@ public class SimpleAveragemeter this.cardinal = 0; } - /** - * + /* (non-Javadoc) + * @see java.lang.Object#toString() */ @Override public String toString() @@ -119,7 +125,9 @@ public class SimpleAveragemeter } /** + * Value. * + * @return the long */ public long value() { diff --git a/src/fr/devinsy/util/SimpleChronometer.java b/src/fr/devinsy/util/SimpleChronometer.java index 9455d1f..5e75cbd 100755 --- a/src/fr/devinsy/util/SimpleChronometer.java +++ b/src/fr/devinsy/util/SimpleChronometer.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -21,15 +21,15 @@ package fr.devinsy.util; import java.util.Date; /** - * + * The Class SimpleChronometer. */ public class SimpleChronometer { // - protected long firstTime; + private long firstTime; /** - * + * Instantiates a new simple chronometer. */ public SimpleChronometer() { @@ -37,7 +37,9 @@ public class SimpleChronometer } /** + * Interval. * + * @return the long */ public long interval() { @@ -50,7 +52,7 @@ public class SimpleChronometer } /** - * + * Reset. */ public void reset() { @@ -59,6 +61,10 @@ public class SimpleChronometer /** * TO BE COMPLETED. + * + * @param interval + * the interval + * @return the string */ public static String humanString(final long interval) { @@ -95,7 +101,11 @@ public class SimpleChronometer } /** + * Short human string. * + * @param interval + * the interval + * @return the string */ public static String shortHumanString(final long interval) { diff --git a/src/fr/devinsy/util/StacktraceWriter.java b/src/fr/devinsy/util/StacktraceWriter.java index 3b474d7..1ce92c5 100644 --- a/src/fr/devinsy/util/StacktraceWriter.java +++ b/src/fr/devinsy/util/StacktraceWriter.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2010, 2013-2016 Christian Pierre MOMON +/* + * Copyright (C) 2010,2013-2016,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -22,13 +22,21 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; /** + * The Class StacktraceWriter. + * * @deprecated use SLF4J.Logger.error("blabla", exception) method * or the ExceptionUtils.getStackTrace(throwable). */ @Deprecated public class StacktraceWriter { + /** + * To string. + * + * @param exception + * the exception + * @return the string * @deprecated use SLF4J.Logger.error("blabla", exception) * method or the ExceptionUtils.getStackTrace(throwable). */ diff --git a/src/fr/devinsy/util/ToolBox.java b/src/fr/devinsy/util/ToolBox.java index adc4b49..071e527 100644 --- a/src/fr/devinsy/util/ToolBox.java +++ b/src/fr/devinsy/util/ToolBox.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON +/* + * Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -27,12 +27,19 @@ import org.apache.commons.lang3.StringUtils; import fr.devinsy.util.strings.StringList; /** + * The Class ToolBox. * - * @author christian.momon@devinsy.fr + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class ToolBox { - + /** + * Clean. + * + * @param source + * the source + * @return the string + */ public static String clean(final String source) { String result; @@ -126,10 +133,13 @@ public class ToolBox } /** + * Index of. * * @param pattern + * the pattern * @param source - * @return + * the source + * @return the int */ public static int indexOf(final String pattern, final List source) { @@ -172,10 +182,13 @@ public class ToolBox } /** + * Matches any. * * @param string + * the string * @param targets - * @return + * the targets + * @return true, if successful */ public static boolean matchesAny(final String string, final String... targets) { @@ -218,8 +231,11 @@ public class ToolBox } /** + * Sort. * - * @return + * @param source + * the source + * @return the double[] */ public static Double[] sort(final Set source) { @@ -296,9 +312,11 @@ public class ToolBox } /** + * To string. * * @param source - * @return + * the source + * @return the string */ public static String toString(final String source) { diff --git a/test/FileIteratorSandbox.java b/test/FileIteratorSandbox.java index 08452c6..6da7ea8 100644 --- a/test/FileIteratorSandbox.java +++ b/test/FileIteratorSandbox.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2013 Christian Pierre MOMON +/* + * Copyright (C) 2013,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -26,86 +26,89 @@ import org.slf4j.LoggerFactory; import fr.devinsy.util.FileIterator; /** - * + * The Class FileIteratorSandbox. */ public class FileIteratorSandbox { - private static final Logger logger; + private static Logger logger; - static - { - // Initialize logger. - org.apache.log4j.BasicConfigurator.configure(); - org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG); + static + { + // Initialize logger. + org.apache.log4j.BasicConfigurator.configure(); + org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG); - logger = LoggerFactory.getLogger(FileIteratorSandbox.class); + logger = LoggerFactory.getLogger(FileIteratorSandbox.class); - // - org.apache.log4j.Logger defaultLogger = org.apache.log4j.Logger.getRootLogger(); - defaultLogger.removeAllAppenders(); - defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n"))); + // + org.apache.log4j.Logger defaultLogger = org.apache.log4j.Logger.getRootLogger(); + defaultLogger.removeAllAppenders(); + defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n"))); - // - logger.debug("Log initialized."); - } + // + logger.debug("Log initialized."); + } - /** + /** + * The main method. * + * @param args + * the arguments */ - public static void main(final String[] args) - { - test(); - } + public static void main(final String[] args) + { + test(); + } - /** - * + /** + * Test. */ - protected static void test() - { - System.out.println("user.dir=" + System.getProperty("user.dir")); + protected static void test() + { + System.out.println("user.dir=" + System.getProperty("user.dir")); - try - { - // File f = new File("TestTree/DirectoryOne/titi2"); - // File f = new File("/home/cpm/.kde//cache-cpmstar"); - File f = new File("tests/TestTree/xine.jpg"); - System.out.println("exists=" + f.exists()); - System.out.println("canonical path = " + f.getCanonicalPath()); - System.out.println("absolute path = " + f.getAbsolutePath()); - System.out.println("name = " + f.getName()); - System.out.println("parent = " + f.getParent()); - System.out.println("path = " + f.getPath()); - System.out.println("path = " + f.lastModified()); - System.out.println("path = " + f.length()); - System.out.println("path = " + f.isFile()); - System.out.println("path = " + f.isDirectory()); - System.out.println("list = " + f.list()); + try + { + // File f = new File("TestTree/DirectoryOne/titi2"); + // File f = new File("/home/cpm/.kde//cache-cpmstar"); + File f = new File("tests/TestTree/xine.jpg"); + System.out.println("exists=" + f.exists()); + System.out.println("canonical path = " + f.getCanonicalPath()); + System.out.println("absolute path = " + f.getAbsolutePath()); + System.out.println("name = " + f.getName()); + System.out.println("parent = " + f.getParent()); + System.out.println("path = " + f.getPath()); + System.out.println("path = " + f.lastModified()); + System.out.println("path = " + f.length()); + System.out.println("path = " + f.isFile()); + System.out.println("path = " + f.isDirectory()); + System.out.println("list = " + f.list()); - System.out.println("----"); - // FileIterator i = new FileIterator(new File("tests/TestTree")); - FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true); - // FileIterator i = new FileIterator(new - // File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false); - // FileIterator i = new FileIterator(new File("tests/TestTree"), - // ".*dsc.*", false); - // FileIterator i = new FileIterator(new - // File("/home/cpm/Images/Photos/")); - // FileIterator i = new FileIterator(new - // File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false); - // FileIterator i = new FileIterator(new - // File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false); + System.out.println("----"); + // FileIterator i = new FileIterator(new File("tests/TestTree")); + FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true); + // FileIterator i = new FileIterator(new + // File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false); + // FileIterator i = new FileIterator(new File("tests/TestTree"), + // ".*dsc.*", false); + // FileIterator i = new FileIterator(new + // File("/home/cpm/Images/Photos/")); + // FileIterator i = new FileIterator(new + // File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false); + // FileIterator i = new FileIterator(new + // File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false); - while (i.hasNext()) - { - // System.out.println(i.toString()); - System.out.println("File=[" + i.next().getPath() + "]"); - } - i.reset(); - System.out.println("Cardinal=" + i.finalCountdown()); - } - catch (Exception exception) - { - System.out.println("ERROR:" + exception.getMessage()); - } - } + while (i.hasNext()) + { + // System.out.println(i.toString()); + System.out.println("File=[" + i.next().getPath() + "]"); + } + i.reset(); + System.out.println("Cardinal=" + i.finalCountdown()); + } + catch (Exception exception) + { + System.out.println("ERROR:" + exception.getMessage()); + } + } } diff --git a/test/Foot1Test.java b/test/Foot1Test.java index dda5c6a..7374c57 100644 --- a/test/Foot1Test.java +++ b/test/Foot1Test.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2013,2017 Christian Pierre MOMON + * + * This file is part of Devinsy-utils. + * + * Devinsy-utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Devinsy-utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Devinsy-utils. If not, see + */ import org.junit.Test; public class Foot1Test diff --git a/test/fr/devinsy/util/FileToolsTest.java b/test/fr/devinsy/util/FileToolsTest.java index 2653b83..e9c52e6 100644 --- a/test/fr/devinsy/util/FileToolsTest.java +++ b/test/fr/devinsy/util/FileToolsTest.java @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2014 Christian Pierre MOMON +/* + * Copyright (C) 2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-utils. * @@ -30,15 +30,17 @@ import org.junit.Test; import fr.devinsy.util.strings.StringList; /** + * The Class FileToolsTest. * - * @author Christian P. Momon + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ + public class FileToolsTest { - static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FileToolsTest.class); + public final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FileToolsTest.class); /** - * + * Before. */ @Before public void before() @@ -48,13 +50,16 @@ public class FileToolsTest } /** - * - */ + * Load to string list URL 01. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ @Test public void loadToStringListURL01() throws IOException { // - logger.debug("===== test starting..."); + this.logger.debug("===== test starting..."); // StringList source = FileTools.loadToStringList(FileTools.class.getResource("/fr/devinsy/util/lines.txt")); @@ -63,18 +68,17 @@ public class FileToolsTest Assert.assertEquals("trois", source.get(3 - 1)); // - logger.debug("===== test done."); + this.logger.debug("===== test done."); } /** - * @throws IOException - * + * Test get extension. */ @Test public void testGetExtension() { // - logger.debug("===== test starting..."); + this.logger.debug("===== test starting..."); // String extension = FileTools.getExtension("test.ext"); @@ -83,6 +87,6 @@ public class FileToolsTest Assert.assertEquals(extension, "ext"); // - logger.debug("===== test done."); + this.logger.debug("===== test done."); } }