{"id":13733986,"url":"https://github.com/greenrobot/essentials","last_synced_at":"2025-12-17T22:32:19.660Z","repository":{"id":22830292,"uuid":"26177368","full_name":"greenrobot/essentials","owner":"greenrobot","description":"General purpose utilities and hash functions for Android and Java (aka java-common)","archived":false,"fork":false,"pushed_at":"2021-03-22T07:44:57.000Z","size":1041,"stargazers_count":1357,"open_issues_count":1,"forks_count":193,"subscribers_count":65,"default_branch":"main","last_synced_at":"2025-05-05T13:17:08.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/greenrobot.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}},"created_at":"2014-11-04T16:22:18.000Z","updated_at":"2025-05-02T00:47:38.000Z","dependencies_parsed_at":"2022-08-17T17:00:34.011Z","dependency_job_id":null,"html_url":"https://github.com/greenrobot/essentials","commit_stats":null,"previous_names":["greenrobot/greenrobot-common"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenrobot%2Fessentials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenrobot%2Fessentials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenrobot%2Fessentials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenrobot%2Fessentials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greenrobot","download_url":"https://codeload.github.com/greenrobot/essentials/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254436944,"owners_count":22070946,"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":[],"created_at":"2024-08-03T03:00:51.532Z","updated_at":"2025-12-17T22:32:14.615Z","avatar_url":"https://github.com/greenrobot.png","language":"Java","readme":"# Essentials\n\n[![Build Status](https://travis-ci.org/greenrobot/essentials.svg?branch=main)](https://travis-ci.org/greenrobot/essentials) \n\nEssentials are a collection of general-purpose classes we found useful in many occasions.\n\n- Beats standard Java API performance, e.g. `LongHashMap` can be twice as fast as `HashMap\u003cLong, Object\u003e`.\n- Adds missing pieces without pulling in heavy-weights like Guava  \n- Improved convenience: do more with less code\n- Super lightweight: \u003c 100k in size\n- Compatible with Android and Java\n\nThis project is bare bones compared to a rich menu offered by Guava or Apache Commons. Essentials is not a framework, it's rather a small set of utilities to make Java standard approaches more convenient or more efficient.\n\n[Website][1] | [JavaDoc](http://greenrobot.org/files/essentials/javadoc/3.0/) | [Changelog][13]\n\n## Features\n\n- [Hash set][6] and [map][7] for primitive long keys outperform the generic versions of the Java Collection APIs\n- [Multimaps][9] provide a map of lists or sets to simplify storing multiple values for a single key\n- [Object cache][10] with powerful configuration options: soft/weak/strong references, maximum size, and time-based expiration\n- [IO utilities][2] help with streams (byte and character based)\n- [File utilities][3] simplify reading and writing strings/bytes/objects from or to files. Also includes getting hashes from files and copying files.\n- [String utilities][4] allow efficient splitting and joining of strings, fast hex creation, and other useful string helpers.\n- [Date utilities][5]\n- [Better hash functions][12]: our Murmur3 implementation provides superior hash quality and outperforms standard [Java hash functions](web-resources/hash-functions-benchmark.pdf)\n- Specialized Streams: for example an optimized [PipedOutputStream replacement][8] (based on a circular byte buffer)\n\nRead more on our [website][14].\n\n## Performance\n\nSome classes where motivated by less than optimal performance offered by standard Java.\n\nFor long keys (also works for int), Essentials provides a specialized implementation, that can be twice as fast.\n\nHere are some (completely non-scientific) benchmarking results running on Ubuntu 20.04 LTS using OpenJDK 11.0.9:   \n\n| Essentials Class        | Java (seconds) | Essentials (seconds)  | Speed up |\n|-------------------------|---------------:|----------------------:|:--------:|\n| LongHashSet (Dynamic)   |         19.756 |                13.079 |   + 51%  |\n| LongHashSet (Prealloc)  |         16.480 |                 8.171 |  + 102%  |\n| LongHashMap (Dynamic)   |         20.311 |                14.659 |   + 39%  |\n| LongHashMap (Prealloc)  |         17.496 |                 8.677 |  + 102%  |\n| PipelineStream (1024KB) |          8.036 |                 1.424 |  + 564%  |\n| StringHex (vs. Guava)   |          6.849 |                 3.732 |   + 84%  |\n\nThe benchmarking sources are available in the java-essentials-performance directory.\n\n## Add the dependency to your project\n\nFor Gradle, you add this dependency (from repository `mavenCentral()`):\n \n    implementation 'org.greenrobot:essentials:3.1.0'\n\nAnd for Maven:\n    \n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.greenrobot\u003c/groupId\u003e\n        \u003cartifactId\u003eessentials\u003c/artifactId\u003e\n        \u003cversion\u003e3.1.0\u003c/version\u003e\n    \u003c/dependency\u003e\n\n## Code samples\n\nExample code for some of the utility classes: \n\n```Java\n// Get all bytes from stream and close the stream safely\nbyte[] bytes = IoUtils.readAllBytesAndClose(inputStream);\n\n// Read the contents of an file as a string (use readBytes to get byte[])\nString contents = FileUtils.readUtf8(file);\n\n// How many days until new year's eve?\nlong time2 = DateUtils.getTimeForDay(2015, 12, 31);\nint daysToNewYear = DateUtils.getDayDifference(time, time2);\n```\n\nMultimaps:\n```Java\nListMap\u003cString,String\u003e multimap = new ListMap\u003c\u003e();\nmultimap.putElement(\"a\", \"1\");\nmultimap.putElement(\"a\", \"2\");\nmultimap.putElement(\"a\", \"3\");\nList\u003cString\u003e strings = multimap.get(\"a\"); // Contains \"1\", \"2\", and \"3\"\n```\n\n[Our hash functions][12] implement [java.util.zip.Checksum](http://docs.oracle.com/javase/8/docs/api/java/util/zip/Checksum.html), so this code might look familiar to you:\n\n```Java\nMurmur3A murmur = new Murmur3A();\nmurmur.update(bytes);\nlong hash = murmur.getValue();\n```\n\nAll hashes can be calculated progressively by calling update(...) multiple times. Our Murmur3A implementation goes a step further by offering updates with primitive data in a very efficient way:\n```Java\n// reuse the previous instance and start over to calculate a new hash\nmurmur.reset();\n\nmurmur.updateLong(42L);\n\n// Varargs and arrays are supported natively, too  \nmurmur.updateInt(2014, 2015, 2016);\n\n// Hash for the previous update calls. No conversion to byte[] necessary.\nhash = murmur.getValue();\n```\n \nThe utility classes are straight forward and don't have dependencies, so you should be fine to grasp them by having a look at their source code. Most of the method names should be self-explaining, and often you'll find JavaDocs where needed.\n\n## Build setup\n\nWe use Gradle as a primary build system.\nPreviously, Maven is used to build greenrobot-common. Inside of [build-common](build-common), there are two parent POMs defined that might be useful: parent-pom and parent-pom-with-checks. The latter integrates FindBugs and Checkstyle in your build. Use it like this: \n\n    \u003cparent\u003e\n        \u003cgroupId\u003ede.greenrobot\u003c/groupId\u003e\n        \u003cartifactId\u003eparent-pom-with-checks\u003c/artifactId\u003e\n        \u003cversion\u003e2.0.0\u003c/version\u003e\n        \u003crelativePath\u003e\u003c/relativePath\u003e\n    \u003c/parent\u003e\n\n## License\n\nCopyright (C) 2012-2020 Markus Junginger, greenrobot (https://greenrobot.org)\n\nEventBus binaries and source code can be used according to the [Apache License, Version 2.0](LICENSE).\n\n# More by greenrobot\n\n[__EventBus__](https://github.com/greenrobot/EventBus) is a central publish/subscribe bus for Android with optional delivery threads, priorities, and sticky events. A great tool to decouple components (e.g. Activities, Fragments, logic components) from each other. \n \n[__ObjectBox__](https://github.com/objectbox/objectbox-java) super-fast object database.\n\n[1]: https://greenrobot.org/essentials\n[2]: java-essentials/src/main/java/org/greenrobot/essentials/io/IoUtils.java\n[3]: java-essentials/src/main/java/org/greenrobot/essentials/io/FileUtils.java\n[4]: java-essentials/src/main/java/org/greenrobot/essentials/StringUtils.java\n[5]: java-essentials/src/main/java/org/greenrobot/essentials/DateUtils.java\n[6]: java-essentials/src/main/java/org/greenrobot/essentials/collections/LongHashSet.java\n[7]: java-essentials/src/main/java/org/greenrobot/essentials/collections/LongHashMap.java\n[8]: java-essentials/src/main/java/org/greenrobot/essentials/io/PipelineOutputStream.java\n[9]: java-essentials/src/main/java/org/greenrobot/essentials/collections/Multimap.java\n[10]: java-essentials/src/main/java/org/greenrobot/essentials/ObjectCache.java\n[12]: https://greenrobot.org/essentials/features/performant-hash-functions-for-java/\n[13]: https://greenrobot.org/essentials/changelog\n[14]: https://greenrobot.org/essentials/features\n","funding_links":[],"categories":["I. Development","工具库","Utility"],"sub_categories":["1. Common frameworks and libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenrobot%2Fessentials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreenrobot%2Fessentials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenrobot%2Fessentials/lists"}