Skip to content
/ sinobu Public

Sinobu is not obsolete framework but utility, which can manipulate objects as a extremely-condensed facade. This is extremely lightweight at approximately 106KB without relying on other libraries.

License

Notifications You must be signed in to change notification settings

teletha/sinobu

Repository files navigation

   

Summary

Sinobu is not obsolete framework but utility, which can manipulate objects as a extremely-condensed facade. This is extremely lightweight at approximately 106 KB without relying on other libraries, and its various operations are designed to run as fast as other competing libraries.

This library aims to simplify and highly condense the functions related to domains that are frequently encountered in real-world development projects, making them easier to use.

  • Dependency Injection
  • Object lifecycle management
  • JavaBeans-like property based type modeling
  • HTTP(S)
  • JSON
  • HTML(XML)
  • Reactive Programming (Rx)
  • Asynchronous processing
  • Parallel processing
  • Multilingualization
  • Template Engine (Mustache)
  • Dynamic plug-in mechanism
  • Object Persistence
  • Logging

With a few exceptions, Sinobu and its APIs are designed to be simple to use and easy to understand by adhering to the following principles.

  • Keep it stupid simple
  • Less is more
  • Type safety
  • Refactoring safety

back to top

Usage

Create instant from type.

class Some {
}

assert I.make(Some.class) != I.make(Some.class);

Create singleton instance. (managed lifestyle)

@Managed(Singleton.class)
class Some {
}

assert I.make(Some.class) == I.make(Some.class);

Enable dependency injection without configuration. (constructor injection)

class Injected {
}

class Injectable {
    Injected injected;

    Injectable(Injected injected) {
        this.injected = injected;
    }
}

Injectable Injectable = I.make(Injectable.class);
assert Injectable.injected != null;

Read contents from HTTP.

I.http("https://httpstat.us/200", String.class).to(text -> {
    // read as text
});

I.http("https://httpstat.us/200", JSON.class).to(json -> {
    // read as JSON
});

I.http("https://httpstat.us/200", XML.class).to(xml -> {
    // read as XML
});

Parse JSON.

JSON json = I.json("""
        {
            "name": "忍",
            "age": 598
        }
        """);

// read value as String (shorthand)
assert json.text("name").equals("忍");

// read value as int
assert json.get("age").as(int.class) == 598;

Parse XML/HTML. (accept tag soup)

XML html = I.xml("""
        <html>
            <body>
                <h1>Heading</h1>
                <div class="age">598</div>
                <p>contents</p>
                <div class="author">忍</p>
            </body>
        </html>
        """);

// select the element by CSS selector and read its text content
assert html.find("p").text().equals("contents");
assert html.find(".author").text().equals("忍");

Reactive stream. (Rx)

String result = I.signal("This", "is", "reactive", "stream")
        .skip(2)
        .map(String::toUpperCase)
        .scan(Collectors.joining(" "))
        .to()
        .exact();

assert result.equals("REACTIVE STREAM");

Evaluate expression language. (Mustache-like syntax)

Person person = new Person();
person.name = "忍";
person.age = 598;

assert I.express("{name} is {age} years old.", person).equals("忍 is 598 years old.");

Write log message on console, file and user-defined appender.

I.trace("Default logging level is INFO.");

I.debug("your.logger.name", "Different logger names can be used for different output settings.");

I.info("system", "The default logger name is [system].");

I.warn("""
        The following settings can be changed for each logger:
            * log level
            * displying caller location
            * output directory of log file
            * whether the log file is overwritten or appended
            * the number of days the log file is kept
        """);

I.error((Supplier) () -> "Use a lambda expression to delay message building.");

back to top

Prerequisites

Sinobu runs on all major operating systems and requires only Java version 17 or later to run. To check, please run java -version from the command line interface. You should see something like this:

> java -version
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment (build 16+36-2231)
OpenJDK 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)

back to top

Install

For any code snippet below, please substitute the version given with the version of Sinobu you wish to use.

Add JitPack repository at the end of repositories element in your build.xml:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

Add it into in the dependencies element like so:

<dependency>
    <groupId>com.github.teletha</groupId>
    <artifactId>sinobu</artifactId>
    <version>3.11.0</version>
</dependency>

Add JitPack repository at the end of repositories in your build.gradle:

repositories {
    maven { url "https://jitpack.io" }
}

Add it into the dependencies section like so:

dependencies {
    implementation 'com.github.teletha:sinobu:3.11.0'
}

Add JitPack repository at the end of resolvers in your build.sbt:

resolvers += "jitpack" at "https://jitpack.io"

Add it into the libraryDependencies section like so:

libraryDependencies += "com.github.teletha" % "sinobu" % "3.11.0"

Add JitPack repository at the end of repositories in your project.clj:

:repositories [["jitpack" "https://jitpack.io"]]

Add it into the dependencies section like so:

:dependencies [[com.github.teletha/sinobu "3.11.0"]]

Add it into your project definition class like so:

require("com.github.teletha", "sinobu", "3.11.0");

back to top

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

The overwhelming majority of changes to this project don't add new features at all. Optimizations, tests, documentation, refactorings -- these are all part of making this product meet the highest standards of code quality and usability. Contributing improvements in these areas is much easier, and much less of a hassle, than contributing code for new features.

Bug Reports

If you come across a bug, please file a bug report. Warning us of a bug is possibly the most valuable contribution you can make to Sinobu. If you encounter a bug that hasn't already been filed, please file a report with an SSCCE demonstrating the bug. If you think something might be a bug, but you're not sure, ask on StackOverflow or on sinobu-discuss.

back to top

Dependency

Sinobu depends on the following products on runtime.

  • No Dependency

back to top

License

Copyright (C) 2024 The SINOBU Development Team

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

back to top

About

Sinobu is not obsolete framework but utility, which can manipulate objects as a extremely-condensed facade. This is extremely lightweight at approximately 106KB without relying on other libraries.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages