From: Svjatoslav Agejenko Date: Mon, 28 Oct 2024 21:33:03 +0000 (+0200) Subject: Updated latest released version number in documentation. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=HEAD;p=svjatoslav_commons.git Updated latest released version number in documentation. --- diff --git a/doc/index.html b/doc/index.html index 98a022b..5a35b54 100644 --- a/doc/index.html +++ b/doc/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Svjatoslav Commons - Java library of commonly used functions @@ -202,19 +202,19 @@

Table of Contents

-
-

1. General

+
+

1. General

  • This program is free software: released under Creative Commons Zero @@ -231,8 +231,8 @@
-
-

1.1. Source code

+
+

1.1. Source code

-
-

2. Library contents

+
+

2. Library contents

  • See JavaDoc.
  • @@ -266,14 +266,6 @@ eu.svjatoslav.commons.data.BitInputStream eu.svjatoslav.commons.data.BitOutputStream -
  • -Slightly enhanced data input and output streams. -

    -
    -eu.svjatoslav.commons.data.EnhancedDataInputStream
    -eu.svjatoslav.commons.data.EnhancedDataOutputStream
    -
  • -
  • Byte array to HEX string converter.

    @@ -281,14 +273,6 @@ Byte array to HEX string converter. eu.svjatoslav.commons.data.HexConverter
  • -
  • -Utility that tries to quess user desktop directory. (Quite ugly and -unreliable. Better solution is needed.) -

    -
    -eu.svjatoslav.commons.file.CommonPathResolver
    -
  • -
  • File path parser.

    @@ -314,14 +298,6 @@ eu.svjatoslav.commons.gui.dialog.ExceptionDialog
