Updated latest released version number in documentation. master
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 28 Oct 2024 21:33:03 +0000 (23:33 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 28 Oct 2024 21:33:03 +0000 (23:33 +0200)
14 files changed:
doc/index.html
doc/index.org
src/main/java/eu/svjatoslav/commons/data/BitInputStream.java
src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java
src/main/java/eu/svjatoslav/commons/data/EnhancedDataInputStream.java [deleted file]
src/main/java/eu/svjatoslav/commons/data/EnhancedDataOutputStream.java [deleted file]
src/main/java/eu/svjatoslav/commons/data/HexConverter.java
src/main/java/eu/svjatoslav/commons/file/CommonPathResolver.java
src/main/java/eu/svjatoslav/commons/file/FilePathParser.java
src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java
src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java [deleted file]
src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java [deleted file]
src/main/java/eu/svjatoslav/commons/string/GlobMatcher.java
src/main/java/eu/svjatoslav/commons/string/String2.java

index 98a022b..5a35b54 100644 (file)
@@ -3,7 +3,7 @@
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
-<!-- 2023-06-11 Sun 21:23 -->
+<!-- 2024-10-28 ma 23:31 -->
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1" />
 <title>Svjatoslav Commons - Java library of commonly used functions</title>
 <h2>Table of Contents</h2>
 <div id="text-table-of-contents" role="doc-toc">
 <ul>
-<li><a href="#orgf8795c6">1. General</a>
+<li><a href="#org688caae">1. General</a>
 <ul>
-<li><a href="#org85c626e">1.1. Source code</a></li>
+<li><a href="#org0b426f5">1.1. Source code</a></li>
 </ul>
 </li>
-<li><a href="#org5358341">2. Library contents</a></li>
-<li><a href="#orgd60f7bf">3. Usage</a></li>
+<li><a href="#org7fdb5b1">2. Library contents</a></li>
+<li><a href="#org79e0c3e">3. Usage</a></li>
 </ul>
 </div>
 </div>
 
-<div id="outline-container-orgf8795c6" class="outline-2">
-<h2 id="orgf8795c6"><span class="section-number-2">1.</span> General</h2>
+<div id="outline-container-org688caae" class="outline-2">
+<h2 id="org688caae"><span class="section-number-2">1.</span> General</h2>
 <div class="outline-text-2" id="text-1">
 <ul class="org-ul">
 <li>This program is free software: released under Creative Commons Zero
 </ul>
 </div>
 
-<div id="outline-container-org85c626e" class="outline-3">
-<h3 id="org85c626e"><span class="section-number-3">1.1.</span> Source code</h3>
+<div id="outline-container-org0b426f5" class="outline-3">
+<h3 id="org0b426f5"><span class="section-number-3">1.1.</span> Source code</h3>
 <div class="outline-text-3" id="text-1-1">
 <ul class="org-ul">
 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=snapshot;h=HEAD;sf=tgz">Download latest snapshot in TAR GZ format</a></li>
@@ -252,8 +252,8 @@ git clone https://www2.svjatoslav.eu/git/svjatoslav_commons.git
 </div>
 </div>
 
-<div id="outline-container-org5358341" class="outline-2">
-<h2 id="org5358341"><span class="section-number-2">2.</span> Library contents</h2>
+<div id="outline-container-org7fdb5b1" class="outline-2">
+<h2 id="org7fdb5b1"><span class="section-number-2">2.</span> Library contents</h2>
 <div class="outline-text-2" id="text-2">
 <ul class="org-ul">
 <li>See <a href="https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/">JavaDoc</a>.</li>
@@ -266,14 +266,6 @@ eu.svjatoslav.commons.data.BitInputStream
 eu.svjatoslav.commons.data.BitOutputStream
 </pre></li>
 
-<li><p>
-Slightly enhanced data input and output streams.
-</p>
-<pre class="example">
-eu.svjatoslav.commons.data.EnhancedDataInputStream
-eu.svjatoslav.commons.data.EnhancedDataOutputStream
-</pre></li>
-
 <li><p>
 Byte array to HEX string converter.
 </p>
@@ -281,14 +273,6 @@ Byte array to HEX string converter.
 eu.svjatoslav.commons.data.HexConverter
 </pre></li>
 
-<li><p>
-Utility that tries to quess user desktop directory. (Quite ugly and
-unreliable. Better solution is needed.)
-</p>
-<pre class="example">
-eu.svjatoslav.commons.file.CommonPathResolver
-</pre></li>
-
 <li><p>
 File path parser.
 </p>
@@ -314,14 +298,6 @@ eu.svjatoslav.commons.gui.dialog.ExceptionDialog
 </pre></li>
 </ul></li>
 
-<li><p>
-Primitive and simple component to add navigation menus to the web
-sites.
-</p>
-<pre class="example">
-eu.svjatoslav.commons.network.navigation
-</pre></li>
-
 <li><p>
 String tokenizer.
 </p>
@@ -346,8 +322,8 @@ eu.svjatoslav.commons.string.WildCardMatcher#match
 </div>
 </div>
 
-<div id="outline-container-orgd60f7bf" class="outline-2">
-<h2 id="orgd60f7bf"><span class="section-number-2">3.</span> Usage</h2>
+<div id="outline-container-org79e0c3e" class="outline-2">
+<h2 id="org79e0c3e"><span class="section-number-2">3.</span> Usage</h2>
 <div class="outline-text-2" id="text-3">
 <p>
 Instructions to embed svjatoslav-commons in your project as a library:
@@ -358,26 +334,26 @@ Maven pom.xml file snippet:
 </p>
 
 <div class="org-src-container">
-<pre class="src src-xml">&lt;<span style="color: #7b68ee; font-weight: bold;">dependencies</span>&gt;
+<pre class="src src-xml">&lt;<span style="color: #89b4fa;">dependencies</span>&gt;
     ...
-    &lt;<span style="color: #7b68ee; font-weight: bold;">dependency</span>&gt;
-        &lt;<span style="color: #7b68ee; font-weight: bold;">groupId</span>&gt;eu.svjatoslav&lt;/<span style="color: #7b68ee; font-weight: bold;">groupId</span>&gt;
-        &lt;<span style="color: #7b68ee; font-weight: bold;">artifactId</span>&gt;svjatoslavcommons&lt;/<span style="color: #7b68ee; font-weight: bold;">artifactId</span>&gt;
-        &lt;<span style="color: #7b68ee; font-weight: bold;">version</span>&gt;1.9&lt;/<span style="color: #7b68ee; font-weight: bold;">version</span>&gt;
-    &lt;/<span style="color: #7b68ee; font-weight: bold;">dependency</span>&gt;
+    &lt;<span style="color: #89b4fa;">dependency</span>&gt;
+        &lt;<span style="color: #89b4fa;">groupId</span>&gt;eu.svjatoslav&lt;/<span style="color: #89b4fa;">groupId</span>&gt;
+        &lt;<span style="color: #89b4fa;">artifactId</span>&gt;svjatoslavcommons&lt;/<span style="color: #89b4fa;">artifactId</span>&gt;
+        &lt;<span style="color: #89b4fa;">version</span>&gt;1.9&lt;/<span style="color: #89b4fa;">version</span>&gt;
+    &lt;/<span style="color: #89b4fa;">dependency</span>&gt;
     ...
-&lt;/<span style="color: #7b68ee; font-weight: bold;">dependencies</span>&gt;
+&lt;/<span style="color: #89b4fa;">dependencies</span>&gt;
 
 
-&lt;<span style="color: #7b68ee; font-weight: bold;">repositories</span>&gt;
+&lt;<span style="color: #89b4fa;">repositories</span>&gt;
     ...
-    &lt;<span style="color: #7b68ee; font-weight: bold;">repository</span>&gt;
-        &lt;<span style="color: #7b68ee; font-weight: bold;">id</span>&gt;svjatoslav.eu&lt;/<span style="color: #7b68ee; font-weight: bold;">id</span>&gt;
-        &lt;<span style="color: #7b68ee; font-weight: bold;">name</span>&gt;Svjatoslav repository&lt;/<span style="color: #7b68ee; font-weight: bold;">name</span>&gt;
-        &lt;<span style="color: #7b68ee; font-weight: bold;">url</span>&gt;https://www2.svjatoslav.eu/maven/&lt;/<span style="color: #7b68ee; font-weight: bold;">url</span>&gt;
-    &lt;/<span style="color: #7b68ee; font-weight: bold;">repository</span>&gt;
+    &lt;<span style="color: #89b4fa;">repository</span>&gt;
+        &lt;<span style="color: #89b4fa;">id</span>&gt;svjatoslav.eu&lt;/<span style="color: #89b4fa;">id</span>&gt;
+        &lt;<span style="color: #89b4fa;">name</span>&gt;Svjatoslav repository&lt;/<span style="color: #89b4fa;">name</span>&gt;
+        &lt;<span style="color: #89b4fa;">url</span>&gt;https://www2.svjatoslav.eu/maven/&lt;/<span style="color: #89b4fa;">url</span>&gt;
+    &lt;/<span style="color: #89b4fa;">repository</span>&gt;
     ...
-&lt;/<span style="color: #7b68ee; font-weight: bold;">repositories</span>&gt;
+&lt;/<span style="color: #89b4fa;">repositories</span>&gt;
 </pre>
 </div>
 </div>
@@ -385,7 +361,7 @@ Maven pom.xml file snippet:
 </div>
 <div id="postamble" class="status">
 <p class="author">Author: Svjatoslav Agejenko</p>
-<p class="date">Created: 2023-06-11 Sun 21:23</p>
+<p class="date">Created: 2024-10-28 ma 23:31</p>
 <p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
 </div>
 </body>
index f6f8c3a..4e0b077 100644 (file)
   : 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
 
     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
 
index af6486f..c88ef63 100755 (executable)
@@ -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;
index d02c3b4..6b4740a 100755 (executable)
@@ -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 (executable)
index 9c3560d..0000000
+++ /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<Integer> readIntegerList() throws IOException {
-        final int length = readInt();
-
-        final List<Integer> 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 (executable)
index 7d936e2..0000000
+++ /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<Integer> 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);
-    }
-
-}
index c6ea706..7f74166 100755 (executable)
@@ -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)
index 06e82c2..f05d08c 100755 (executable)
@@ -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"));
     }
