Popularity
4.0
Stable
Activity
7.9
Growing
303
17
58

Code Quality Rank: L1
Programming language: Java
License: MIT License
Latest version: v1.58

underscore-java alternatives and similar libraries

Based on the "Functional Programming" category

Do you think we are missing an alternative of underscore-java or a related project?

Add another 'Functional Programming' Library

README

underscore-java

Maven Central MIT License Build Status Coverage Status codecov.io CircleCI Codeship Status for javadev/underscore-java wercker status Build status Build Status Run Status Known Vulnerabilities Codacy Badge Sputnik Code Scene BCH compliance Quality Gate Quality Gate Scrutinizer Build Status Hits-of-Code Java Version

Join the chat at https://gitter.im/javadev/underscore-java

Requirements

Java 1.6 and later, Java 1.8 or Java 11.

Installation

Include the following in your pom.xml for Maven:

<dependencies>
  <dependency>
    <groupId>com.github.javadev</groupId>
    <artifactId>underscore</artifactId>
    <version>1.58</version>
  </dependency>
  ...
</dependencies>

Gradle:

compile 'com.github.javadev:underscore:1.58'

Usage

U.chain(/* array | list | set | map | anything based on Iterable interface */)
    .filter(..)
    .map(..)
    ...
    .sortWith()
    .forEach(..);
U.chain(value1, value2, value3)...
U.range(0, 10)...

U.chain(1, 2, 3) // or java.util.Arrays.asList(1, 2, 3) or new Integer[] {1, 2, 3}
    .filter(v -> v > 1)
    // 2, 3
    .map(v -> v + 1)
    // 3, 4
    .sortWith((a, b) -> b.compareTo(a))
    // 4, 3
    .forEach(System.out::println);
    // 4, 3

U.formatXml("<a><b>data</b></a>");
    // <a>
    //    <b>data</b>
    // </a>

U.formatJson("{\"a\":{\"b\":\"data\"}}");
    // {
    //    "a": {
    //      "b": "data"
    //    }
    // }

U.xmlToJson("<a><b>data</b></a>");
    // {
    //   "a": {
    //     "b": "data"
    //   },
    //   "#omit-xml-declaration": "yes"
    // }

U.jsonToXml("{\"a\":{\"b\":\"data\"}}");
    // <?xml version="1.0" encoding="UTF-8"?>
    // <a>
    //   <b>data</b>
    // </a>

Map<String, Object> value = U.objectBuilder()
    .add("firstName", "John")
    .add("lastName", "Smith")
    .add("age", 25)
    .add("address", U.arrayBuilder()
        .add(U.objectBuilder()
            .add("streetAddress", "21 2nd Street")
            .add("city", "New York")
            .add("state", "NY")
            .add("postalCode", "10021")))
    .add("phoneNumber", U.arrayBuilder()
        .add(U.objectBuilder()
            .add("type", "home")
            .add("number", "212 555-1234"))
        .add(U.objectBuilder()
            .add("type", "fax")
            .add("number", "646 555-4567")))
    .build();
    // {firstName=John, lastName=Smith, age=25, address=[{streetAddress=21 2nd Street,
    // city=New York, state=NY, postalCode=10021}], phoneNumber=[{type=home, number=212 555-1234},
    // {type=fax, number=646 555-4567}]}

Underscore-java is a java port of Underscore.js.

In addition to porting Underscore's functionality, Underscore-java includes matching unit tests.

For docs, license, tests, and downloads, see: http://javadev.github.io/underscore-java

Thanks to Jeremy Ashkenas and all contributors to Underscore.js.


*Note that all licence references and agreements mentioned in the underscore-java README section above are relevant to that project's source code only.