(All the English in this document has been translated using AI, for better understanding, it can be switched to Chinese.)
# Introduction
Kunlun is a Java technology framework based on the Facade pattern. Its design philosophy is to provide users with a unified interface for interaction with other modules through the Facade pattern. Users do not need to understand the implementation details of other modules, and they will not be coupled with a specific implementation, which is more conducive to extension and maintenance.
# Function Diagram

# Function List
Below, we will briefly introduce the functions and scenarios of various tools. For more detailed documentation, please refer to: https://github.com/kahle23/kunlun-plus. (Since this project is considered a "Facade", there are fewer specific implementation classes; what's more important are its interfaces and utility classes).
## Action Tools
What is an "Action"? In fact, any piece of program can be expressed as "fun(input) return output;", similar to the mathematical expression "f(x)". Here, I have defined it as "Action", and then given it a name. Therefore, whether it's extremely complex logic or simple logic, it can be invoked by "Action name + input parameters + variables that receive the output parameters".
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// If the company's framework includes two types of order profit-sharing algorithms, "order-share1" and "order-share2"
OrderDTO order = ...;
// Calculation and filling of order profit-sharing information
ActionUtils.execute("order-share1", order, Object.class);
// If you want to use another profit-sharing algorithm, you just need to modify it as follows
ActionUtils.execute("order-share2", order, Object.class);
```
## AI Tools
What is AI? AI, short for Artificial Intelligence, refers to the intelligence displayed by systems created by humans. This intelligence manifests itself through learning, understanding, reasoning, problem-solving, perceiving the environment, recognizing language, and so on. Examples include Machine Learning (ML), Natural Language Processing (NLP), Optical Character Recognition (OCR), and others.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
Dict args = Dict.of("model", "gpt-3.5-turbo-0613")
.set("temperature", 1.9)
.set("messages", Arrays.asList(
Dict.of("role", "system").set("content", "You are a helpful assistant."),
Dict.of("role", "user").set("content", "what is AI?"))
)
;
String method = "chat";
Dict execute = AiUtils.execute("openai", args, method, Dict.class);
log.info("result: {}", JSON.toJSONString(execute, Boolean.TRUE));
```
## Proxy Tools
Proxy tools are essentially dynamic proxy object generation tools; they are tools used in the application of the Proxy design pattern. In this project, only the implementation class of the dynamic proxy based on JDK was realized.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
HelloServiceImpl realHelloService = new HelloServiceImpl();
HelloService helloService = ProxyUtils.proxy(new AbstractInterceptor(realHelloService) {
@Override
public Object intercept(Object proxyObject, Method method, Object[] args) throws Throwable {
log.info("Proxy object's class is {}", proxyObject.getClass().getName());
log.info("Hello, this is intercept. ");
return method.invoke(getOriginalObject(), args);
}
});
log.info(helloService.sayHello(name));
```
## Bean Container Tools
Based on the Bean container and dependency inversion is a very good design approach, so there is this Bean container tool, which allows the use of Bean container and dependency inversion related functions even in scenarios without a Spring container.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// No available
```
## Cache Tools
Cache tools are primarily used to enhance the speed of data access by storing copies of frequently used data to reduce retrieval time from the original storage.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
String cacheName = "TEST";
CacheUtils.put(cacheName, "key1", "val1");
CacheUtils.put(cacheName, "key2", "val2");
log.info("{}", CacheUtils.get(cacheName, "key1"));
log.info("{}", CacheUtils.get(cacheName, "key2"));
```
## Chain Tools or Workflow Tools
A set of tools designed based on the responsibility chain and workflow, used for handling most scenarios where a responsibility chain or workflow can be applied.
For example:
- Approval processes (approval workflow);
- Various activities in e-commerce systems;
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// No available
```
## Codec Tools
Encoding and decoding tools, such as Base64 encoding and decoding, Hex encoding and decoding, and Unicode encoding and decoding, etc.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// Base64 encoding and decoding
String encode = CodecUtils.encodeToString(BASE64, dataBytes);
log.info("Encode string: {}{}", NEWLINE, encode);
byte[] decode = CodecUtils.decodeFromString(BASE64, encode);
log.info("Decode string: {}{}", NEWLINE, new String(decode, "UTF-8"));
// Unicode encoding and decoding
String encode = CodecUtils.encode(UNICODE, "Hello,Java! ");
log.info(encode);
log.info(CodecUtils.decode(UNICODE, encode));
```
## Context Tools
When developing application services, information about the current logged-in user is generally placed in context tools. However, in this project, the context tool is a very top-level abstract design.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// No available
```
## Type Conversion Tools
In Java, scenarios often arise where you need to convert a string type like "16" into a numeric type like Integer 16. This is easy to handle in clear-cut cases. But what if the input parameter is an Object and you need to perform numerical calculations during business operations? Or perhaps the business operation only requires passing in the expected conversion type—this scenario becomes more complex.
Especially when generics are involved, things can get even more complicated, such as converting from "List" to "PageList". These are the issues that the type conversion tool aims to address.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// String to Double conversion
Object obj = ConversionUtils.convert("102", double.class);
log.info("{} {}", obj.getClass(), obj);
// Time string to Date object conversion
Object obj = ConversionUtils.convert("2019-03-25 10:10:10 300", java.sql.Date.class);
log.info("{} {}", obj.getClass(), DateUtils.format((Date) obj));
```
## Encryption and Decryption Tools
Encryption and decryption tools include AES, DES, DESede, Blowfish, RSA, etc. As for Hash-related tools, there are MD2, MD5, SHA1, SHA256, etc. Hmac-related tools include HmacMD5, HmacSHA1, HmacSHA256, etc.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// No available
```
## Data related Tools
Data operation-related tools include serialization and deserialization tools, data comparison tools, tuple-related tools, etc.
### Serialize and Deserialize Tools
Serialization tools are the process of converting objects into a transportable or storable sequence of bytes, while deserialization tools are the process of restoring the byte sequence back into an object.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// No available
```
### Comparator Tools
In Java, everything can be an object, so comparison tools can compare differences such as images, files, and data between two objects. Since collections like List are essentially also objects, they can also be used to compare the differences between multiple object data and among multiple objects.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
// No available
```
### Validator Tools
A validator tool checks if certain data (an object) conforms to the rules of a specific validator implementation class. The most classic example of a validator implementation class is one based on regular expressions. Therefore, a validator tool is essentially a set of tools that verify whether items like email addresses, bank cards, phone numbers, etc., are "correct". Of course, its greatest advantage is the ease with which it can be customized based on business needs.
### Tuple related Tools
A tuple refers to objects like "KeyValue," "Pair," and "Triple," which are convenient for storing data.
**Simple usage example (some example codes require pre-configuration or implementation):**
```java
KeyValue keyValue = new KeyValueImpl();
Triple triple = new TripleImpl