-
  • -Primitive and simple component to add navigation menus to the web -sites. -

    -
    -eu.svjatoslav.commons.network.navigation
    -
  • -
  • String tokenizer.

    @@ -346,8 +322,8 @@ eu.svjatoslav.commons.string.WildCardMatcher#match
  • -
    -

    3. Usage

    +
    +

    3. Usage

    Instructions to embed svjatoslav-commons in your project as a library: @@ -358,26 +334,26 @@ Maven pom.xml file snippet:

    -
    <dependencies>
    +
    <dependencies>
         ...
    -    <dependency>
    -        <groupId>eu.svjatoslav</groupId>
    -        <artifactId>svjatoslavcommons</artifactId>
    -        <version>1.9</version>
    -    </dependency>
    +    <dependency>
    +        <groupId>eu.svjatoslav</groupId>
    +        <artifactId>svjatoslavcommons</artifactId>
    +        <version>1.9</version>
    +    </dependency>
         ...
    -</dependencies>
    +</dependencies>
     
     
    -<repositories>
    +<repositories>
         ...
    -    <repository>
    -        <id>svjatoslav.eu</id>
    -        <name>Svjatoslav repository</name>
    -        <url>https://www2.svjatoslav.eu/maven/</url>
    -    </repository>
    +    <repository>
    +        <id>svjatoslav.eu</id>
    +        <name>Svjatoslav repository</name>
    +        <url>https://www2.svjatoslav.eu/maven/</url>
    +    </repository>
         ...
    -</repositories>
    +</repositories>
     
    @@ -385,7 +361,7 @@ Maven pom.xml file snippet:

    Author: Svjatoslav Agejenko

    -

    Created: 2023-06-11 Sun 21:23

    +

    Created: 2024-10-28 ma 23:31

    Validate

    diff --git a/doc/index.org b/doc/index.org index f6f8c3a..4e0b077 100644 --- a/doc/index.org +++ b/doc/index.org @@ -28,17 +28,9 @@ : eu.svjatoslav.commons.data.BitInputStream : eu.svjatoslav.commons.data.BitOutputStream -- Slightly enhanced data input and output streams. - : eu.svjatoslav.commons.data.EnhancedDataInputStream - : eu.svjatoslav.commons.data.EnhancedDataOutputStream - - Byte array to HEX string converter. : eu.svjatoslav.commons.data.HexConverter -- Utility that tries to quess user desktop directory. (Quite ugly and - unreliable. Better solution is needed.) - : eu.svjatoslav.commons.file.CommonPathResolver - - File path parser. : eu.svjatoslav.commons.file.FilePathParser @@ -50,10 +42,6 @@ and associated program call stack traceback. : eu.svjatoslav.commons.gui.dialog.ExceptionDialog -- Primitive and simple component to add navigation menus to the web - sites. - : eu.svjatoslav.commons.network.navigation - - String tokenizer. : eu.svjatoslav.commons.string.tokenizer diff --git a/src/main/java/eu/svjatoslav/commons/data/BitInputStream.java b/src/main/java/eu/svjatoslav/commons/data/BitInputStream.java index af6486f..c88ef63 100755 --- a/src/main/java/eu/svjatoslav/commons/data/BitInputStream.java +++ b/src/main/java/eu/svjatoslav/commons/data/BitInputStream.java @@ -21,6 +21,12 @@ public class BitInputStream { this.inputStream = inputStream; } + /** + * Read bits from the input stream. + * @param bitCount Number of bits to read. + * @return Read bits. + * @throws IOException If an I/O error occurs. + */ public int readBits(final int bitCount) throws IOException { int readableByte = 0; diff --git a/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java b/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java index d02c3b4..6b4740a 100755 --- a/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java +++ b/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java @@ -23,6 +23,10 @@ public class BitOutputStream { this.outputStream = outputStream; } + /** + * Finish writing the last byte. + * @throws IOException If an I/O error occurs. + */ public void finishByte() throws IOException { if (currentBytePointer != 0) { outputStream.write(currentByte); @@ -30,6 +34,12 @@ public class BitOutputStream { } } + /** + * Write bits to the output stream. + * @param data Data to write. + * @param bitCount Number of bits to write. + * @throws IOException If an I/O error occurs. + */ public void storeBits(final int data, final int bitCount) throws IOException { for (int i = bitCount - 1; i >= 0; i--) { diff --git a/src/main/java/eu/svjatoslav/commons/data/EnhancedDataInputStream.java b/src/main/java/eu/svjatoslav/commons/data/EnhancedDataInputStream.java deleted file mode 100755 index 9c3560d..0000000 --- a/src/main/java/eu/svjatoslav/commons/data/EnhancedDataInputStream.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko. - * This project is released under Creative Commons Zero (CC0) license. - */ -package eu.svjatoslav.commons.data; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -public class EnhancedDataInputStream extends DataInputStream { - - public EnhancedDataInputStream(final InputStream in) { - super(in); - } - - public List readIntegerList() throws IOException { - final int length = readInt(); - - final List result = new ArrayList<>(); - - for (int i = 0; i < length; i++) - result.add(readInt()); - - return result; - } - - public String readString() throws IOException { - - final int length = readInt(); - if (length == -1) - return null; - - final byte[] bytes = new byte[length]; - readFully(bytes); - - return new String(bytes, "UTF-8"); - } - -} diff --git a/src/main/java/eu/svjatoslav/commons/data/EnhancedDataOutputStream.java b/src/main/java/eu/svjatoslav/commons/data/EnhancedDataOutputStream.java deleted file mode 100755 index 7d936e2..0000000 --- a/src/main/java/eu/svjatoslav/commons/data/EnhancedDataOutputStream.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko. - * This project is released under Creative Commons Zero (CC0) license. - */ -package eu.svjatoslav.commons.data; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -public class EnhancedDataOutputStream extends DataOutputStream { - - public EnhancedDataOutputStream(final OutputStream out) { - super(out); - } - - public void writeIntegerList(final List list) throws IOException { - writeInt(list.size()); - - for (final Integer integer : list) - writeInt(integer); - } - - public void writeString(final String string) throws IOException { - if (string == null) { - writeInt(-1); - return; - } - - final byte[] bytes = string.getBytes("UTF-8"); - - writeInt(bytes.length); - write(bytes); - } - -} diff --git a/src/main/java/eu/svjatoslav/commons/data/HexConverter.java b/src/main/java/eu/svjatoslav/commons/data/HexConverter.java index c6ea706..7f74166 100755 --- a/src/main/java/eu/svjatoslav/commons/data/HexConverter.java +++ b/src/main/java/eu/svjatoslav/commons/data/HexConverter.java @@ -8,6 +8,13 @@ public class HexConverter { static final String hexCharacters = "0123456789ABCDEF"; + /** + * Converts a byte array to hexadecimal string. + * + * @param bytes + * Byte array. + * @return Hexadecimal string. + */ public static String byteArrayToHex(final byte[] bytes) { if (bytes == null) diff --git a/src/main/java/eu/svjatoslav/commons/file/CommonPathResolver.java b/src/main/java/eu/svjatoslav/commons/file/CommonPathResolver.java index 06e82c2..f05d08c 100755 --- a/src/main/java/eu/svjatoslav/commons/file/CommonPathResolver.java +++ b/src/main/java/eu/svjatoslav/commons/file/CommonPathResolver.java @@ -8,6 +8,11 @@ import java.io.File; public class CommonPathResolver { + /** + * Returns current user's home directory. + * + * @return Home directory. + */ public static File getHomeDirectory() { return new File(System.getProperty("user.home")); } diff --git a/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java b/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java index 05430c4..ca4a0f3 100755 --- a/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java +++ b/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java @@ -8,12 +8,22 @@ import java.io.File; public class FilePathParser { + /** + * Returns file extension. + * @param file File. + * @return File extension. Empty string if a file has no extension. + */ public static String getFileExtension(final File file) { final String fullFileName = file.getName(); return getFileExtension(fullFileName); } + /** + * Returns file extension. + * @param fullFileName Full file name. + * @return File extension. Empty string if a file has no extension. + */ public static String getFileExtension(final String fullFileName) { final int dot = fullFileName.lastIndexOf('.'); String fileExtension; @@ -27,11 +37,25 @@ public class FilePathParser { return fileExtension; } + /** + * Returns file name without extension. + * + * @param file + * File. + * @return File name without extension. + */ public static String getFileNameWithoutExtension(final File file) { final String fullFileName = file.getName(); return getFileNameWithoutExtension(fullFileName); } + /** + * Returns file name without extension. + * + * @param fullFileName + * Full file name. + * @return File name without extension. + */ public static String getFileNameWithoutExtension(final String fullFileName) { final int dot = fullFileName.lastIndexOf('.'); String fileName; @@ -43,6 +67,13 @@ public class FilePathParser { return fileName; } + /** + * Returns file size description. + * + * @param fileSize + * File size in bytes. + * @return File size description. + */ public static String getFileSizeDescription(long fileSize) { String suffix = "b"; diff --git a/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java b/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java index 32974f1..638e284 100755 --- a/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java +++ b/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java @@ -9,6 +9,11 @@ import java.awt.*; import static javax.swing.BoxLayout.Y_AXIS; +/** + * Helper class to show graphical exception dialog. + *

    + * Dialog contains exception details and stack trace. + */ public class ExceptionDialog { public ExceptionDialog(final Exception exception) { @@ -73,14 +78,14 @@ public class ExceptionDialog { final JPanel topPanel = new JPanel(); topPanel.setLayout(new BoxLayout(topPanel, Y_AXIS)); - // add exception type + // add an exception type topPanel.add( new JLabel("Exception type: " + exception.getClass().getCanonicalName())); - // add error message + // add an error message topPanel.add(new JLabel("Error message: " + exception.getMessage())); - // add cause message + // add a cause message Throwable cause = exception.getCause(); if (cause != null && cause.getMessage() != null) topPanel.add(new JLabel("Cause: " + cause.getMessage())); diff --git a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java b/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java deleted file mode 100755 index eca13a6..0000000 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko. - * This project is released under Creative Commons Zero (CC0) license. - */ -package eu.svjatoslav.commons.network.navigation; - -import javax.servlet.http.HttpServletRequest; -import java.net.MalformedURLException; -import java.net.URL; - -public class Navigation { - - private NavigationItem root = new NavigationItem(null, null, null); - - public NavigationItem getRoot(){ - return root; - } - - public NavigationItem getSelectedItem(final HttpServletRequest request) { - final String requestUrl = request.getRequestURL().toString(); - - final String requestPath; - try { - requestPath = new URL(requestUrl).getPath(); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("Illegal request URL provided." , e); - } - - @SuppressWarnings("unchecked") final NavigationItem match = root.getMatch(requestPath); - - if (match != null) - return match; - - return root.getDefaultNavigationItem(); - } - - @SuppressWarnings("unchecked") - public String getTopMenu(final HttpServletRequest request) { - - final NavigationItem selectedItem = getSelectedItem(request); - final StringBuilder result = new StringBuilder(); - - result.append("

    "); - - for (final NavigationItem item : root.getChildren()) { - - if (item == selectedItem) - result.append(""); - else - result.append(""); - - result.append("
    " + item.getTitle() + "
    "); - result.append("
    "); - } - - result.append("
    "); - - return result.toString(); - } - -} diff --git a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java deleted file mode 100755 index 168b809..0000000 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko. - * This project is released under Creative Commons Zero (CC0) license. - */ -package eu.svjatoslav.commons.network.navigation; - -import eu.svjatoslav.commons.string.GlobMatcher; - -import java.util.ArrayList; -import java.util.List; - -public class NavigationItem { - - private final ArrayList children = new ArrayList<>(); - private final String url; - private String pattern; - private String title; - private boolean isDefault; - - public NavigationItem(final String url, String pattern, String title ) { - this.url = url; - this.pattern = pattern; - this.title = title; - } - - public NavigationItem setDefault(){ - isDefault = true; - return this; - } - - public boolean isDefault(){ - return isDefault; - } - - public void add(final NavigationItem navigationItem) { - children.add(navigationItem); - } - - public String getUrl() { - return url; - } - - NavigationItem getMatch(final String requestPath) { - if (matchesUrl(requestPath)) - return this; - - for (final NavigationItem childNavigationItem : children) { - final NavigationItem match = childNavigationItem.getMatch(requestPath); - - if (match != null) - return match; - } - return null; - } - - public List getChildren() { - return children; - } - - public String getTitle() { - return title; - } - - public boolean matchesUrl(final String url) { - return GlobMatcher.match(url, pattern); - } - - public NavigationItem getDefaultNavigationItem() { - for (NavigationItem child : children) - if (child.isDefault()) - return child; - return null; - } -} diff --git a/src/main/java/eu/svjatoslav/commons/string/GlobMatcher.java b/src/main/java/eu/svjatoslav/commons/string/GlobMatcher.java index c27c523..5bdd7fb 100755 --- a/src/main/java/eu/svjatoslav/commons/string/GlobMatcher.java +++ b/src/main/java/eu/svjatoslav/commons/string/GlobMatcher.java @@ -4,6 +4,16 @@ */ package eu.svjatoslav.commons.string; +/** + * GlobMatcher - class for matching strings against wildcard expressions. + *

    + *

    + * Wildcard expressions:
    + * * -- corresponds to any amount of characters.
    + * ? -- corresponds to any single character.
    + * 
    + */ + public class GlobMatcher { /** diff --git a/src/main/java/eu/svjatoslav/commons/string/String2.java b/src/main/java/eu/svjatoslav/commons/string/String2.java index c18633a..4068c4a 100755 --- a/src/main/java/eu/svjatoslav/commons/string/String2.java +++ b/src/main/java/eu/svjatoslav/commons/string/String2.java @@ -121,10 +121,20 @@ public class String2 { return this; } + /** + * Check if the string has a suffix. + * @param suffix to check + * @return true if the string has the suffix + */ public boolean hasSuffix(String suffix) { return contains(suffix, getLength() - suffix.length()); } + /** + * Check if the string has a prefix. + * @param prefix to check + * @return true if the string has the prefix + */ public boolean hasPrefix(String prefix) { return contains(prefix, 0); }