{"id":22269479,"url":"https://github.com/floriande/jextensions","last_synced_at":"2026-02-13T06:06:29.115Z","repository":{"id":126869399,"uuid":"220487092","full_name":"FlorianDe/jextensions","owner":"FlorianDe","description":"A custom Java library for frequently used functions, algorithms and boilerplate code reduction. Provides precompiled github packages to use as dependencies in maven/gradle.","archived":false,"fork":false,"pushed_at":"2024-12-15T22:19:18.000Z","size":85,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-15T23:20:23.766Z","etag":null,"topics":["extensions","gradle","java","java-library","library"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlorianDe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-08T14:47:40.000Z","updated_at":"2024-12-15T22:19:20.000Z","dependencies_parsed_at":"2023-06-18T12:19:09.736Z","dependency_job_id":null,"html_url":"https://github.com/FlorianDe/jextensions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianDe%2Fjextensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianDe%2Fjextensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianDe%2Fjextensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianDe%2Fjextensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlorianDe","download_url":"https://codeload.github.com/FlorianDe/jextensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236360634,"owners_count":19136681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extensions","gradle","java","java-library","library"],"created_at":"2024-12-03T11:16:36.247Z","updated_at":"2026-02-13T06:06:29.085Z","avatar_url":"https://github.com/FlorianDe.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JExtensions\n[![CI Build](https://github.com/FlorianDe/jextensions/actions/workflows/build.yml/badge.svg)](https://github.com/FlorianDe/jextensions/actions/workflows/build.yml)\n[![CI Test](https://github.com/FlorianDe/jextensions/actions/workflows/test.yml/badge.svg)](https://github.com/FlorianDe/jextensions/actions/workflows/test.yml)\n[![GitHub Release](https://img.shields.io/github/v/release/FlorianDe/jextensions?label=Version)](https://github.com/FlorianDe/jextensions/releases)\n[![GitHub commits since latest release](https://img.shields.io/github/commits-since/FlorianDe/jextensions/latest)\n](https://github.com/FlorianDe/jextensions/commits/main/)\n[![GitHub License](https://img.shields.io/github/license/floriande/jextensions)\n](LICENSE)\n\n\nJExtensions is a custom Java library that simplifies your development process by providing frequently used functions, algorithms, and utilities. Designed to reduce boilerplate code, this library is a handy toolset for any Java project. It includes utilities for file locking, random selection, assertion helpers, and array operations. \n\nAdditionally, precompiled GitHub packages are available for seamless integration with Maven or Gradle.\n\n---\n\n## Features\n\n### 1. **io.file**\n   - **Single Instance Lock Checker**: Prevent multiple instances of an application or process by implementing a file-based lock mechanism.\n\n### 2. **math.distribution**\n   - **Random Picker Library**: Various strategies for selecting random items from a dataset:\n     - **VoseAliasRandomSelector**: Efficient implementation of the Alias Method for weighted random selection.\n     - **LinearSearchSelector**: Straightforward random selection using a linear search approach.\n     - **BinarySearchRandomSelector**: Optimized for weighted random selection with binary search.\n\n### 3. **util**\n   - **Assertions**: Simplify common assertions to make your code more readable and less error-prone.\n   - **Array Utilities**: A collection of helper methods to work with arrays efficiently.\n\n---\n\n## Getting Started\n\n### Prerequisites\n- Java 8 or higher\n- Maven or Gradle for dependency management\n\n### Installation\n\n#### Using Maven\nAdd the following dependency to your `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.floriande\u003c/groupId\u003e\n    \u003cartifactId\u003ejextensions\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Using Gradle\nAdd the following dependency to your `build.gradle`:\n\n```gradle\nimplementation 'com.github.floriande:jextensions:0.1.0'\n```\n\n---\n\n## Usage\n\n### Single Instance Lock Checker\n```java\nif (new SingleInstanceLock().isSingleInstanceRunning()) {\n    log.error(\"An instance of this application is already running!\");\n    System.exit(1);\n} \n//TODO Try to show/open the running application!\n```\n\n### Random Pickers\n```java\n// VoseAliasRandomSelector example\nMap\u003cInteger, Double\u003e elements = Map.of(\n        1, 0.15,\n        2, 0.6,\n        3, 0.25,\n);\n\nDistributionCollection\u003cInteger\u003e distributionCollection = DistributionCollectionFactory.createWeighted(\n        elements.keySet(),\n        elements::get,\n        VoseAliasRandomSelector::new\n);\n\nRandom random = new Random(); // possible to add a seed\ndistributionCollection.next(random);\n```\n\nFor more infos and benchmarks check [DistributionCollectionTest.java](src/test/java/de/florian/jextensions/math/distribution/DistributionCollectionTest.java).\n\n### Utility Methods\n#### Array Utils\nThe `ArrayUtils` class offers helpful methods for working with collections and arrays, providing functionality to simplify common array operations. Here's a quick overview:\n\n1. **`copyFromCollection(Collection\u003cT\u003e values)`**\n   - Creates a new array containing all elements from a given collection.\n   - The resulting array is typed based on the collection elements.\n   - Example:\n     ```java\n     String[] array = ArrayUtils.copyFromCollection(new String[] {\"Hello\", \"World\"});\n     ```\n\n2. **`normalize(double[] values)`**\n   - Normalizes the values in an array so their sum equals `1.0`.\n   - Handles cases where the array contains zeros or very small values without throwing errors.\n   - Example:\n     ```java\n     double[] normalized = ArrayUtils.normalize(new double[] {1.0, 2.0, 3.0});\n     ```\n\n3. **`normalize(double[] values, double normalizedSum)`**\n   - Similar to the above method but allows you to specify a desired sum for the normalized values.\n   - Throws `IllegalArgumentException` if any value in the array or the `normalizedSum` is `NaN` or `Infinity`.\n   - Example:\n     ```java\n     double[] normalized = ArrayUtils.normalize(new double[] {1.0, 2.0, 3.0}, 100.0);\n     ```\n\n#### Checker\nThe `Checker` class provides utility methods to simplify common validation (assertion) checks in your code, reducing boilerplate and improving readability. Below is a brief overview of the available methods:\n\n1. **`requireNonNullAndNotEmpty(Collection\u003cT\u003e collection, String name)`**\n   - Ensures that a collection is not `null` and is not empty.\n   - Throws `IllegalArgumentException` if the validation fails.\n   - Example:\n     ```java\n     Checker.requireNonNullAndNotEmpty(myList, \"myList\");\n     ```\n\n2. **`requireCondition(boolean expression, String messageFormat, Object... parameters)`**\n   - Validates that a condition is true.\n   - Throws `IllegalArgumentException` with a formatted message if the condition is false.\n   - Example:\n     ```java\n     Checker.requireCondition(x \u003e 0, \"Value must be greater than zero: %d\", x);\n     ```\n\n3. **`requireGreaterThanZero(T number)`**\n   - Ensures a numeric value is greater than zero.\n   - Returns the number if valid, or throws `IllegalArgumentException` otherwise.\n   - Example:\n     ```java\n     int positiveNumber = Checker.requireGreaterThanZero(42);\n     ```\n\n---\n\n## Contributing\nContributions are welcome! Please fork this repository and submit a pull request with your improvements or new features.\n\n### Steps to Contribute\n1. Fork the repository.\n2. Create a new branch: `git checkout -b feature/branch-name`.\n3. Make your changes and commit them: `git commit -m 'Add some feature'`.\n4. Push to the branch: `git push origin feature/branch-name`.\n5. Submit a pull request.\n\n---\n\n## License\nThis project is licensed under the **GNU General Public License v3.0 (GPL-3.0)** License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n## Contact\nIf you have any questions or feedback, feel free to open an issue or contact the repository owner.\n\n---\n\n## Acknowledgments\nInspired by common developer needs to simplify Java project workflows.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloriande%2Fjextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloriande%2Fjextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloriande%2Fjextensions/lists"}