https://github.com/trptr/java-wrapper
Clojure wrappers for various Java classes.
https://github.com/trptr/java-wrapper
clojure java locale wrapper
Last synced: 4 months ago
JSON representation
Clojure wrappers for various Java classes.
- Host: GitHub
- URL: https://github.com/trptr/java-wrapper
- Owner: trptr
- License: gpl-3.0
- Created: 2018-12-26T15:04:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-28T21:46:18.000Z (almost 7 years ago)
- Last Synced: 2025-08-17T13:17:31.485Z (5 months ago)
- Topics: clojure, java, locale, wrapper
- Language: Clojure
- Size: 101 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
# java-wrapper
Clojure wrappers for various Java classes.
[](https://clojars.org/trptr/java-wrapper)
## Goal
Provide APIs for Java classes that make their usage comfortable within Clojure.
For example, compare the usage of `java.util.Locale$Builder.build` in the standard way:
```clojure
(-> (Locale$Builder.)
(.setLanguage "ru")
(.setScript "Cyrl")
(.build))
```
with the equivalent code using `trptr.java-wrapper.locale/build`:
```clojure
(build {:language "ru"
:script "Cyrl"})
```
The latter is idiomatic Clojure, so can be used in idiomatic Clojure ways comfortably, e.g.
the map can be `merge`d with other maps, mappings can be `assoc`ed, `dissoc`ed or selected, etc.
Moreover, in simpler cases a keyword (or a string...) can substitute a complete object,
which is then created on the fly, behind the scenes, as needed:
```clojure
(get-display-name :de-ch :en)
```
(using `get-display-name` from the `ns` `trptr.java-wrapper.locale`) is equivalent to
```clojure
(.getDisplayName (Locale. "de" "CH") (Locale. "en"))
```
## Documentation
* this readme
* [API and namepace docs](http://trptr.github.io/java-wrapper/index.html)
* [tests](test/trptr/java_wrapper): simple usage examples
## Status
The latest version is 0.2.3, containing wrappers for 1 class: `java.util.Locale`.
Coming soon: `java.text.NumberFormat`.
Bug reports and new wrapper requests [are welcome](https://github.com/trptr/java-wrapper/issues/new/choose).
## Usage
### Via `deps.edn`
#### Using a git url
Include a dependency on this repo in your `deps.edn`. For example:
```clojure
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
trptr/java-wrapper {:git/url "https://github.com/trptr/java-wrapper.git"
:sha "66a41e22bbdc67fab2a5039c551c5c79dc9b662f"}}}
```
#### Using mvn version
Include a dependency on the mvn version in your `deps.edn`. For example:
```clojure
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
trptr/java-wrapper {:mvn/version "0.2.3"}}}
```
### Via Leiningen
Include a dependency on the mvn version in your `project.clj`. For example:
```clojure
:dependencies [[org.clojure/clojure "1.10.0"]
[trptr/java-wrapper "0.2.3"]]
```
### Others
See https://clojars.org/trptr/java-wrapper.
### Inside your `ns`
Require the proper trptr namespace(s). For example:
```clojure
(ns my-namespace
(:require [trptr.java-wrapper.locale :as jwl]))
(defn -main
[& _]
(->> jwl/available-locales
(map jwl/get-display-name)
sort
(clojure.string/join "\n")
println))
```
## Copyright and License
Copyright 2018, 2019 trptr
trptr/java-wrapper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
If you need other licensing, let me know!