AbacusUtil Docs | Download | Javadoc | FAQ | Community

Release the power in Java programming

AbacusUtil is a general programming library/framework in Java. It's simple, powerful and easy to use with concise APIs. To provide the unmatchable programming experiences and high performance solutions, We think the API design and implementation again and again. First, let's take a quick look:

  • range/repeat/concat/stringOf/valueOf/as/...
  • int[] a = Array.range(1, 3);
    int[] b = Array.rangeClosed(3, 7);
    int[] c = N.concat(a, b);
    String str = N.stringOf(c);
    N.println(str); // [1, 2, 3, 4, 5, 6, 7]
    int[] d = N.valueOf(int[].class, str);
    assertTrue(N.equals(c, d));
    IntList.of(d).filter(e -> e % 2 == 0).average().ifPresent(N::println);
    
    List<String> list = N.asList("abc", "1", "2", "3");
    Map<String, Integer> map = N.asMap("a", 1, "b", 2, "c", 3);
    Set<String> set = N.asImmutableSet("abc", "1", "2", "3");
    

  • Lambda/Stream/Functional programming...
  • Stream.of("abc", "123", "ab123").filter(str -> str.startsWith("a")).forEach(N::println);
    // abc
    // ab123
    
    List<String> strs = N.asList("Hello Java", "I LIKE Functional Programming");
    
    // average length of words in the strings.
    Stream.of(strs).flatMap2(str -> str.split(" ")).averageDouble(str -> str.length());
    // 5.833333333333333
    
    // count the characters in upper case.
    Stream.of(strs).flatMapToChar(str -> CharStream.from(str)).filter(ch -> N.isUpperCase(ch)).count();
    // 9
    

  • SQLBuilder/Executor...
  • 					// Insert
    String sql_insert = NE.insert("gui", "firstName", "lastName", "lastUpdateTime", "createTime").into("account").sql();
    // Or: String sql_insert = NE.insertInto(Account.class, N.asSet("id").sql();
    // sql: INSERT INTO account (gui, first_name, last_name, last_update_time, create_time) VALUES (:gui, :firstName, :lastName, :lastUpdateTime, :createTime)
    long id = sqlExecutor.insert(sql_insert, account);
    
    // Read
    String sql_getById = NE.select("id", "gui", "firstName", "lastName").from("account").where("id = :id").sql();
    // sql: SELECT id AS "id", gui AS "gui", first_name AS "firstName", last_name AS "lastName" FROM account WHERE id = :id
    Account dbAccount = sqlExecutor.queryForEntity(Account.class, sql_getById, id);
    
    //Update
    dbAccount.setFirstName("newFirstName");
    String sql_updateFirstNameById = NE.update("account").set("firstName").where("id = :id").sql();
    // sql: UPDATE account SET first_name = :firstName WHERE id = :id
    sqlExecutor.update(sql_updateFirstNameById, dbAccount);
    
    // Delete
    String sql_deleteByFirstName = NE.deleteFrom("account").where("firstName = :firstName").sql();
    // sql: DELETE FROM account WHERE first_name = :firstName
    sqlExecutor.update(sql_deleteByFirstName, dbAccount);
    

  • XML/JSONParser...
  • String xml = xmlParser.serialize(account);
    // XML: <account><id>0</id><gui>9d436ceb-a85f-40b2-86aa-20625a7d68b0</gui><firstName>3e37c0e9-96c3-40f3-99a2-bde3a384956c</firstName><lastName>38d19d46-6701-4f36-a112-924376154280</lastName><status>0</status><lastUpdateTime>1437609384633</lastUpdateTime><createTime>1437609384633</createTime></account>
    Account account2 = xmlParser.deserialize(Account.class, xml);
    
    String json = jsonParser.serialize(account);
    // JSON: {id:0, gui:"edf40293-2e38-4c51-885b-e74638f7b7d2", firstName:"f063cb51-75f6-4810-a8e6-8e55d2db440f", lastName:"70e6f942-8400-4b84-9f17-02594d99ee2c", status:0, lastUpdateTime:1437609422217, createTime:1437609422217}
    account2 = jsonParser.deserialize(Account.class, json);
    

  • Code Generation: (Account.java)
  • // 1, Productivity: generate tens, even hundreds of lines of code by couple of lines of codes in one minute.
    // 2. Maintainability: It's easy and simple to add/remove fields or change types of fields. And all the codes follow the same format.
    // 3. Bug free. No test is required for the auto-generated codes and no test coverage is counted. 
    // 4. Actually, the auto-generated code can be built to jar file directly. Things could be as beautiful as you could imagine. 
    File srcDir = new File("./src");
    String packageName = "com.x.y";
    
    Map<String, Object> fields = N.asLinkedHashMap("firstName", String.class, "lastName", String.class, 
            "birthdate", Date.class, "email", String.class, "address", String.class, "attrs", "Map<String, Object>");
    CodeGenerator.generateEntity(srcDir, packageName, "Account", fields);
    

    Here are the features/APIs supported in AbacusUtil:

    "SIMPLE IS BEAUTIFUL" - We always keep it in mind to build The Best Programming Library EVER.

    Leaving a comment/question at AbacusUtil Google Group...