Liking cljdoc? Tell your friends :D

java-wrapper

Clojure wrappers for various Java classes.

Clojars Project

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:

(-> (Locale$Builder.)
    (.setLanguage "ru")
    (.setScript   "Cyrl")
    (.build))

with the equivalent code using trptr.java-wrapper.locale/build:

(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 merged with other maps, mappings can be assoced, dissoced 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:

(get-display-name :de-ch :en)

(using get-display-name from the ns trptr.java-wrapper.locale) is equivalent to

(.getDisplayName (Locale. "de" "CH") (Locale. "en"))

Documentation

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.

Usage

Via deps.edn

Using a git url

Include a dependency on this repo in your deps.edn. For example:

{: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:

{: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:

: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:

(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!

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close