Skip to content

Commit e6d8d78

Browse files
author
Zihlu Wang
authored
Merge pull request #48 from OnixByte/release/v2.0.0
Release/v2.0.0
2 parents 8e6ba32 + 7eeb8a9 commit e6d8d78

File tree

26 files changed

+694
-508
lines changed

26 files changed

+694
-508
lines changed

README.md

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,20 @@
11
# JDevKit
22

3-
JDevKit is a Java Development Kit that offers a set of convenient tools for writing code efficiently.
4-
5-
## Modules
6-
7-
> For more information, please visit the README file of each module.
8-
9-
### `devkit-core` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/devkit-core/README.md)_</span>
10-
11-
The core module for `JDevKit`, by now, this module contains the commonly used classes of the whole `dev-kit`.
12-
13-
### `devkit-utils` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/devkit-utils/README.md)_</span>
14-
15-
A collection of common utility classes to simplify Java development. It includes tools for Base64 encoding/decoding of strings, reducing if-else code blocks using Lambda expressions, converting between maps and arbitrary objects, high-precision chained mathematical calculations, and string hashing or message digest calculations.
16-
17-
### `guid` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/guid/README.md)_</span>
18-
19-
A module for generating globally unique IDs. It includes a facade interface and an implementation of GUID generation using the Snowflake algorithm. More globally unique ID generation modes will be added in the future.
20-
21-
### `WebCal` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/webcal/README.md)_</span>
22-
23-
The module `webcal` is a Java library that facilitates the generation and resolution of iCalendar content for web-based calendar applications. It provides a flexible and easy-to-use API for creating web calendars with customisable settings and events.
24-
25-
With the `webcal` module, developers can easily integrate calendar functionality into web applications, enabling users to view, add, and manage events in a structured and standardized format. It is designed to simplify calendar-related tasks and enhance the overall user experience when dealing with calendar data on the web.
26-
27-
Please note that the `webcal` module adheres to the iCalendar standard specified in RFC 5545, ensuring compatibility with other calendar applications that support this format.
28-
29-
### `simple-jwt-facade` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-facade/README.md)_</span>
30-
31-
A facade for Simple JWT (JSON Web Token) implementations in Java. This module provides a unified interface to work with JWTs regardless of the underlying implementation.
32-
33-
### `simple-jwt-authzero` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-authzero/README.md)_</span>
34-
35-
A Simple JWT implementation using the com.auth0:java-jwt library.
36-
37-
### `simple-jwt-jjwt` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-jjwt/README.md)_</span>
3+
![Static Badge](https://img.shields.io/badge/tag-v2.0.0-orange)
4+
![Static Badge](https://img.shields.io/badge/maven_central-v2.0.0-orange)
5+
![Static Badge](https://img.shields.io/badge/licence-Apache_2.0-green)
6+
![Static Badge](https://img.shields.io/badge/JDK-%E2%89%A517-blue)
387

39-
A Simple JWT implementation using the `io.jsonwebtoken:jjwt-api` library.
408

41-
### `simple-jwt-spring-boot-starter` <span style="font-size: 14px;">_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-spring-boot-starter/README.md)_</span>
42-
43-
A Spring Boot autoconfiguration wrapper for the simple-jwt module, making it easier to integrate JWT functionality into Spring Boot applications.
9+
JDevKit is a Java Development Kit that offers a set of convenient tools for writing code efficiently.
4410

4511
## Installation and Usage
4612

47-
### Before Installation
48-
49-
For **Chinese Mainland** users, it is suggested to use maven packages services provided by coding.net.
50-
51-
You could follow the following steps to configure.
52-
53-
#### For Maven
54-
55-
You could add the following codes to register Coding Nexus to your Maven.
56-
57-
```xml
58-
<repository>
59-
<id>codecrafters-coding-nexus</id>
60-
<name>codecrafters-coding-nexus</name>
61-
<url>https://codecrafters-maven.pkg.coding.net/repository/common-productions/maven-packages/</url>
62-
<releases>
63-
<enabled>true</enabled>
64-
</releases>
65-
<snapshots>
66-
<enabled>true</enabled>
67-
</snapshots>
68-
</repository>
69-
```
70-
71-
#### For Gradle
72-
73-
You could add a new repository to Gradle repositories closure.
74-
75-
```groovy
76-
maven { url 'https://codecrafters-maven.pkg.coding.net/repository/common-productions/maven-packages/' }
77-
```
78-
79-
```kotlin
80-
maven(url = "https://codecrafters-maven.pkg.coding.net/repository/common-productions/maven-packages/")
81-
```
82-
8313
If you are using **Maven**, please paste the following codes to _pom.xml_ in your project.
8414

8515
```xml
8616
<dependency>
87-
<groupId>cn.org.codecrafters</groupId>
17+
<groupId>com.onixbyte</groupId>
8818
<artifactId>${artifactId}</artifactId>
8919
<version>${version}</version>
9020
</dependency>
@@ -93,11 +23,11 @@ If you are using **Maven**, please paste the following codes to _pom.xml_ in you
9323
If you are using **Gradle**, please paste the following codes to _buile.gradle\[.kts\]_ in your project.
9424

9525
```groovy
96-
implementation 'cn.org.codecrafters:$artifactId:$version'
26+
implementation 'com.onixbyte:$artifactId:$version'
9727
```
9828

9929
```kotlin
100-
implementation("cn.org.codecrafters:$artifactId:$version")
30+
implementation("com.onixbyte:$artifactId:$version")
10131
```
10232

10333
If you want to check the available versions, please check out at our [official site](https://codecrafters.org.cn/devkit/changelog).

devkit-core/README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@
22

33
## Introduction
44

5-
This module is the main part of `JDevKit`, an open-source Java class library that provides a set of convenient tools to streamline code development and enhance productivity. This module serves as the basement of other modules.
6-
7-
## Prerequisites
8-
9-
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience.
10-
11-
## Installation
12-
13-
You don't have to install this module at all, any module which is from `JDevKit` contains this `devkit-core` module.
14-
15-
## Contact
16-
17-
If you have any suggestions, ideas, don't hesitate contacting us via [GitHub Issues](https://github.com/CodeCraftersCN/jdevkit/issues/new) or [Discord Community](https://discord.gg/NQK9tjcBB8).
18-
19-
If you face any bugs while using our library and you are able to fix any bugs in our library, we would be happy to accept pull requests from you on [GitHub](https://github.com/CodeCraftersCN/jdevkit/compare).
5+
This module serves as the basement of `JDevKit`. It provides some base exceptions that `JDevKit` might use.

devkit-utils/README.md

Lines changed: 9 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -2,189 +2,15 @@
22

33
## Introduction
44

5-
This module is part of `JDevKit`, an open-source Java Development Kit that provides a set of convenient tools to streamline code development and enhance productivity. This module serves as the useful toolkit for the library, contains a collection of utility classes commonly used in all Java Application development.
5+
This module provides a set of utilities to streamline Java codes.
66

7-
## Prerequisites
7+
## Features
88

9-
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience.
9+
- AES encryption and decryption;
10+
- Base64 encode and decode;
11+
- Boolean calculation;
12+
- Reduce `if...else...` with **lambdas**;
13+
- Hash calculation for strings;
14+
- Convert Java beans to map and map to Java beans;
15+
- Simplified range generator.
1016

11-
## Installation
12-
13-
### If you are using `Maven`
14-
15-
It is quite simple to install this module by `Maven`. The only thing you need to do is find your `pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add the following codes to `<dependencies>` node:
16-
17-
```xml
18-
<dependency>
19-
<groupId>cn.org.codecrafters</groupId>
20-
<artifactId>devkit-utils</artifactId>
21-
<version>${devkit-utils.version}</version>
22-
</dependency>
23-
```
24-
25-
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at `/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`), then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do is click the refresh button of `Maven`.
26-
27-
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the following steps.
28-
29-
1. Download the `jar` file from any place you can get and transfer the `jar` files to your work computer.
30-
2. Move the `jar` files to your local `Maven` Repository as the path of `/path/to/maven_local_repo/cn/org/codecrafters/devkit-utils/`.
31-
32-
### If you are using `Gradle`
33-
34-
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
35-
36-
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure in the build script:
37-
38-
```groovy
39-
implementation 'cn.org.codecrafters:devkit-utils:${devkit-utils.version}'
40-
```
41-
42-
### If you are not using `Maven` or `Gradle`
43-
44-
1. Download the `jar` file from the Internet.
45-
2. Create a folder in your project and name it as a name you like(i.e., for me, I prefer `vendor`).
46-
3. Put the `jar` file to the folder you just created in Step 2.
47-
4. Add this folder to your project `classpath`.
48-
49-
### Base64 Encode and Decode
50-
51-
If you are trying to encode a string to Base64 string or decode a Base64 string to normal string, then you can try this:
52-
53-
```java
54-
import utils.com.onixbyte.devkit.Base64Util;
55-
56-
// To reduce sample codes, let me use the simplified main method that is upcoming in Java 21
57-
void main(String... args) {
58-
var aString = "The string you need to encode.";
59-
// Encode it from original text.
60-
var encodedString = Base64Util.encode(aString);
61-
// Decode the encoded text.
62-
var decodedString = Base64Util.decode(encodedString);
63-
}
64-
```
65-
66-
## Reduce `if...else...`
67-
68-
I believe those `if...else...` blocks make you headache, and Java imported lambda since Java 8, why not try to replace those `if...else` with lambda expressions?
69-
70-
```java
71-
import utils.com.onixbyte.devkit.BranchUtil;
72-
73-
void main(String... args) {
74-
var a = 1;
75-
var b = 2;
76-
77-
if (a < b) {
78-
// do something...
79-
} else {
80-
// do something different...
81-
}
82-
// The codes above is really annoying, have a try of the lambda version.
83-
84-
BranchUtil.or(a < b) // If multiple logical expressions are combined using the OR operator.
85-
.handle(() -> {
86-
// do something if a < b.
87-
}, () -> {
88-
// do something if a > b.
89-
});
90-
91-
BranchUtil.and(a < b) // If multiple logical expressions are combined using the AND operator
92-
.handle(() -> {
93-
// do something if a < b.
94-
}, () -> {
95-
// do something if a > b.
96-
});
97-
}
98-
```
99-
100-
What if you have to get some data from this branch? Don't worry, those **lambda supports Supplier**. Just add a return in those lambda is fine.
101-
102-
## CHAINED High-precision Calculation
103-
104-
If you have faced high-precision mathematical calculation in Java, you might know it is very troubled to do it in **ANY** programming languages. I'm certain you remember that `0.1 + 0.2 != 0.3` right?
105-
106-
In Java, we usually do high-precision mathematical calculation with `BigDecimal` which is quite tricky when using it.
107-
108-
```java
109-
import utils.com.onixbyte.devkit.ChainedCalcUtil;
110-
111-
void main(String... args) {
112-
// If you are trying to calculate the expression of 1 * 2 / 2 - 3 + 4
113-
ChainedCalcUtil.startWith(1).multiply(2).divide(2).subtract(3).add(4).getInteger(); // you can also get a double by getDouble([int scale]), get a BigDecimal by getDecimal([int scale]) or get a long by getLong().
114-
}
115-
```
116-
117-
If you are facing a divide calculation which has an infinite decimal expansion, then DON'T use `divide(dividend)`, use `divideWithScale(dividend, scale, [beforeOperateScale])`.
118-
119-
## Hash a `String`
120-
121-
As is well known, storing plain text passwords in a database is very insecure. Therefore, you need to encrypt the passwords stored in the database, or at least make it difficult for hackers to see the real password at a glance. As a result, hash calculation is often used in database password obfuscation due to its ease of use.
122-
123-
This `HashUtil` supports these following hash or message digest algorithms:
124-
125-
- MD2
126-
- MD5
127-
- SHA-1
128-
- SHA-224
129-
- SHA-256
130-
- SHA-384
131-
- SHA-512
132-
133-
If you want to run a hash calculation to a string, you can use the following codes:
134-
135-
```java
136-
import utils.com.onixbyte.devkit.HashUtil;
137-
138-
void main(String... args) {
139-
var plaintext = "This is a plain text";
140-
var hashedText = HashUtil.md2(plaintext); // if you want to use other algorithm, just change the method name such as md5, sha1, sha224 and so on.
141-
}
142-
```
143-
144-
Besides, if you want to use other character set to do the hash calculation, you can add the specified charset after the text to be calculated.
145-
146-
```java
147-
HashUtil.$algorithm$(String textToCalculate, Charset charset);
148-
```
149-
150-
## Convert a Map to Any Object and Vice Versa
151-
152-
A Map is a data structure that allows you to store key-value pairs. The keys can be of any type and the values can be of any type. In this case, the key is the user's name and the value is the user's profile.
153-
154-
Imagine you are developing a website where users can register an account and store their profile. A profile can contain information like their name, age, address, and email address. You store the user's profile in a Map. When the user registers an account, you need to store their profile in a database. A database is a system for storing data. A database can store any type of data, including Maps.
155-
156-
In order to store the Map in a database, you need to convert the Map to an Object. An Object is a generic data type that can store any type of data.
157-
158-
```java
159-
import utils.com.onixbyte.devkit.MapUtil;
160-
161-
class Data {
162-
private String name;
163-
private Long id;
164-
private Integer age;
165-
166-
// Setters and getters here.
167-
168-
// No-args constructor and all-args constructor here.
169-
}
170-
171-
void main(String... args) {
172-
// Create a map.
173-
var dataMap = new HashMap<String, Object>();
174-
dataMap.put("name", "Zihlu Wang");
175-
dataMap.put("id", 1L);
176-
dataMap.put("age", 18);
177-
178-
// Convert this map to an instance of class Data
179-
var data = MapUtil.mapToObject(dataMap, Data.class); // Then you got an instance of Data("Zihlu Wang", 1L, 18);
180-
181-
// Then you can convert this object to a map.
182-
var anotherDataMap = MapUtil.objectToMap(data)
183-
}
184-
```
185-
186-
## Contact
187-
188-
If you have any suggestions, ideas, don't hesitate contacting us via [GitHub Issues](https://github.com/CodeCraftersCN/jdevkit/issues/new) or [Discord Community](https://discord.gg/NQK9tjcBB8).
189-
190-
If you face any bugs while using our library and you are able to fix any bugs in our library, we would be happy to accept pull requests from you on [GitHub](https://github.com/CodeCraftersCN/jdevkit/compare).

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ javaJwtVersion=4.4.0
2020
junitVersion=5.11.4
2121
logbackVersion=1.5.16
2222
slf4jVersion=2.0.16
23-
springVersion=6.2.1
24-
springBootVersion=3.4.1
23+
springVersion=6.2.2
24+
springBootVersion=3.4.2
2525

26-
artefactVersion=1.8.0
26+
artefactVersion=2.0.0
2727
projectUrl=https://onixbyte.com/JDevKit
2828
projectGithubUrl=https://github.com/OnixByte/JDevKit
2929
licenseName=The Apache License, Version 2.0

0 commit comments

Comments
 (0)