index 05430c4..ca4a0f3 100755 (executable)
@@ -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";
 
index 32974f1..638e284 100755 (executable)
@@ -9,6 +9,11 @@ import java.awt.*;
 
 import static javax.swing.BoxLayout.Y_AXIS;
 
+/**
+ * Helper class to show graphical exception dialog.
+ * <p>
+ * 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 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 (executable)
index eca13a6..0000000
+++ /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("<div class=\"navigationMenu\">");
-
-        for (final NavigationItem item : root.getChildren()) {
-
-            if (item == selectedItem)
-                result.append("<a class=\"menuItemSelected\" href=\""
-                        + item.getUrl() + "\">");
-            else
-                result.append("<a class=\"menuItem\" href=\""
-                        + item.getUrl() + "\">");
-
-            result.append("<div>" + item.getTitle() + "</div>");
-            result.append("</a>");
-        }
-
-        result.append("</div>");
-
-        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 (executable)
index 168b809..0000000
+++ /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<NavigationItem> 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<NavigationItem> 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;
-    }
-}
index c27c523..5bdd7fb 100755 (executable)
@@ -4,6 +4,16 @@
  */
 package eu.svjatoslav.commons.string;
 
+/**
+ * GlobMatcher - class for matching strings against wildcard expressions.
+ * <p>
+ * <pre>
+ * Wildcard expressions:
+ * * -- corresponds to any amount of characters.
+ * ? -- corresponds to any single character.
+ * </pre>
+ */
+
 public class GlobMatcher {
 
     /**
index c18633a..4068c4a 100755 (executable)
@@ -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);
     }