{"id":50842888,"url":"https://github.com/nanolaba/sugar","last_synced_at":"2026-06-14T07:35:04.021Z","repository":{"id":353258049,"uuid":"780652860","full_name":"nanolaba/sugar","owner":"nanolaba","description":"A tiny, zero-dependency Java library of static syntactic-sugar helpers — one class, one purpose: cut the boilerplate out of everyday Java","archived":false,"fork":false,"pushed_at":"2026-04-23T06:54:07.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-14T07:35:03.666Z","etag":null,"topics":["checked-exceptions","java","java8","lambdas","library","maven-central","memoization","syntactic-sugar","utility"],"latest_commit_sha":null,"homepage":"https://github.com/nanolaba/sugar","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanolaba.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-01T22:55:43.000Z","updated_at":"2026-04-23T06:54:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/nanolaba/sugar","commit_stats":null,"previous_names":["nanolaba/sugar"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nanolaba/sugar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanolaba%2Fsugar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanolaba%2Fsugar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanolaba%2Fsugar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanolaba%2Fsugar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanolaba","download_url":"https://codeload.github.com/nanolaba/sugar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanolaba%2Fsugar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34313515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["checked-exceptions","java","java8","lambdas","library","maven-central","memoization","syntactic-sugar","utility"],"created_at":"2026-06-14T07:35:02.074Z","updated_at":"2026-06-14T07:35:04.014Z","avatar_url":"https://github.com/nanolaba.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- This file was automatically generated by Nanolaba Readme Generator (NRG) 0.4-SNAPSHOT --\u003e\n\u003c!-- Visit https://github.com/nanolaba/readme-generator for details --\u003e\n\n\n[ **en** | [ru](README.ru.md) ]\n\n# Sugar\n\n[![CI](https://github.com/nanolaba/sugar/actions/workflows/ci.yml/badge.svg)](https://github.com/nanolaba/sugar/actions/workflows/ci.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/com.nanolaba/sugar?label=Maven%20Central)](https://central.sonatype.com/artifact/com.nanolaba/sugar)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)\n![Java](https://img.shields.io/badge/Java-8%2B-blue)\n\nA tiny, zero-dependency Java library of static syntactic-sugar helpers — one class, one purpose: cut the boilerplate out of everyday Java.\n\nThe whole library is a single class, `com.nanolaba.sugar.Code`, with helpers for the most common friction points: running lambdas that throw checked exceptions, multi-value equality checks, and lazy memoization.\n\n## Table of contents\n1. [Requirements](#requirements)\n2. [Installation](#installation)\n\t1. [Snapshot versions](#snapshot-versions)\n3. [Usage](#usage)\n\t1. [`run` — checked exceptions out of the way](#run-checked-exceptions-out-of-the-way)\n\t2. [`runQuietly` — swallow, or fall back to a default](#runquietly-swallow-or-fall-back-to-a-default)\n\t3. [`equalsAny` — null-safe multi-value equality](#equalsany-null-safe-multi-value-equality)\n\t4. [`memoize` — lazy, thread-safe, compute-at-most-once](#memoize-lazy-thread-safe-compute-at-most-once)\n4. [Building from source](#building-from-source)\n5. [Links](#links)\n6. [License](#license)\n\n\n## Requirements\n\n- Java 8+\n- Maven 3.x (to build from source)\n\n## Installation\n\nReleased artifacts are published to **Maven Central** — no extra repository configuration is required.\n\n**Maven**\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.nanolaba\u003c/groupId\u003e\n    \u003cartifactId\u003esugar\u003c/artifactId\u003e\n    \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**Gradle**\n\n```groovy\ndependencies {\n    implementation 'com.nanolaba:sugar:1.0'\n}\n```\n\n### Snapshot versions\n\nTo use a development snapshot, add the Sonatype Central snapshot repository:\n\n```xml\n\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ecentral.sonatype.com-snapshot\u003c/id\u003e\n        \u003curl\u003ehttps://central.sonatype.com/repository/maven-snapshots\u003c/url\u003e\n        \u003csnapshots\u003e\n            \u003cenabled\u003etrue\u003c/enabled\u003e\n            \u003cupdatePolicy\u003ealways\u003c/updatePolicy\u003e\n        \u003c/snapshots\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n## Usage\n\nAll helpers are `static` methods on `Code`. A static import keeps call sites tidy:\n\n```java\nimport static com.nanolaba.sugar.Code.*;\n```\n\n### `run` — checked exceptions out of the way\n\nWraps a lambda that may throw a checked `Exception`. Any exception is rethrown as a `RuntimeException`; unchecked exceptions and `Error`s pass through unchanged.\n\n```java\n// With a return value\nbyte[] content = run(() -\u003e Files.readAllBytes(path));\n\n// Side effect only\nrun(() -\u003e Thread.sleep(100));\n```\n\n### `runQuietly` — swallow, or fall back to a default\n\nSwallows any exception from the lambda. The overload with a default `Supplier` returns that default when an exception occurs — the supplier is only evaluated on failure.\n\n```java\n// Fall back to a default\nint port = runQuietly(() -\u003e Integer.parseInt(System.getenv(\"PORT\")), () -\u003e 8080);\n\n// Fire-and-forget\nrunQuietly(() -\u003e socket.close());\n```\n\n### `equalsAny` — null-safe multi-value equality\n\nReturns `true` if the first argument equals any of the following ones, using `Objects.equals` (so `null` is compared safely).\n\n```java\nif (equalsAny(status, \"OK\",\"READY\",\"IDLE\")) {\n    // ...\n}\n```\n\n### `memoize` — lazy, thread-safe, compute-at-most-once\n\nWraps a `Supplier\u003cT\u003e` so its value is computed at most once. The first `get()` is `synchronized`; afterwards the delegate replaces itself and every subsequent call is a plain field read with no locking.\n\n```java\nSupplier\u003cConfig\u003e config = memoize(() -\u003e loadConfigFromDisk());\nconfig.get(); // reads from disk\nconfig.get(); // cached, no lock\n```\n\n## Building from source\n\n```bash\nmvn clean install\n```\n\nThe build runs PIT mutation testing with a 100% threshold — any surviving mutant fails the build. When adding code, expect to cover every branch and boundary with assertions.\n\n## Links\n\n- Source code: [https://github.com/nanolaba/sugar](https://github.com/nanolaba/sugar)\n- Issue tracker: [https://github.com/nanolaba/sugar/issues](https://github.com/nanolaba/sugar/issues)\n- Maven Central: [central.sonatype.com/artifact/com.nanolaba/sugar](https://central.sonatype.com/artifact/com.nanolaba/sugar)\n\n## License\n\nReleased under the [Apache License 2.0](LICENSE).\n\n---\n*Generated with [nanolaba/readme-generator](https://github.com/nanolaba/readme-generator) — 23.04.2026*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanolaba%2Fsugar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanolaba%2Fsugar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanolaba%2Fsugar/lists"}