kiss
I
Sinobu is not obsolete framework but utility, which can manipulate objects as a extremely-condensed facade.
- Instantiation and Management
-
Usually, the container which manages the object uses “get” method to provide such functionality. However, Sinobu uses
#make(Class)
. This difference of method name indicates the difference of the way for the management of objects, which also greatly affects the default lifestyle (called Scope in other containers).We do not provides the functionalities related to object lifecycle through Sinobu, because we believe that it is better to use functionalities equipped in Java as much as possible. For example, if you want to receive initialization callback, it is better to use constructor.
- Dependency Injection
-
Sinobu supports Constructor Injection only. The Constructor Injection is a dependency injection variant where an object gets all its dependencies via the constructor. We can say that there is no possibility that Operation Injection, Field Injection and Interface Injection will be supported in the days to come. This is one of the most important policy in Sinobu. The following is a benefit of Constructor Injection:
- It makes a strong dependency contract
- It makes effective use of constructor in object lifecycle
- It makes JavaBeans property clean
- It makes testing easy, since dependencies can be passed in as Mock Object
The following is a deficit of Constructor Injection:
- It can't resolve circular dependency
Jobs
Scheduler
The parallel task scheduler.
NoOP
WiseRunnable
No Operation
Lang
VariableString
String
The default language in this VM environment.
Logger
WiseTriConsumerString
, Level
, Object
String
, Level
, Object
The user-defined extra log appender.
accept
(A
a
)
boolean
A
a
)A |
|
A a |
|
boolean |
Always true. |
Accept any value. Use with method reference.
void accept() {
Predicate<String> accept = I::accept;
assert accept.test("accept") == true;
assert accept.test("all") == true;
assert accept.test(null) == true;
}
accept
(A
a
, B
b
)
boolean
A
a
, B
b
)A |
|
B |
|
A a |
|
B b |
|
boolean |
Always true. |
Accept any value. Use with method reference.
void accept2() {
BiPredicate<String, Integer> accept = I::accept;
assert accept.test("accept", 1) == true;
assert accept.test("all", -1) == true;
assert accept.test(null, 0) == true;
}
array
(T
one
, T
other
)
T
T
one
, T
other
)T |
Array element types. |
T one |
Array to be concatenated at the top. |
T other |
Array to be concatenated at the end. |
T |
Newly created array with concatenated elements. |
Creates a new array whose elements are the concatenated elements of the two given arrays.
void concatTwoArrays() {
String[] head = {"a", "b", "c"};
String[] tail = {"d", "e"};
assert Arrays.equals(I.array(head, tail), new String[] {"a", "b", "c", "d", "e"});
}
bundle
(T
items
)
T
T
items
)T |
Interface type. |
T items |
A set of objects that implement a common interface. |
T |
A bundled interface. |
Create a new bundled implementation of the interface common to the given objects. Calling a method of the retrieved implementation object will transparently call the same method on all the given objects. In the case of a method with a return value, the result of the last object's call will be used.
In situations where the compiler cannot estimate the type of the common interface, use
I#bundle(Class, Object...)
instead, which can specify the type.
void bundleRunnables() {
int[] value = {0};
Runnable bundled = I.bundle(() -> value[0] += 1, () -> value[0] += 2);
bundled.run();
assert value[0] == 3;
bundled.run();
assert value[0] == 6;
}
void returnLastInterfaceResult() {
Function<Integer, Integer> bundled = I.bundle(x -> x + 1, y -> y + 2);
assert bundled.apply(10) == 12;
}
void cantInferCommonInterface() {
ArrayList array = new ArrayList();
LinkedList linked = new LinkedList();
assertThrows(IllegalArgumentException.class, () -> I.bundle(array, linked));
}
bundle
(ClassT
type
, T
items
)
T
ClassT
type
, T
items
)T |
Interface type. |
Class type |
Specify the common interfaces. |
T items |
A set of objects that implement a common interface. |
T |
A bundled interface. |
Create a new bundled implementation of the interface common to the given objects. Calling a method of the retrieved implementation object will transparently call the same method on all the given objects. In the case of a method with a return value, the result of the last object's call will be used.
void bundleList() {
ArrayList array = new ArrayList();
LinkedList linked = new LinkedList();
List bundled = I.bundle(List.class, array, linked);
bundled.add(10);
assert array.size() == 1;
assert linked.size() == 1;
}
collect
(ClassT
type
, V
items
)
T
ClassT
type
, V
items
)T
|
Specify the concrete class which implements the |
V |
The type of the |
Class type |
A |
V items |
A list of items. |
T |
The new created |
Create a new Collection
to hold the specified items. Basically, the type of the
collection should be a real class, but if it is a List
or Set
, the default
implementation class (ArrayList
, HashSet
) will be used.
public void collect() {
List<Integer> list = I.collect(List.class, 1, 2, 3);
assert list instanceof ArrayList;
assert list.size() == 3;
assert list.get(0) == 1;
assert list.get(1) == 2;
assert list.get(2) == 3;
}
public void collectWithNoItem() {
List<Integer> list = I.collect(LinkedList.class);
assert list instanceof LinkedList;
assert list.isEmpty();
}
copy
(InputStream
input
, OutputStream
output
, boolean
close
)
void
InputStream
input
, OutputStream
output
, boolean
close
)InputStream input |
InputStream to which data will be read from. |
OutputStream output |
OutputStream to which data will be written to. |
boolean close |
Whether input and output streams will be closed automatically or not. |
Copies data from InputStream
to OutputStream
. This method does the data
buffering internally, so you do not need to do the buffering explicitly.
void copyInputStream() {
byte[] bytes = {0, 1, 2, 3};
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
ByteArrayOutputStream out = new ByteArrayOutputStream();
I.copy(in, out, true);
assert Arrays.equals(bytes, out.toByteArray());
}
copy
(Readable
input
, Appendable
output
, boolean
close
)
void
Readable
input
, Appendable
output
, boolean
close
)Readable input |
Readable to which data will be read from. |
Appendable output |
Appendable to which data will be written to. |
boolean close |
Whether input and output streams will be closed automatically or not. |
Copies data from Readable
to Appendable
. This method does the data buffering
internally, so you do not need to do the buffering explicitly.
void copyReadable() {
String value = "test";
StringReader in = new StringReader(value);
StringWriter out = new StringWriter();
I.copy(in, out, true);
assert out.toString().equals(value);
}
debug
(Object
msg
)
void
Object
msg
)Object msg |
A message log. |
Write java.lang.System.Logger.Level#DEBUG
log.
debug
(String
name
, Object
msg
)
void
String
name
, Object
msg
)String name |
A logger name. |
Object msg |
A message log. |
Write java.lang.System.Logger.Level#DEBUG
log.
debug
(WiseSupplier
msg
)
void
WiseSupplier
msg
)WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#DEBUG
log.
debug
(String
name
, WiseSupplier
msg
)
void
String
name
, WiseSupplier
msg
)String name |
A logger name. |
WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#DEBUG
log.
env
(String
name
)
String
String
name
)String name |
A environment variable name. |
String |
The value of the environment variable with the specified name, or |
Read environment variables based on the following priorities (sources higher in the list take precedence over those located lower).
System#getenv(String)
- .env property file in current working directory (optional)
- .env property file on the classpath (optional)
@EnabledIfEnvironmentVariable(named = "TEMP", matches = ".*")
void env() {
assert I.env("TEMP") != null; // The value varies depending on the execution environment.
assert I.env("not-exist") == null;
}
env
(String
name
, T
defaults
)
T
String
name
, T
defaults
)T |
|
String name |
A environment variable name. |
T defaults |
If the specified name is not found, set and return this default value. |
T |
The value of the environment variable with the specified name. |
Read environment variables based on the following priorities (sources higher in the list take precedence over those located lower). If the environment variable with the specified name does not exist, the value specified as the default value will be set as the new environment variable and used.
System#getenv(String)
- .env property file in current working directory (optional)
- .env property file on the classpath (optional)
error
(Object
msg
)
void
Object
msg
)Object msg |
A message log. |
Write java.lang.System.Logger.Level#ERROR
log.
error
(String
name
, Object
msg
)
void
String
name
, Object
msg
)String name |
A logger name. |
Object msg |
A message log. |
Write java.lang.System.Logger.Level#ERROR
log.
error
(WiseSupplier
msg
)
void
WiseSupplier
msg
)WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#ERROR
log.
error
(String
name
, WiseSupplier
msg
)
void
String
name
, WiseSupplier
msg
)String name |
A logger name. |
WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#ERROR
log.
express
(String
text
, Object
contexts
)
String
String
text
, Object
contexts
)String text |
A text with the path of the property names enclosed in "{}". |
Object contexts |
A list of context values. |
String |
A calculated text. |
It is a very simple template engine that can calculate a string that replaces the path of a property names enclosed in "{}" with the actual value of the property. Support Mustache Syntax partially.
void variable() {
KVS context = $("lang", "the minimum language");
assert I.express("I want {lang}.", context).equals("I want the minimum language.");
}
void bean() {
Person bean = new Person();
bean.setAge(15);
bean.setLastName("Kahu");
bean.setFirstName("Tino");
assert I.express("{firstName}({age}) : It's noisy.", bean).equals("Tino(15) : It's noisy.");
}
void section() {
List context = List.of("one", "two", "three");
assert I.express("""
<ul>
{#this}
<li>{.}</li>
{/this}
</ul>
""", context).equals("""
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
""");
}
void sectionByEmptyList() {
List context = Collections.emptyList();
assert I.express("{#this}The text here will not be output.{/this}", context).equals("");
}
void sectionByFalse() {
boolean context = false;
assert I.express("{#this}The text here will not be output.{/this}", context).equals("");
}
void invertedByEmptyList() {
List context = Collections.emptyList();
assert I.express("""
<ul>
{#this}
<li>{.}</li>
{/this}
{^this}
<li>No Items</li>
{/this}
</ul>
""", context).equals("""
<ul>
<li>No Items</li>
</ul>
""");
}
express
(String
text
, Object
contexts
, WiseTriFunctionModel
, Object
, String
, Object
resolvers
)
String
String
text
, Object
contexts
, WiseTriFunctionModel
, Object
, String
, Object
resolvers
)String text |
A text with the path of the property names enclosed in "{}". |
Object contexts |
A list of context values. |
WiseTriFunction resolvers |
|
String |
A calculated text. |
It is a very simple template engine that can calculate a string that replaces the path of a property names enclosed in "{}" with the actual value of the property. Support Mustache Syntax partially.
express
(String
text
, String
open
, String
close
, Object
contexts
, WiseTriFunctionModel
, Object
, String
, Object
resolvers
)
String
String
text
, String
open
, String
close
, Object
contexts
, WiseTriFunctionModel
, Object
, String
, Object
resolvers
)String text |
A text with the path of the property names enclosed in "{}". |
String open |
|
String close |
|
Object contexts |
A list of context values. |
WiseTriFunction resolvers |
|
String |
A calculated text. |
It is a very simple template engine that can calculate a string that replaces the path of a property names enclosed in "{}" with the actual value of the property. Support Mustache Syntax partially.
find
(ClassE
extensionPoint
)
ListE
ClassE
extensionPoint
)E
E
|
An Extension Point. |
Class extensionPoint |
An extension point class. The Extension Point class is only accepted, otherwise this method will return empty list. |
List |
All Extensions of the given Extension Point or empty list. |
Find all Extensions which are specified by the given Extension Point.
The returned list will be "safe" in that no references to it are maintained by Sinobu. (In other words, this method must allocate a new list). The caller is thus free to modify the returned list.
find
(ClassE
extensionPoint
, Class
key
)
E
ClassE
extensionPoint
, Class
key
)E
|
An Extension Point. |
Class extensionPoint |
An Extension Point class. The
Extension Point class is only accepted,
otherwise this method will return |
Class key |
An Extension Key class. |
E |
An associated Extension of the given Extension Point and the given Extension Key or
|
Find the Extension which are specified by the given Extension Point and the given key.
findAs
(ClassE
extensionPoint
)
ListClassE
ClassE
extensionPoint
)ClassE
E
|
An Extension Point. |
Class extensionPoint |
An extension point class. The Extension Point class is only accepted, otherwise this method will return empty list. |
List |
All Extension classes of the given Extension Point or empty list. |
Find all Extensions classes which are specified by the given Extension Point.
The returned list will be "safe" in that no references to it are maintained by Sinobu. (In other words, this method must allocate a new list). The caller is thus free to modify the returned list.
http
(String
request
, ClassT
type
, HttpClient
client
)
SignalT
String
request
, ClassT
type
, HttpClient
client
)T
T |
String , InputStream , HttpResponse , XML , or your
bean class |
String request |
Request URI. |
Class type |
Response handler. ( |
HttpClient client |
|
Signal |
If the request is successful, the content will be sent. If the request is unsuccessful, an error will be sent. |
Gets the response from the specified URL (including https), converting it to the specified type. Supported types are as follows:
String
InputStream
HttpResponse
XML
JSON
- Any types that can be mapped from JSON
It will check the Content-Encoding header and automatically decompress the body if it is
compressed with gzip or deflate. HTTP communication by this method is done asynchronously. It
is possible to process it synchronously by calling the return value's
Signal#waitForTerminate()
.
void responseString() {
httpClientMock.onGet().doReturn("ok");
assert I.http("http://test.com", String.class, httpClientMock).to().is("ok");
}
void responseHTML() {
httpClientMock.onGet().doReturnXML("<html><body>contents</body></html>");
XML xml = I.http("http://test.com", XML.class, httpClientMock).to().exact();
assert xml.name().equals("html");
assert xml.text().equals("contents");
}
void responseJSON() {
httpClientMock.onGet().doReturnJSON(text("{'state' : 'ok'}"));
JSON json = I.http("http://test.com", JSON.class, httpClientMock).to().exact();
assert json.get(String.class, "state").equals("ok");
}
void responseMappedType() {
class Response {
public String state;
}
httpClientMock.onGet().doReturnJSON(text("{'state' : 'ok'}"));
Response response = I.http("http://test.com", Response.class, httpClientMock).to().exact();
assert response.state.equals("ok");
}
http
(Builder
request
, ClassT
type
, HttpClient
client
)
SignalT
Builder
request
, ClassT
type
, HttpClient
client
)T
T |
String , InputStream , HttpResponse , XML , or your
bean class |
Builder request |
Request builder. |
Class type |
Response handler. ( |
HttpClient client |
|
Signal |
If the request is successful, the content will be sent. If the request is unsuccessful, an error will be sent. |
Gets the response from the specified URL (including https), converting it to the specified type. Supported types are as follows:
String
InputStream
HttpResponse
XML
JSON
- Any types that can be mapped from JSON
It will check the Content-Encoding header and automatically decompress the body if it is
compressed with gzip or deflate. HTTP communication by this method is done asynchronously. It
is possible to process it synchronously by calling the return value's
Signal#waitForTerminate()
.
http
(String
uri
, ConsumerWebSocket
open
, HttpClient
client
)
SignalString
String
uri
, ConsumerWebSocket
open
, HttpClient
client
)String
String uri |
URI to connect. |
Consumer open |
Called only once, when a connection is established. |
HttpClient client |
|
Signal |
Communication status. |
Connect to the specified URI by Websocket. The status of the communication is transmitted to
Signal
. Once the connection is established, it performs a 'open' callback.
info
(Object
msg
)
void
Object
msg
)Object msg |
A message log. |
Write java.lang.System.Logger.Level#INFO
log.
info
(String
name
, Object
msg
)
void
String
name
, Object
msg
)String name |
A logger name. |
Object msg |
A message log. |
Write java.lang.System.Logger.Level#INFO
log.
info
(WiseSupplier
msg
)
void
WiseSupplier
msg
)WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#INFO
log.
info
(String
name
, WiseSupplier
msg
)
void
String
name
, WiseSupplier
msg
)String name |
A logger name. |
WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#INFO
log.
json
(String
input
)
JSON
String
input
)String input |
A json format text. |
JSON |
A parsed |
Parse the specified JSON format text.
json
(String
input
, ClassT
type
)
T
String
input
, ClassT
type
)T |
|
String input |
A json format text. |
Class type |
|
T |
A parsed |
Parse the specified JSON format text.
json
(Path
input
)
JSON
Path
input
)Path input |
A json format text. |
JSON |
A parsed |
Parse the specified JSON format text.
json
(InputStream
input
)
JSON
InputStream
input
)InputStream input |
A json format text. |
JSON |
A parsed |
Parse the specified JSON format text.
json
(Reader
input
)
JSON
Reader
input
)Reader input |
A json format text. |
JSON |
A parsed |
Parse the specified JSON format text.
json
(Reader
input
, ClassT
type
)
T
Reader
input
, ClassT
type
)T |
|
Reader input |
A json format text. |
Class type |
|
T |
A parsed |
Parse the specified JSON format text.
list
(V
items
)
ListV
V
items
)V
V |
|
V items |
A list of items. |
List |
The new created |
Create ArrayList
with the specified items.
load
(URL
source
)
Disposable
URL
source
)URL source |
A source class to indicate the class set which are loaded. |
Disposable |
Call |
Load all Extensible
types from the specified source.
You can pass the csv data from "kiss.Extensible" environment variable which enumerates pre-scanned class names.
load
(Class
source
)
Disposable
Class
source
)Class source |
A source class to indicate the class set which are loaded. |
Disposable |
Call |
Load all Extensible
types from the specified source.
You can pass the csv data from "kiss.Extensible" environment variable which enumerates pre-scanned class names.
make
(Class?
T
modelClass
)
T
Class?
T
modelClass
)T |
A model type. |
Class modelClass |
A target class to create instance. |
T |
An instance of the specified model class. This instance is managed by Sinobu. |
Returns a new or cached instance of the model class.
This method supports the top-level class and the member type. If the local class or the
anonymous class is passed to this argument, UnsupportedOperationException
will be
thrown. There is a possibility that a part of this limitation will be removed in the future.
make
(ClassT
type
, InvocationHandler
handler
)
T
ClassT
type
, InvocationHandler
handler
)T |
|
Class type |
A model type. |
InvocationHandler handler |
A proxy handler. |
T |
Proxy instance for the given interface. |
Create proxy instance.
pair
(A
param1
, B
param2
)
ⅡA
, B
A
param1
, B
param2
)A
, B
A |
|
B |
|
A param1 |
A first parameter. |
B param2 |
A second parameter. |
Ⅱ |
A created tuple. |
Create value set.
pair
(A
param1
, B
param2
, C
param3
)
ⅢA
, B
, C
A
param1
, B
param2
, C
param3
)A
, B
, C
A |
|
B |
|
C |
|
A param1 |
A first parameter. |
B param2 |
A second parameter. |
C param3 |
A third parameter. |
Ⅲ |
A created tuple. |
Create value set.
prototype
(ClassM
model
)
LifestyleM
ClassM
model
)M
M |
A |
Class model |
A model type. |
Lifestyle |
A built |
Build prototype-like Lifestyle
that creates a new instance every time demanded. This
is default lifestyle in Sinobu.
The created
You may also specify a Lifestyle
has the functionality of Dependency Injection. The Lifestyle
attempts to create an instance using the first constructor declared with the fewest number of
arguments. If the argument contains a Managed
type, an instance of that type will
also be created automatically. This dependency injection is done at the same time when the
model is instantiated. But if you want to delay the creation of the dependency until it is
needed, you can set the argument type to Lifestyle
Class
type as an argument if you need the currently processing
model type. This feature is mainly available when implementing the special generic
Lifestyle
.
prototype
(ClassM
model
, WiseFunctionClass
, Object
injector
)
LifestyleM
ClassM
model
, WiseFunctionClass
, Object
injector
)M
M |
A |
P |
|
Class model |
A model type. |
WiseFunction injector |
A injector for parameters. The default injector is |
Lifestyle |
A built |
Build prototype-like Lifestyle
that creates a new instance every time demanded. This
is default lifestyle in Sinobu.
The created
You may also specify a Lifestyle
has the functionality of Dependency Injection. The Lifestyle
attempts to create an instance using the first constructor declared with the fewest number of
arguments. If the argument contains a Managed
type, an instance of that type will
also be created automatically. This dependency injection is done at the same time when the
model is instantiated. But if you want to delay the creation of the dependency until it is
needed, you can set the argument type to Lifestyle
Class
type as an argument if you need the currently processing
model type. This feature is mainly available when implementing the special generic
Lifestyle
.
quiet
(Object
object
)
RuntimeException
Object
object
)Object object |
An exception to throw quietly or an object to close quietly. |
RuntimeException |
A pseudo unchecked exception. |
Close the specified object quietly if it is AutoCloseable
. Equivalent to
AutoCloseable#close()
, except any exceptions will be ignored. This is typically used
in finally block like the following.
AutoCloseable input = null; try { // some IO action } catch (Exception e) { throw e; } finally { I.quiet(input); }
Throw the specified checked exception quietly or close the specified AutoCloseable
object quietly.
This method doesn't wrap checked exception around unchecked exception (e.g. new RuntimeException(e)) and doesn't shelve it. This method deceive the compiler that the checked exception is unchecked one. So you can catch a raw checked exception in the caller of the method which calls this method.
private void callerWithoutErrorHandling() { methodQuietly(); } private void callerWithErrorHandling() { try { methodQuietly(); } catch (Exception e) { // you can catch the checked exception here } } private void methodQuietly() { try { // throw some checked exception } catch (CheckedException e) { throw I.quiet(e); // rethrow checked exception quietly } }
recurse
(WiseTriConsumerWiseBiConsumerA
, B
, A
, B
function
)
WiseBiConsumerA
, B
WiseTriConsumerWiseBiConsumerA
, B
, A
, B
function
)A
, B
A |
|
B |
|
WiseTriConsumer function |
A recursive function. |
WiseBiConsumer |
A created function. |
Define recursive BiConsumer
.
I.recurse((self, param1, param2) -> { // your function code });
recurse
(WiseTriFunctionWiseBiFunctionA
, B
, R
, A
, B
, R
function
)
WiseBiFunctionA
, B
, R
WiseTriFunctionWiseBiFunctionA
, B
, R
, A
, B
, R
function
)A
, B
, R
A |
|
B |
|
R |
|
WiseTriFunction function |
A recursive function. |
WiseBiFunction |
A created function. |
Define recursive BiFunction
.
I.recurse((self, param1, param2) -> { // your function code });
recurse
(WiseBiConsumerWiseConsumerA
, A
function
)
WiseConsumerA
WiseBiConsumerWiseConsumerA
, A
function
)A
A |
|
WiseBiConsumer function |
A target function to convert. |
WiseConsumer |
A converted recursive function. |
Define recursive Consumer
.
I.recurse((self, param) -> { // your function code });
recurse
(WiseBiFunctionWiseFunctionA
, R
, A
, R
function
)
WiseFunctionA
, R
WiseBiFunctionWiseFunctionA
, R
, A
, R
function
)A
, R
A |
|
R |
|
WiseBiFunction function |
A recursive function. |
WiseFunction |
A created function. |
Define recursive Function
.
I.recurse((self, param) -> { // your function code });
recurse
(WiseConsumerWiseRunnable
function
)
WiseRunnable
WiseConsumerWiseRunnable
function
)WiseConsumer function |
A recursive function. |
WiseRunnable |
A created function. |
Define recursive Runnable
.
I.recurse(self -> { // your function code });
recurse
(WiseFunctionWiseSupplierR
, R
function
)
WiseSupplierR
WiseFunctionWiseSupplierR
, R
function
)R
R |
|
WiseFunction function |
A recursive function. |
WiseSupplier |
A created function. |
Define recursive Supplier
.
I.recurse(self -> { // your function code });
reject
(A
a
)
boolean
A
a
)A |
|
A a |
|
boolean |
Always false. |
Reject any value. Use with method reference.
void reject() {
Predicate<String> reject = I::reject;
assert reject.test("reject") == false;
assert reject.test("all") == false;
assert reject.test(null) == false;
}
reject
(A
a
, B
b
)
boolean
A
a
, B
b
)A |
|
B |
|
A a |
|
B b |
|
boolean |
Always false. |
Reject any value. Use with method reference.
void reject2() {
BiPredicate<String, Integer> accept = I::reject;
assert accept.test("reject", 1) == false;
assert accept.test("all", -1) == false;
assert accept.test(null, 0) == false;
}
schedule
(Runnable
task
)
CompletableFuture?
Runnable
task
)?
Runnable task |
A task to execute. |
CompletableFuture |
A result of the executing task. |
Execute the specified task in the sinobu managed background thread pool.
schedule
(long
delayTime
, TimeUnit
unit
, ScheduledExecutorService
scheduler
)
SignalLong
long
delayTime
, TimeUnit
unit
, ScheduledExecutorService
scheduler
)Long
long delayTime |
The delay time to wait before emitting the first value of 1L |
TimeUnit unit |
The time unit for delay time |
ScheduledExecutorService scheduler |
The task scheduler. |
Signal |
Signal that emits long value (1) after the delay time |
Returns an Signal
that emits long value (1) after the delay time.
schedule
(long
delayTime
, long
intervalTime
, TimeUnit
unit
, boolean
fixedRate
, ScheduledExecutorService
scheduler
)
SignalLong
long
delayTime
, long
intervalTime
, TimeUnit
unit
, boolean
fixedRate
, ScheduledExecutorService
scheduler
)Long
long delayTime |
The initial delay time to wait before emitting the first value of 1L |
long intervalTime |
The period of time between emissions of the subsequent numbers |
TimeUnit unit |
the time unit for both delay time and interval time |
boolean fixedRate |
|
ScheduledExecutorService scheduler |
|
Signal |
Signal that emits long value (1) after the delay time and ever-increasing
numbers after each interval time of time thereafter |
Returns an Signal
that emits long value (1) after the delay time and ever-increasing
numbers after each interval time of time thereafter.
schedule
(String
cron
)
SignalLong
String
cron
)Long
String cron |
The cron expression. |
Signal |
Signal that emits long value (1) at the time and ever-increasing numbers
after each interval of time thereafter |
Create a time-based periodic executable scheduler. It will be executed at regular intervals starting from a specified base time. For example, if the base time is 00:05 and the interval is 30 minutes, the actual execution time will be 00:05, 00:30, 01:05, 01:35, and so on.
schedule
(String
cron
, ZoneId
id
)
SignalLong
String
cron
, ZoneId
id
)Long
String cron |
The cron expression. |
ZoneId id |
|
Signal |
Signal that emits long value (1) at the time and ever-increasing numbers
after each interval of time thereafter |
Create a time-based periodic executable scheduler. It will be executed at regular intervals starting from a specified base time. For example, if the base time is 00:05 and the interval is 30 minutes, the actual execution time will be 00:05, 00:30, 01:05, 01:35, and so on.
set
(V
items
)
SetV
V
items
)V
V |
|
V items |
A list of items. |
Set |
The new created |
Create HashSet
with the specified items.
signal
(V
values
)
SignalV
V
values
)V
V |
|
V values |
A list of values to emit. |
Signal |
The |
Signal the specified values.
signal
(IterableV
values
)
SignalV
IterableV
values
)V
V |
|
Iterable values |
A list of values to emit. |
Signal |
The |
Signal the specified values.
signal
(SupplierV
value
)
SignalV
SupplierV
value
)V
V |
|
Supplier value |
A value to emit. |
Signal |
The |
Signal
the specified values.signalError
(Throwable
error
)
SignalV
Throwable
error
)V
V |
|
Throwable error |
An error to emit. |
Signal |
The |
Returns an Signal
that invokes an Observer#error(Throwable)
method when the
Observer
subscribes to it.
trace
(Object
msg
)
void
Object
msg
)Object msg |
A message log. |
Write java.lang.System.Logger.Level#TRACE
log.
trace
(String
name
, Object
msg
)
void
String
name
, Object
msg
)String name |
A logger name. |
Object msg |
A message log. |
Write java.lang.System.Logger.Level#TRACE
log.
trace
(WiseSupplier
msg
)
void
WiseSupplier
msg
)WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#TRACE
log.
trace
(String
name
, WiseSupplier
msg
)
void
String
name
, WiseSupplier
msg
)String name |
A logger name. |
WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#TRACE
log.
transform
(In
input
, ClassOut
output
)
Out
In
input
, ClassOut
output
)In |
An input type you want to transform from. |
Out |
An output type you want to transform into. |
In input |
A target object. |
Class output |
A target type. |
Out |
A transformed object. |
Transform any type object into the specified type if possible.
translate
(String
text
, Object
context
)
VariableString
String
text
, Object
context
)String
String text |
Basic English sentences. |
Object context |
Parameters to be assigned to variables in a sentence. (Optional) |
Variable |
The text will be automatically translated. Basic sentences must be written in English. It
will be translated online automatically into the language specified in the global variable
#Lang
. Once the text is translated, it is saved to the local disk and loaded from
there in the future.
translate
(Disposable
disposer
, String
text
, Object
context
)
VariableString
Disposable
disposer
, String
text
, Object
context
)String
Disposable disposer |
|
String text |
Basic English sentences. |
Object context |
Parameters to be assigned to variables in a sentence. (Optional) |
Variable |
The text will be automatically translated. Basic sentences must be written in English. It
will be translated online automatically into the language specified in the global variable
#Lang
. Once the text is translated, it is saved to the local disk and loaded from
there in the future.
type
(String
fqcn
)
Class
String
fqcn
)String fqcn |
A fully qualified class name to want. |
Class |
The specified class. |
Find the class by the specified fully qualified class name.
unwrap
(Class
type
)
Class
Class
type
)Class type |
the class to convert to its primitive type (must not be |
Class |
the corresponding primitive class, or |
Returns the primitive type corresponding to the given wrapper class (boxed type). If the given class is not a wrapper type, the class itself is returned unchanged.
The mapping is as follows:
- Boolean.class → boolean.class
- Byte.class → byte.class
- Character.class → char.class
- Short.class → short.class
- Integer.class → int.class
- Long.class → long.class
- Float.class → float.class
- Double.class → double.class
- Void.class → void.class
vouch
(T
defaults
, T
values
)
T
T
defaults
, T
values
)T |
A type of value. |
T defaults |
A default value. |
T values |
A candidate of values. |
T |
A suitable value. |
Obtains the last non-null value from the specified array. If there is no suitable value in the array or the array itself, the default value is retrieved.
warn
(Object
msg
)
void
Object
msg
)Object msg |
A message log. |
Write java.lang.System.Logger.Level#WARNING
log.
warn
(String
name
, Object
msg
)
void
String
name
, Object
msg
)String name |
A logger name. |
Object msg |
A message log. |
Write java.lang.System.Logger.Level#WARNING
log.
warn
(WiseSupplier
msg
)
void
WiseSupplier
msg
)WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#WARNING
log.
warn
(String
name
, WiseSupplier
msg
)
void
String
name
, WiseSupplier
msg
)String name |
A logger name. |
WiseSupplier msg |
A message log. |
Write java.lang.System.Logger.Level#WARNING
log.
wiseR
(Runnable
lambda
)
WiseRunnable
Runnable
lambda
)Runnable lambda |
A target function. |
WiseRunnable |
A cast function. |
Cast from Runnable
to WiseRunnable
.
void runnable() {
Runnable lambda = () -> {
};
WiseRunnable dressed = I.wiseR(lambda);
assert dressed != lambda;
lambda = (WiseRunnable) () -> {
};
dressed = I.wiseR(lambda);
assert dressed == lambda;
}
wiseC
(ConsumerA
lambda
)
WiseConsumerA
ConsumerA
lambda
)A
A |
|
Consumer lambda |
A target function. |
WiseConsumer |
A cast function. |
Cast from Consumer
to WiseConsumer
.
void consumer() {
Consumer lambda = v -> {
};
WiseConsumer dressed = I.wiseC(lambda);
assert dressed != lambda;
lambda = (WiseConsumer) v -> {
};
dressed = I.wiseC(lambda);
assert dressed == lambda;
}
wiseC
(Runnable
lambda
)
WiseConsumerA
Runnable
lambda
)A
A |
|
Runnable lambda |
A target function. |
WiseConsumer |
A cast function. |
Cast from Runnable
to WiseConsumer
. All missing parameters will be added on
the right side. All additional caller arguments are ignored.
void consumerFromRunnable() throws Throwable {
int[] counter = {0};
WiseConsumer<String> consumer = I.wiseC(() -> counter[0]++);
assert counter[0] == 0;
consumer.accept("invoke as Consumer");
assert counter[0] == 1;
consumer.ACCEPT("invoke as WiseConsumer");
assert counter[0] == 2;
}
wiseS
(SupplierR
lambda
)
WiseSupplierR
SupplierR
lambda
)R
R |
|
Supplier lambda |
A target function. |
WiseSupplier |
A cast function. |
Cast from Supplier
to WiseSupplier
.
void supplier() {
Supplier lambda = () -> "";
WiseSupplier dressed = I.wiseS(lambda);
assert dressed != lambda;
lambda = (WiseSupplier) () -> "";
dressed = I.wiseS(lambda);
assert dressed == lambda;
}
wiseS
(R
constant
)
WiseSupplierR
R
constant
)R
R |
|
R constant |
The fixed return value. |
WiseSupplier |
A created function. |
Create WiseSupplier
which always return the specified value.
void supplierFromConstant() {
WiseSupplier supplier = I.wiseS("constant");
assert supplier.get().equals("constant");
}
void supplierFromNullConstant() {
WiseSupplier supplier = I.wiseS((Object) null);
assert supplier.get() == null;
}
wiseF
(FunctionA
, R
lambda
)
WiseFunctionA
, R
FunctionA
, R
lambda
)A
, R
A |
|
R |
|
Function lambda |
A target function. |
WiseFunction |
A cast function. |
Cast from Function
to WiseFunction
.
void function() {
Function lambda = p -> "";
WiseFunction dressed = I.wiseF(lambda);
assert dressed != lambda;
lambda = (WiseFunction) p -> "";
dressed = I.wiseF(lambda);
assert dressed == lambda;
}
wiseF
(SupplierR
lambda
)
WiseFunctionA
, R
SupplierR
lambda
)A
, R
A |
|
R |
|
Supplier lambda |
A target function. |
WiseFunction |
A cast function. |
Cast from Supplier
to WiseFunction
. All missing parameters will be added on
the right side. All additional caller arguments are ignored.
void functionFromSupplier() {
WiseFunction<String, String> function = I.wiseF(() -> "constant");
assert function.apply("any value").equals("constant");
assert function.apply("returns the fixed value").equals("constant");
}
wiseF
(R
constant
)
WiseFunctionA
, R
R
constant
)A
, R
A |
|
R |
|
R constant |
The fixed return value. |
WiseFunction |
A created function. |
Create WiseFunction
which always return the specified value.
void functionFromConstant() {
WiseFunction<String, String> function = I.wiseF("constant");
assert function.apply("any value").equals("constant");
assert function.apply("returns the fixed value").equals("constant");
}
void functionFromNullConstant() {
WiseFunction<String, String> function = I.wiseF((String) null);
assert function.apply("any value") == null;
assert function.apply("returns the fixed value") == null;
}
wrap
(Class
type
)
Class
Class
type
)Class type |
the class to convert to its wrapper type (must not be |
Class |
the corresponding wrapper class, or |
Returns the wrapper class (boxed type) corresponding to the given primitive type. If the given class is not a primitive, the class itself is returned unchanged.
The mapping is as follows:
- boolean.class → Boolean.class
- byte.class → Byte.class
- char.class → Character.class
- short.class → Short.class
- int.class → Integer.class
- long.class → Long.class
- float.class → Float.class
- double.class → Double.class
- void.class → Void.class
write
(Object
input
)
String
Object
input
)Object input |
A Java object. All properties will be serialized deeply. |
String |
A JSON representation of Java object. |
Write JSON representation of Java object.
write
(Object
input
, Appendable
output
)
void
Object
input
, Appendable
output
)Object input |
A Java object. All properties will be serialized deeply. |
Appendable output |
A serialized data output. |
Write JSON representation of Java object to the specified output.
If the output object implements AutoCloseable
, AutoCloseable#close()
method
will be invoked certainly.
write
(Model
model
, Object
input
, Appendable
output
)
void
Model
model
, Object
input
, Appendable
output
)Model model |
A root model of the input object. |
Object input |
A Java object. All properties will be serialized deeply. |
Appendable output |
A serialized data output. |
Write JSON representation of Java object to the specified output.
If the output object implements AutoCloseable
, AutoCloseable#close()
method
will be invoked certainly.
xml
(String
input
)
XML
String
input
)String input |
Text of xml representation. |
XML |
A constructed |
Parse the specified XML format text.
xml
(Path
input
)
XML
Path
input
)Path input |
Path to the XML file. |
XML |
A constructed |
Parse the specified XML format text.
xml
(InputStream
input
)
XML
InputStream
input
)InputStream input |
Text stream of xml representation. |
XML |
A constructed |
Parse the specified XML format text.
xml
(Reader
input
)
XML
Reader
input
)Reader input |
Text stream of xml representation. |
XML |
A constructed |
Parse the specified XML format text.
xml
(Node
input
)
XML
Node
input
)Node input |
A xml expression. |
XML |
A constructed |
Parse the specified XML format text.
getActualTypeArguments
()
Type
Type |
getRawType
()
Type
Type |
getOwnerType
()
Type
Type |