-<!doctype html>
-<html lang="en">
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
+<!-- 2022-06-26 Sun 02:43 -->
+<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>
-<!-- 2020-05-01 Fri 23:39 -->
-<meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1">
-<meta name="generator" content="Org-mode">
-<meta name="author" content="Svjatoslav Agejenko">
-<link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
-<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
-<style type="text/css">
-footer {background-color: #111 !important;}
-pre {background-color: #111; color: #ccc;}
-</style>
-<style type="text/css">
-/* org mode styles on top of twbs */
-
-html {
+<meta name="author" content="Svjatoslav Agejenko" />
+<meta name="generator" content="Org Mode" />
+<style>
+ #content { max-width: 60em; margin: auto; }
+ .title { text-align: center;
+ margin-bottom: .2em; }
+ .subtitle { text-align: center;
+ font-size: medium;
+ font-weight: bold;
+ margin-top:0; }
+ .todo { font-family: monospace; color: red; }
+ .done { font-family: monospace; color: green; }
+ .priority { font-family: monospace; color: orange; }
+ .tag { background-color: #eee; font-family: monospace;
+ padding: 2px; font-size: 80%; font-weight: normal; }
+ .timestamp { color: #bebebe; }
+ .timestamp-kwd { color: #5f9ea0; }
+ .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
+ .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
+ .org-center { margin-left: auto; margin-right: auto; text-align: center; }
+ .underline { text-decoration: underline; }
+ #postamble p, #preamble p { font-size: 90%; margin: .2em; }
+ p.verse { margin-left: 3%; }
+ pre {
+ border: 1px solid #e6e6e6;
+ border-radius: 3px;
+ background-color: #f2f2f2;
+ padding: 8pt;
+ font-family: monospace;
+ overflow: auto;
+ margin: 1.2em;
+ }
+ pre.src {
position: relative;
- min-height: 100%;
-}
-
-body {
- font-size: 18px;
- margin-bottom: 105px;
-}
-
-footer {
+ overflow: auto;
+ }
+ pre.src:before {
+ display: none;
position: absolute;
- bottom: 0;
+ top: -8px;
+ right: 12px;
+ padding: 3px;
+ color: #555;
+ background-color: #f2f2f299;
+ }
+ pre.src:hover:before { display: inline; margin-top: 14px;}
+ /* Languages per Org manual */
+ pre.src-asymptote:before { content: 'Asymptote'; }
+ pre.src-awk:before { content: 'Awk'; }
+ pre.src-authinfo::before { content: 'Authinfo'; }
+ pre.src-C:before { content: 'C'; }
+ /* pre.src-C++ doesn't work in CSS */
+ pre.src-clojure:before { content: 'Clojure'; }
+ pre.src-css:before { content: 'CSS'; }
+ pre.src-D:before { content: 'D'; }
+ pre.src-ditaa:before { content: 'ditaa'; }
+ pre.src-dot:before { content: 'Graphviz'; }
+ pre.src-calc:before { content: 'Emacs Calc'; }
+ pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
+ pre.src-fortran:before { content: 'Fortran'; }
+ pre.src-gnuplot:before { content: 'gnuplot'; }
+ pre.src-haskell:before { content: 'Haskell'; }
+ pre.src-hledger:before { content: 'hledger'; }
+ pre.src-java:before { content: 'Java'; }
+ pre.src-js:before { content: 'Javascript'; }
+ pre.src-latex:before { content: 'LaTeX'; }
+ pre.src-ledger:before { content: 'Ledger'; }
+ pre.src-lisp:before { content: 'Lisp'; }
+ pre.src-lilypond:before { content: 'Lilypond'; }
+ pre.src-lua:before { content: 'Lua'; }
+ pre.src-matlab:before { content: 'MATLAB'; }
+ pre.src-mscgen:before { content: 'Mscgen'; }
+ pre.src-ocaml:before { content: 'Objective Caml'; }
+ pre.src-octave:before { content: 'Octave'; }
+ pre.src-org:before { content: 'Org mode'; }
+ pre.src-oz:before { content: 'OZ'; }
+ pre.src-plantuml:before { content: 'Plantuml'; }
+ pre.src-processing:before { content: 'Processing.js'; }
+ pre.src-python:before { content: 'Python'; }
+ pre.src-R:before { content: 'R'; }
+ pre.src-ruby:before { content: 'Ruby'; }
+ pre.src-sass:before { content: 'Sass'; }
+ pre.src-scheme:before { content: 'Scheme'; }
+ pre.src-screen:before { content: 'Gnu Screen'; }
+ pre.src-sed:before { content: 'Sed'; }
+ pre.src-sh:before { content: 'shell'; }
+ pre.src-sql:before { content: 'SQL'; }
+ pre.src-sqlite:before { content: 'SQLite'; }
+ /* additional languages in org.el's org-babel-load-languages alist */
+ pre.src-forth:before { content: 'Forth'; }
+ pre.src-io:before { content: 'IO'; }
+ pre.src-J:before { content: 'J'; }
+ pre.src-makefile:before { content: 'Makefile'; }
+ pre.src-maxima:before { content: 'Maxima'; }
+ pre.src-perl:before { content: 'Perl'; }
+ pre.src-picolisp:before { content: 'Pico Lisp'; }
+ pre.src-scala:before { content: 'Scala'; }
+ pre.src-shell:before { content: 'Shell Script'; }
+ pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
+ /* additional language identifiers per "defun org-babel-execute"
+ in ob-*.el */
+ pre.src-cpp:before { content: 'C++'; }
+ pre.src-abc:before { content: 'ABC'; }
+ pre.src-coq:before { content: 'Coq'; }
+ pre.src-groovy:before { content: 'Groovy'; }
+ /* additional language identifiers from org-babel-shell-names in
+ ob-shell.el: ob-shell is the only babel language using a lambda to put
+ the execution function name together. */
+ pre.src-bash:before { content: 'bash'; }
+ pre.src-csh:before { content: 'csh'; }
+ pre.src-ash:before { content: 'ash'; }
+ pre.src-dash:before { content: 'dash'; }
+ pre.src-ksh:before { content: 'ksh'; }
+ pre.src-mksh:before { content: 'mksh'; }
+ pre.src-posh:before { content: 'posh'; }
+ /* Additional Emacs modes also supported by the LaTeX listings package */
+ pre.src-ada:before { content: 'Ada'; }
+ pre.src-asm:before { content: 'Assembler'; }
+ pre.src-caml:before { content: 'Caml'; }
+ pre.src-delphi:before { content: 'Delphi'; }
+ pre.src-html:before { content: 'HTML'; }
+ pre.src-idl:before { content: 'IDL'; }
+ pre.src-mercury:before { content: 'Mercury'; }
+ pre.src-metapost:before { content: 'MetaPost'; }
+ pre.src-modula-2:before { content: 'Modula-2'; }
+ pre.src-pascal:before { content: 'Pascal'; }
+ pre.src-ps:before { content: 'PostScript'; }
+ pre.src-prolog:before { content: 'Prolog'; }
+ pre.src-simula:before { content: 'Simula'; }
+ pre.src-tcl:before { content: 'tcl'; }
+ pre.src-tex:before { content: 'TeX'; }
+ pre.src-plain-tex:before { content: 'Plain TeX'; }
+ pre.src-verilog:before { content: 'Verilog'; }
+ pre.src-vhdl:before { content: 'VHDL'; }
+ pre.src-xml:before { content: 'XML'; }
+ pre.src-nxml:before { content: 'XML'; }
+ /* add a generic configuration mode; LaTeX export needs an additional
+ (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
+ pre.src-conf:before { content: 'Configuration File'; }
+
+ table { border-collapse:collapse; }
+ caption.t-above { caption-side: top; }
+ caption.t-bottom { caption-side: bottom; }
+ td, th { vertical-align:top; }
+ th.org-right { text-align: center; }
+ th.org-left { text-align: center; }
+ th.org-center { text-align: center; }
+ td.org-right { text-align: right; }
+ td.org-left { text-align: left; }
+ td.org-center { text-align: center; }
+ dt { font-weight: bold; }
+ .footpara { display: inline; }
+ .footdef { margin-bottom: 1em; }
+ .figure { padding: 1em; }
+ .figure p { text-align: center; }
+ .equation-container {
+ display: table;
+ text-align: center;
width: 100%;
- height: 101px;
- background-color: #f5f5f5;
-}
-
-footer > div {
+ }
+ .equation {
+ vertical-align: middle;
+ }
+ .equation-label {
+ display: table-cell;
+ text-align: right;
+ vertical-align: middle;
+ }
+ .inlinetask {
padding: 10px;
-}
-
-footer p {
- margin: 0 0 5px;
- text-align: center;
- font-size: 16px;
-}
-
-#table-of-contents {
- margin-top: 20px;
- margin-bottom: 20px;
-}
-
-blockquote p {
- font-size: 18px;
-}
-
-pre {
- font-size: 16px;
-}
-
-.footpara {
- display: inline-block;
-}
-
-figcaption {
- font-size: 16px;
- color: #666;
- font-style: italic;
- padding-bottom: 15px;
-}
-
-/* from twbs docs */
-
-.bs-docs-sidebar.affix {
- position: static;
-}
-@media (min-width: 768px) {
- .bs-docs-sidebar {
- padding-left: 20px;
- }
-}
-
-/* All levels of nav */
-.bs-docs-sidebar .nav > li > a {
- display: block;
- padding: 4px 20px;
- font-size: 14px;
- font-weight: 500;
- color: #999;
-}
-.bs-docs-sidebar .nav > li > a:hover,
-.bs-docs-sidebar .nav > li > a:focus {
- padding-left: 19px;
- color: #A1283B;
- text-decoration: none;
- background-color: transparent;
- border-left: 1px solid #A1283B;
-}
-.bs-docs-sidebar .nav > .active > a,
-.bs-docs-sidebar .nav > .active:hover > a,
-.bs-docs-sidebar .nav > .active:focus > a {
- padding-left: 18px;
- font-weight: bold;
- color: #A1283B;
- background-color: transparent;
- border-left: 2px solid #A1283B;
-}
-
-/* Nav: second level (shown on .active) */
-.bs-docs-sidebar .nav .nav {
- display: none; /* Hide by default, but at >768px, show it */
- padding-bottom: 10px;
-}
-.bs-docs-sidebar .nav .nav > li > a {
- padding-top: 1px;
- padding-bottom: 1px;
- padding-left: 30px;
- font-size: 12px;
- font-weight: normal;
-}
-.bs-docs-sidebar .nav .nav > li > a:hover,
-.bs-docs-sidebar .nav .nav > li > a:focus {
- padding-left: 29px;
-}
-.bs-docs-sidebar .nav .nav > .active > a,
-.bs-docs-sidebar .nav .nav > .active:hover > a,
-.bs-docs-sidebar .nav .nav > .active:focus > a {
- padding-left: 28px;
- font-weight: 500;
-}
-
-/* Nav: third level (shown on .active) */
-.bs-docs-sidebar .nav .nav .nav {
- padding-bottom: 10px;
-}
-.bs-docs-sidebar .nav .nav .nav > li > a {
- padding-top: 1px;
- padding-bottom: 1px;
- padding-left: 40px;
- font-size: 12px;
- font-weight: normal;
-}
-.bs-docs-sidebar .nav .nav .nav > li > a:hover,
-.bs-docs-sidebar .nav .nav .nav > li > a:focus {
- padding-left: 39px;
-}
-.bs-docs-sidebar .nav .nav .nav > .active > a,
-.bs-docs-sidebar .nav .nav .nav > .active:hover > a,
-.bs-docs-sidebar .nav .nav .nav > .active:focus > a {
- padding-left: 38px;
- font-weight: 500;
-}
-
-/* Show and affix the side nav when space allows it */
-@media (min-width: 992px) {
- .bs-docs-sidebar .nav > .active > ul {
- display: block;
- }
- /* Widen the fixed sidebar */
- .bs-docs-sidebar.affix,
- .bs-docs-sidebar.affix-bottom {
- width: 213px;
- }
- .bs-docs-sidebar.affix {
- position: fixed; /* Undo the static from mobile first approach */
- top: 20px;
- }
- .bs-docs-sidebar.affix-bottom {
- position: absolute; /* Undo the static from mobile first approach */
- }
- .bs-docs-sidebar.affix .bs-docs-sidenav,.bs-docs-sidebar.affix-bottom .bs-docs-sidenav {
- margin-top: 0;
- margin-bottom: 0
- }
-}
-@media (min-width: 1200px) {
- /* Widen the fixed sidebar again */
- .bs-docs-sidebar.affix-bottom,
- .bs-docs-sidebar.affix {
- width: 263px;
- }
-}
+ border: 2px solid gray;
+ margin: 10px;
+ background: #ffffcc;
+ }
+ #org-div-home-and-up
+ { text-align: right; font-size: 70%; white-space: nowrap; }
+ textarea { overflow-x: auto; }
+ .linenr { font-size: smaller }
+ .code-highlighted { background-color: #ffff00; }
+ .org-info-js_info-navigation { border-style: none; }
+ #org-info-js_console-label
+ { font-size: 10px; font-weight: bold; white-space: nowrap; }
+ .org-info-js_search-highlight
+ { background-color: #ffff00; color: #000000; font-weight: bold; }
+ .org-svg { }
</style>
-<script type="text/javascript">
-$(function() {
- 'use strict';
-
- $('.bs-docs-sidebar li').first().addClass('active');
-
- $(document.body).scrollspy({target: '.bs-docs-sidebar'});
-
- $('.bs-docs-sidebar').affix();
-});
-</script>
+<link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
</head>
<body>
-<div id="content" class="container">
-<div class="row"><div class="col-md-9"><h1 class="title">Svjatoslav Commons - Java library of commonly used functions</h1>
+<div id="content" class="content">
+<h1 class="title">Svjatoslav Commons - Java library of commonly used functions</h1>
+<div id="table-of-contents" role="doc-toc">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents" role="doc-toc">
+<ul>
+<li><a href="#org805f71e">1. General</a>
+<ul>
+<li><a href="#org2e84a8e">1.1. Source code</a></li>
+</ul>
+</li>
+<li><a href="#orgc45a3c9">2. Library contents</a></li>
+<li><a href="#org0dfc99c">3. Usage</a></li>
+</ul>
+</div>
+</div>
-<div id="outline-container-sec-1" class="outline-2">
-<h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
+<div id="outline-container-org805f71e" class="outline-2">
+<h2 id="org805f71e"><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
-(CC0) license
-</li>
+(CC0) license</li>
<li>Program author:
<ul class="org-ul">
-<li>Svjatoslav Agejenko
-</li>
-<li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a>
-</li>
-<li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
-</li>
-</ul>
-</li>
+<li>Svjatoslav Agejenko</li>
+<li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a></li>
+<li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a></li>
+</ul></li>
-<li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a>
-</li>
+<li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a></li>
</ul>
</div>
-<div id="outline-container-sec-1-1" class="outline-3">
-<h3 id="sec-1-1"><span class="section-number-3">1.1</span> Source code</h3>
+<div id="outline-container-org2e84a8e" class="outline-3">
+<h3 id="org2e84a8e"><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>
+<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>
-<li><a href="https://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=summary">Browse Git repository online</a>
-</li>
+<li><a href="https://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=summary">Browse Git repository online</a></li>
-<li>Clone Git repository using command:
+<li><p>
+Clone Git repository using command:
+</p>
<pre class="example">
git clone https://www2.svjatoslav.eu/git/svjatoslav_commons.git
+</pre></li>
-</pre>
-</li>
-
-<li>See <a href="https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/">JavaDoc</a>.
-</li>
+<li>See <a href="https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/">JavaDoc</a>.</li>
</ul>
</div>
</div>
</div>
-<div id="outline-container-sec-2" class="outline-2">
-<h2 id="sec-2"><span class="section-number-2">2</span> Library contents</h2>
+<div id="outline-container-orgc45a3c9" class="outline-2">
+<h2 id="orgc45a3c9"><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>
-
-<li>Commandline Interface helper
-<pre class="example">
-eu.svjatoslav.commons.commandline.CLIHelper
-
-</pre>
-</li>
-
-<li>Commandline arguments parser and validator.
-<pre class="example">
-eu.svjatoslav.commons.commandline.parameterparser
-
-</pre>
-</li>
+<li>See <a href="https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/">JavaDoc</a>.</li>
-<li>Bit input and output streams.
+<li><p>
+Bit input and output streams.
+</p>
<pre class="example">
eu.svjatoslav.commons.data.BitInputStream
eu.svjatoslav.commons.data.BitOutputStream
+</pre></li>
-</pre>
-</li>
-
-<li>Slightly enhanced data input and output streams.
+<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>
-</pre>
-</li>
-
-<li>Byte array to HEX string converter.
+<li><p>
+Byte array to HEX string converter.
+</p>
<pre class="example">
eu.svjatoslav.commons.data.HexConverter
+</pre></li>
-</pre>
-</li>
-
-<li>Utility that tries to quess user desktop directory. (Quite ugly and
+<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>
-</pre>
-</li>
-
-<li>File path parser.
+<li><p>
+File path parser.
+</p>
<pre class="example">
eu.svjatoslav.commons.file.FilePathParser
+</pre></li>
-</pre>
-</li>
-
-<li>File IO helper.
+<li><p>
+File IO helper.
+</p>
<pre class="example">
eu.svjatoslav.commons.file.IOHelper
-
-</pre>
-</li>
+</pre></li>
<li>Graphical error dialog.
<ul class="org-ul">
-<li>Reusable graphical dialog to capture and show program exceptions
+<li><p>
+Reusable graphical dialog to capture and show program exceptions
and associated program call stack traceback.
+</p>
<pre class="example">
eu.svjatoslav.commons.gui.dialog.ExceptionDialog
+</pre></li>
+</ul></li>
-</pre>
-</li>
-</ul>
-</li>
-
-<li>Primitive and simple component to add navigation menus to the web
+<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>
-</pre>
-</li>
-
-<li>String tokenizer.
+<li><p>
+String tokenizer.
+</p>
<pre class="example">
eu.svjatoslav.commons.string.tokenizer
+</pre></li>
-</pre>
-</li>
-
-<li>Improved String, optimized for dealing with prefixes and suffixes.
+<li><p>
+Improved String, optimized for dealing with prefixes and suffixes.
+</p>
<pre class="example">
eu.svjatoslav.commons.string.String2
+</pre></li>
-</pre>
-</li>
-
-<li>Wildcards matcher. (?, *)
+<li><p>
+Wildcards matcher. (?, *)
+</p>
<pre class="example">
eu.svjatoslav.commons.string.WildCardMatcher#match
-
-</pre>
-</li>
+</pre></li>
</ul>
</div>
</div>
-<div id="outline-container-sec-3" class="outline-2">
-<h2 id="sec-3"><span class="section-number-2">3</span> Usage</h2>
+<div id="outline-container-org0dfc99c" class="outline-2">
+<h2 id="org0dfc99c"><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:
</p>
<div class="org-src-container">
-
<pre class="src src-xml"><<span style="color: #A6E22E;">dependencies</span>>
...
<<span style="color: #A6E22E;">dependency</span>>
</div>
</div>
</div>
-</div><div class="col-md-3"><nav id="table-of-contents">
-<div id="text-table-of-contents" class="bs-docs-sidebar">
-<ul class="nav">
-<li><a href="#sec-1">1. General</a>
-<ul class="nav">
-<li><a href="#sec-1-1">1.1. Source code</a></li>
-</ul>
-</li>
-<li><a href="#sec-2">2. Library contents</a></li>
-<li><a href="#sec-3">3. Usage</a></li>
-</ul>
</div>
-</nav>
-</div></div></div>
-<footer id="postamble" class="">
-<div><p class="author">Author: Svjatoslav Agejenko</p>
-<p class="date">Created: 2020-05-01 Fri 23:39</p>
-<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 26.1 (<a href="http://orgmode.org">Org-mode</a> 9.1.9)</p>
+<div id="postamble" class="status">
+<p class="author">Author: Svjatoslav Agejenko</p>
+<p class="date">Created: 2022-06-26 Sun 02:43</p>
+<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
-</footer>
</body>
</html>
#+TITLE: Svjatoslav Commons - Java library of commonly used functions
-* (document settings) :noexport:
-** use dark style for TWBS-HTML exporter
-#+HTML_HEAD: <link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
-#+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-#+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
-#+HTML_HEAD: <style type="text/css">
-#+HTML_HEAD: footer {background-color: #111 !important;}
-#+HTML_HEAD: pre {background-color: #111; color: #ccc;}
-#+HTML_HEAD: </style>
-
* General
- This program is free software: released under Creative Commons Zero
(CC0) license
* Library contents
- See [[https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/][JavaDoc]].
-- Commandline Interface helper
- : eu.svjatoslav.commons.commandline.CLIHelper
-
-- Commandline arguments parser and validator.
- : eu.svjatoslav.commons.commandline.parameterparser
-
- Bit input and output streams.
: eu.svjatoslav.commons.data.BitInputStream
: eu.svjatoslav.commons.data.BitOutputStream
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-/**
- * Command-line interface helper.
- */
-public class CLIHelper {
-
- /**
- * Ask boolean value from user on command-line.
- *
- * @param prompt to show to the user
- * @return <code>true</code> is user answered affirmative.
- */
- public static boolean askBoolean(final String prompt) {
-
- final BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
-
- while (true)
- try {
- System.out.print(prompt);
-
- String line = br.readLine();
- if (line != null) {
- final String userInput = line.toLowerCase();
-
- if ("y".equals(userInput) || "yes".equals(userInput)
- || "true".equals(userInput))
- return true;
-
- if ("n".equals(userInput) || "no".equals(userInput)
- || "false".equals(userInput))
- return false;
- }
- System.out
- .println("Invalid input. You shall enter y/yes/true or n/no/false.");
- } catch (final IOException ioe) {
- ioe.printStackTrace();
- }
- }
-
- /**
- * Ask numerical long value from user on command-line.
- *
- * @param prompt to show to the user
- * @return value given by user
- */
- public static long askLong(final String prompt) {
-
- final BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
-
- while (true) {
- System.out.print(prompt);
-
- try {
- final String userInput = br.readLine();
-
- try {
- return Long.parseLong(userInput);
- } catch (final NumberFormatException e) {
- System.out.println("\nError: You shall enter an integer.");
- }
- } catch (final IOException ioe) {
- ioe.printStackTrace();
- }
-
- }
- }
-
- /**
- * Ask string value from user on command-line.
- *
- * @param prompt to show to the user
- * @return value given by the user
- */
- public static String askString(final String prompt) {
-
- final BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
-
- while (true) {
- System.out.print(prompt);
-
- try {
- return br.readLine();
- } catch (final IOException ioe) {
- ioe.printStackTrace();
- }
-
- }
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser;
-
-public enum ArgumentCount {
-
- NONE, // parameter has no arguments
- SINGLE, // parameter has one argument
- MULTI // parameter can have multiple arguments
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public abstract class Parameter<T, I extends Parameter> {
-
- /**
- * Purpose of this argument, like: input image path, compression level, etc...
- *
- * Note: for describing argument type (file, integer, ...) there is {@link #describeFormat()}.
- */
- public final String description;
-
- public final List<String> arguments = new ArrayList<>();
- final ArgumentCount argumentCount;
- private final List<String> aliases = new ArrayList<>();
- /**
- * Indicates that at least one argument is mandatory for this parameter.
- */
- protected boolean mandatory;
- /**
- * If this parameter was present in the commandline, then this boolean will
- * be set to <code>true</code>.
- */
- private boolean specified;
-
- public Parameter(final boolean mandatory,
- final ArgumentCount argumentCount, final String description,
- final String... aliases2) {
-
- this.mandatory = mandatory;
- this.description = description;
- this.argumentCount = argumentCount;
-
- // save aliases
- Collections.addAll(aliases, aliases2);
-
- }
-
- public Parameter(final String description, final ArgumentCount argumentCount) {
- this.description = description;
- this.argumentCount = argumentCount;
- }
-
- @SuppressWarnings("unchecked")
- public I addAliases(final String... aliasArray) {
-
- // save aliases
- Collections.addAll(aliases, aliasArray);
-
- return (I) this;
- }
-
- /**
- * @param argumentString argument to add
- * @return <code>true</code> if no errors were found. <code>false</code>
- * otherwise.
- */
- public boolean addArgument(final String argumentString) {
- // check if arguments are allowed for this parameter
- if (argumentCount.equals(ArgumentCount.NONE)) {
- System.out
- .println("Error! No arguments are allowed for parameters: "
- + getAliases());
- return false;
- }
-
- // check if multiple arguments are allowed
- if ((arguments.size() > 0)
- && (argumentCount.equals(ArgumentCount.SINGLE))) {
- System.out
- .println("Error! Only single argument is allowed for parameters: "
- + getAliases());
- return false;
- }
-
- if (!validate(argumentString)) {
-
- System.out.println("Error! Invalid argument \"" + argumentString
- + "\". It shall be " + describeFormat() + ".");
- return false;
-
- }
-
- arguments.add(argumentString);
-
- return true;
- }
-
- /**
- * @return Single line argument type description. If argument type should be file,
- * date, integer, regular expression, etc..
- *
- * Note: for argument purpose description there is {@link #description}
- */
- public abstract String describeFormat();
-
- public String getAliases() {
- final StringBuilder buffer = new StringBuilder();
-
- for (final String alias : aliases) {
-
- if (buffer.length() > 0)
- buffer.append(", ");
-
- buffer.append(alias);
- }
-
- return buffer.toString();
- }
-
- public String getHelp() {
- final StringBuilder buffer = new StringBuilder();
-
- // first line
- buffer.append(getAliases());
- if (!argumentCount.equals(ArgumentCount.NONE)) {
- buffer
- .append(" (")
- .append(isMandatory() ? "mandatory, " : "")
- .append(describeFormat())
- .append(")");
-
- if (argumentCount.equals(ArgumentCount.MULTI))
- buffer.append("...");
- }
- buffer.append("\n");
-
- // second line
- buffer.append(" " + description + "\n");
-
- return buffer.toString();
- }
-
- public abstract T getValue();
-
- public boolean isMandatory() {
- return mandatory;
- }
-
- /**
- * @return the parameterSpecified
- */
- public boolean isSpecified() {
- return specified;
- }
-
- /**
- * @param specified the parameterSpecified to set
- */
- protected void setSpecified(final boolean specified) {
- this.specified = specified;
- }
-
- /**
- * @param alias alias to check against
- * @return <code>true</code> if given alias is registered for this
- * parameter.
- */
- public boolean matchesAlias(final String alias) {
- return aliases.contains(alias);
-
- }
-
- /**
- * Notifies this parameter that no more arguments will follow. This gives
- * parameter chance to verify if this is ok.
- *
- * @return <code>true</code> if no errors were found. <code>false</code>
- * otherwise.
- */
- public boolean noMoreArguments() {
-
- if ((!argumentCount.equals(ArgumentCount.NONE))
- && (arguments.isEmpty())) {
-
- System.out.println("Error! " + getAliases()
- + " require at least one following argument.");
-
- return false;
- }
- return true;
- }
-
- @SuppressWarnings("unchecked")
- public I setMandatory() {
- mandatory = true;
- return (I) this;
- }
-
- /**
- * @param value value to validate
- * @return <code>true</code> if value is correct, <code>false</code>
- * otherwise.
- */
- public abstract boolean validate(String value);
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser;
-
-import java.util.ArrayList;
-
-/**
- * <pre>
- * Single commandline parameter can have any amount of arguments.
- * </pre>
- */
-public class Parser {
-
- private final ArrayList<Parameter<?, ? extends Parameter>> parameters = new ArrayList<>();
-
- public <E extends Parameter> E add(final E parameter) {
- parameters.add(parameter);
- return parameter;
- }
-
- /**
- * @return <code>true</code> if no errors were found. <code>false</code>
- * otherwise.
- */
- private boolean checkMandatoryArgumentsPresent() {
-
- for (final Parameter parameter : parameters)
- if (parameter.isMandatory() && (!parameter.isSpecified())) {
- System.out.println("Error! Mandatory parameter ("
- + parameter.getAliases() + ") is not specified.");
- return false;
- }
-
- return true;
- }
-
- /**
- * Return parameter by given alias or <code>null</code> if no parameter
- * exists for given alias.
- *
- * @param alias parameter alias
- * @return found parameter or <code>null</code> if parameter was not found.
- */
- public Parameter findParameterByAlias(final String alias) {
-
- for (final Parameter parameter : parameters)
- if (parameter.matchesAlias(alias))
- return parameter;
-
- return null;
- }
-
- /**
- * @param args commandline arguments
- * @return <code>true</code> if no errors were found. <code>false</code>
- * otherwise.
- */
- public boolean parse(final String[] args) {
-
- Parameter currentParameter = null;
-
- for (final String argument : args) {
-
- final Parameter parameterForAlias = findParameterByAlias(argument);
- if (parameterForAlias == null) {
- if (currentParameter == null) {
- System.out.println("Unknown commandline parameter: "
- + argument);
- return false;
- }
-
- if (!currentParameter.addArgument(argument))
- return false;
-
- } else {
- if (currentParameter != null)
- if (!currentParameter.noMoreArguments())
- return false;
-
- parameterForAlias.setSpecified(true);
- currentParameter = parameterForAlias;
- }
-
- }
-
- return checkMandatoryArgumentsPresent();
- }
-
- public void showHelp() {
- System.out.println("Available commandline arguments:");
- for (final Parameter parameter : parameters)
- System.out.println(parameter.getHelp());
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-import java.io.File;
-
-public class DirectoryParameter extends Parameter<File, DirectoryParameter> {
-
- private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
-
- public DirectoryParameter(final String description) {
- super(description, ArgumentCount.SINGLE);
- }
-
- @Override
- public java.lang.String describeFormat() {
- return existenceType.description + " directory";
- }
-
- @Override
- public File getValue() {
-
- if (arguments.size() != 1)
- throw new RuntimeException("Parameter " + description
- + " shall have exactly 1 argument.");
-
- return new File(arguments.get(0));
- }
-
- public DirectoryParameter mustExist() {
- existenceType = ExistenceType.MUST_EXIST;
- return this;
- }
-
- public DirectoryParameter mustNotExist() {
- existenceType = ExistenceType.MUST_NOT_EXIST;
- return this;
- }
-
- @Override
- public boolean validate(final java.lang.String value) {
- final File file = new File(value);
-
- if (existenceType == ExistenceType.MUST_EXIST) {
- return file.exists() && file.isDirectory();
- }
-
- if (existenceType == ExistenceType.MUST_NOT_EXIST) {
- return !file.exists();
- }
-
- if (existenceType == ExistenceType.DOES_NOT_MATTER) {
- if (file.exists())
- if (file.isFile())
- return false;
-
- return true;
- }
-
- return false;
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-import java.io.File;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class DirectoryParameters extends Parameter<List<File>, DirectoryParameters> {
-
- private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
-
- public DirectoryParameters(final String description) {
- super(description, ArgumentCount.MULTI);
- }
-
- @Override
- public String describeFormat() {
- return existenceType.description + " directories";
- }
-
- @Override
- public List<File> getValue() {
- return arguments.stream().map(File::new).collect(Collectors.toList());
- }
-
- public DirectoryParameters mustExist() {
- existenceType = ExistenceType.MUST_EXIST;
- return this;
- }
-
- public DirectoryParameters mustNotExist() {
- existenceType = ExistenceType.MUST_NOT_EXIST;
- return this;
- }
-
- @Override
- public boolean validate(final String value) {
- final File file = new File(value);
-
- if (existenceType == ExistenceType.MUST_EXIST) {
- return file.exists() && file.isDirectory();
- }
-
- if (existenceType == ExistenceType.MUST_NOT_EXIST) {
- return !file.exists();
- }
-
- if (existenceType == ExistenceType.DOES_NOT_MATTER) {
- if (file.exists())
- if (file.isFile())
- return false;
-
- return true;
- }
-
- return false;
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-public enum ExistenceType {
-
- MUST_EXIST("existing"), MUST_NOT_EXIST("not existing"), DOES_NOT_MATTER("");
-
- public final String description;
-
- ExistenceType(final String description) {
- this.description = description;
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-import java.io.File;
-
-public class FileParameter extends Parameter<File, FileParameter> {
-
- private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
-
- public FileParameter(final String description) {
- super(description, ArgumentCount.SINGLE);
- }
-
- protected static boolean validateFile(ExistenceType existenceType, String value) {
- final File file = new File(value);
-
- if (existenceType == ExistenceType.MUST_EXIST) {
- return file.exists() && file.isFile();
- }
-
- if (existenceType == ExistenceType.MUST_NOT_EXIST) {
- return !file.exists();
- }
-
- if (existenceType == ExistenceType.DOES_NOT_MATTER) {
- if (file.exists())
- if (file.isDirectory())
- return false;
-
- return true;
- }
-
- return false;
- }
-
- @Override
- public java.lang.String describeFormat() {
- return existenceType.description + " file";
- }
-
- @Override
- public File getValue() {
-
- if (arguments.size() != 1)
- throw new RuntimeException("Parameter " + description
- + " shall have exactly 1 argument.");
-
- return new File(arguments.get(0));
- }
-
- public FileParameter mustExist() {
- existenceType = ExistenceType.MUST_EXIST;
- return this;
- }
-
- public FileParameter mustNotExist() {
- existenceType = ExistenceType.MUST_NOT_EXIST;
- return this;
- }
-
- @Override
- public boolean validate(final java.lang.String value) {
- return validateFile(existenceType, value);
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-import java.io.File;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static eu.svjatoslav.commons.commandline.parameterparser.parameter.FileParameter.validateFile;
-
-public class FileParameters extends Parameter<List<File>, FileParameters> {
-
- private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
-
- public FileParameters(final String description) {
- super(description, ArgumentCount.MULTI);
- }
-
- @Override
- public String describeFormat() {
- return existenceType.description + " files";
- }
-
- @Override
- public List<File> getValue() {
- return arguments.stream().map(File::new).collect(Collectors.toList());
- }
-
- public FileParameters mustExist() {
- existenceType = ExistenceType.MUST_EXIST;
- return this;
- }
-
- public FileParameters mustNotExist() {
- existenceType = ExistenceType.MUST_NOT_EXIST;
- return this;
- }
-
- @Override
- public boolean validate(final String value) {
- return validateFile(existenceType, value);
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-public class IntegerParameter extends Parameter<Integer, IntegerParameter> {
-
- public IntegerParameter(final String description) {
- super(description, ArgumentCount.SINGLE);
- }
-
- @Override
- public java.lang.String describeFormat() {
- return "integer";
- }
-
- @Override
- public Integer getValue() {
- if (arguments.size() != 1)
- throw new RuntimeException("Parameter " + description
- + " shall have exactly 1 argument.");
- return Integer.parseInt(arguments.get(0));
- }
-
- @Override
- public boolean validate(final java.lang.String value) {
- try {
- java.lang.Integer.valueOf(value);
- return true;
- } catch (final NumberFormatException e) {
- return false;
- }
- }
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-public class NullParameter extends Parameter<Boolean, NullParameter> {
-
- public NullParameter(final String description) {
- super(description, ArgumentCount.NONE);
- }
-
- @Override
- public java.lang.String describeFormat() {
- return "<none>";
- }
-
- @Override
- public Boolean getValue() {
- return isSpecified();
- }
-
- @Override
- public boolean validate(final java.lang.String value) {
- return true;
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-public class StringParameter extends Parameter<String, StringParameter> {
-
- public final String defaultValue;
-
- public StringParameter(final String description) {
- super(description, ArgumentCount.SINGLE);
- defaultValue = null;
- }
- public StringParameter(final String description, String defaultValue) {
- super(description, ArgumentCount.SINGLE);
- this.defaultValue = defaultValue;
- this.setSpecified(true);
- }
-
- @Override
- public java.lang.String describeFormat() {
- return "string";
- }
-
- @Override
- public String getValue() {
-
- if (arguments.isEmpty() && (defaultValue != null)) return defaultValue;
-
- if (arguments.size() == 1) return arguments.get(0);
-
- throw new RuntimeException("Parameter " + description
- + " shall have exactly 1 argument.");
- }
-
- @Override
- public boolean validate(final java.lang.String value) {
- return true;
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser.parameter;
-
-import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-
-import java.util.List;
-
-public class StringParameters extends Parameter<List<String>, StringParameters> {
-
- public StringParameters(final String description) {
- super(description, ArgumentCount.MULTI);
- }
-
- @Override
- public java.lang.String describeFormat() {
- return "one to many strings";
- }
-
- @Override
- public List<String> getValue() {
- return arguments;
- }
-
- @Override
- public boolean validate(final java.lang.String value) {
- return true;
- }
-
-}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.commons.commandline.parameterparser;
-
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.FileParameter;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import static org.junit.Assert.*;
-
-public class ParserTest {
-
- Parser parser;
-
- @Before
- public void setUp() {
- parser = new Parser();
- }
-
- @Test
- public void testParse() throws IOException {
-
- // define allowed parameters
- final StringParameter helpParameter = parser.add(new StringParameter("Show help screen")
- .addAliases("--help", "-h").setMandatory());
-
- final StringParameter compileParameter = parser.add(new StringParameter("Compile code"))
- .addAliases("--compile", "-c");
-
- FileParameter fileParameter = parser.add(new FileParameter("Input file")
- .addAliases("-i").mustExist());
-
- createTemporaryFile();
-
- // check help generation
- parser.showHelp();
-
- // parse arguments
- parser.parse(new String[]{"--help", "section", "-i", "/tmp/file with spaces"});
-
- // --help was in the arguments
- assertTrue(helpParameter.isSpecified());
-
- // compile was not present
- assertFalse(compileParameter.isSpecified());
-
- // validate that help argument was "section"
- assertEquals("section", helpParameter.getValue());
-
- assertTrue(fileParameter.isSpecified());
- assertEquals("/tmp/file with spaces", fileParameter.getValue().getAbsolutePath());
-
- }
-
- private void createTemporaryFile() throws IOException {
- File fileWithSpaces = new File("/tmp/file with spaces");
- FileWriter writer = new FileWriter(fileWithSpaces);
- writer.write("test");
- writer.close();
- }
-}